Skip to content

Commit

Permalink
Merge pull request #2099 from hwupathum/remove-registry
Browse files Browse the repository at this point in the history
Replace IdentityPersistenceManager with SAMLSSOServiceProviderManager
  • Loading branch information
hwupathum committed Jun 22, 2023
2 parents 49a0991 + bf464a0 commit 0d1874f
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import org.wso2.carbon.identity.application.mgt.ApplicationManagementService;
import org.wso2.carbon.identity.application.mgt.listener.ApplicationMgtListener;
import org.wso2.carbon.identity.consent.server.configs.mgt.services.ConsentServerConfigsManagementService;
import org.wso2.carbon.identity.core.SAMLSSOServiceProviderManager;
import org.wso2.carbon.identity.core.util.IdentityCoreInitializedEvent;
import org.wso2.carbon.identity.event.handler.AbstractEventHandler;
import org.wso2.carbon.identity.event.services.IdentityEventService;
Expand Down Expand Up @@ -908,6 +909,28 @@ protected void unsetJWTAccessTokenClaimProvider(JWTAccessTokenClaimProvider clai
OAuth2ServiceComponentHolder.getInstance().removeJWTAccessTokenClaimProvider(claimProvider);
}

@Reference(
name = "saml.sso.service.provider.manager",
service = SAMLSSOServiceProviderManager.class,
cardinality = ReferenceCardinality.MANDATORY,
policy = ReferencePolicy.DYNAMIC,
unbind = "unsetSAMLSSOServiceProviderManager")
protected void setSAMLSSOServiceProviderManager(SAMLSSOServiceProviderManager samlSSOServiceProviderManager) {

OAuth2ServiceComponentHolder.getInstance().setSamlSSOServiceProviderManager(samlSSOServiceProviderManager);
if (log.isDebugEnabled()) {
log.debug("SAMLSSOServiceProviderManager set in to bundle");
}
}

protected void unsetSAMLSSOServiceProviderManager(SAMLSSOServiceProviderManager samlSSOServiceProviderManager) {

OAuth2ServiceComponentHolder.getInstance().setSamlSSOServiceProviderManager(null);
if (log.isDebugEnabled()) {
log.debug("SAMLSSOServiceProviderManager unset in to bundle");
}
}

@Reference(
name = "identity.application.authentication.framework",
service = ApplicationAuthenticationService.class,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import org.wso2.carbon.identity.application.authentication.framework.UserSessionManagementService;
import org.wso2.carbon.identity.application.mgt.ApplicationManagementService;
import org.wso2.carbon.identity.consent.server.configs.mgt.services.ConsentServerConfigsManagementService;
import org.wso2.carbon.identity.core.SAMLSSOServiceProviderManager;
import org.wso2.carbon.identity.core.handler.HandlerComparator;
import org.wso2.carbon.identity.event.services.IdentityEventService;
import org.wso2.carbon.identity.oauth.OAuthAdminServiceImpl;
Expand Down Expand Up @@ -75,6 +76,7 @@ public class OAuth2ServiceComponentHolder {
private static KeyIDProvider keyIDProvider = null;
private IdpManager idpManager;
private static UserSessionManagementService userSessionManagementService;
private static SAMLSSOServiceProviderManager samlSSOServiceProviderManager;
private static RoleManager roleManager;
private static OrganizationUserResidentResolverService organizationUserResidentResolverService;
private List<ScopeDTO> oidcScopesClaims = new ArrayList<>();
Expand Down Expand Up @@ -477,6 +479,26 @@ public static void setConfigurationContextService(ConfigurationContextService co
OAuth2ServiceComponentHolder.configurationContextService = configurationContextService;
}

/**
* Get the OAuth2ScopeClaimMappingDAO instance.
*
* @param samlSSOServiceProviderManager SAMLSSOServiceProviderManager instance.
*/
public static void setSamlSSOServiceProviderManager(SAMLSSOServiceProviderManager samlSSOServiceProviderManager) {

OAuth2ServiceComponentHolder.samlSSOServiceProviderManager = samlSSOServiceProviderManager;
}

/**
* Get the SAMLSSOServiceProviderManager instance.
*
* @return SAMLSSOServiceProviderManager instance.
*/
public static SAMLSSOServiceProviderManager getSamlSSOServiceProviderManager() {

return samlSSOServiceProviderManager;
}

/**
* Returns JWT access token additional claim providers.
*
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* Copyright (c) 2012, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
* Copyright (c) 2012, WSO2 LLC. (http://www.wso2.com).
*
* WSO2 Inc. licenses this file to you under the Apache License,
* WSO2 LLC. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
* in compliance with the License.
* You may obtain a copy of the License at
Expand Down Expand Up @@ -43,7 +43,6 @@
import org.wso2.carbon.base.MultitenantConstants;
import org.wso2.carbon.base.ServerConfiguration;
import org.wso2.carbon.context.PrivilegedCarbonContext;
import org.wso2.carbon.context.RegistryType;
import org.wso2.carbon.identity.application.authentication.framework.model.AuthenticatedUser;
import org.wso2.carbon.identity.application.authentication.framework.util.FrameworkUtils;
import org.wso2.carbon.identity.application.common.IdentityApplicationManagementException;
Expand All @@ -60,7 +59,6 @@
import org.wso2.carbon.identity.base.IdentityConstants;
import org.wso2.carbon.identity.base.IdentityException;
import org.wso2.carbon.identity.core.model.SAMLSSOServiceProviderDO;
import org.wso2.carbon.identity.core.persistence.IdentityPersistenceManager;
import org.wso2.carbon.identity.core.util.IdentityTenantUtil;
import org.wso2.carbon.identity.core.util.IdentityUtil;
import org.wso2.carbon.identity.oauth.common.OAuthConstants;
Expand All @@ -79,7 +77,6 @@
import org.wso2.carbon.identity.saml.common.util.exception.IdentityUnmarshallingException;
import org.wso2.carbon.idp.mgt.IdentityProviderManagementException;
import org.wso2.carbon.idp.mgt.IdentityProviderManager;
import org.wso2.carbon.registry.core.Registry;
import org.wso2.carbon.user.api.UserStoreException;
import org.wso2.carbon.user.api.UserStoreManager;
import org.wso2.carbon.user.core.UniqueIDUserStoreManager;
Expand Down Expand Up @@ -1013,10 +1010,8 @@ private SAMLSSOServiceProviderDO getSAMLSSOServiceProvider(String issuerName, St
privilegedCarbonContext.setTenantDomain(tenantDomain);

IdentityTenantUtil.initializeRegistry(tenantId, tenantDomain);
IdentityPersistenceManager persistenceManager = IdentityPersistenceManager.getPersistanceManager();
Registry registry = (Registry) PrivilegedCarbonContext.getThreadLocalCarbonContext().getRegistry
(RegistryType.SYSTEM_CONFIGURATION);
return persistenceManager.getServiceProvider(registry, issuerName);
return OAuth2ServiceComponentHolder.getInstance().getSamlSSOServiceProviderManager()
.getServiceProvider(issuerName, tenantId);
} catch (IdentityException e) {
throw new IdentityOAuth2Exception("Error occurred while validating existence of SAML service provider " +
"'" + issuerName + "' that issued the assertion in the tenant domain '" + tenantDomain + "'");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
* Copyright (c) 2017, WSO2 LLC. (http://www.wso2.com).
*
* WSO2 Inc. licenses this file to you under the Apache License,
* WSO2 LLC. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
* in compliance with the License.
* You may obtain a copy of the License at
Expand Down Expand Up @@ -52,8 +52,8 @@
import org.wso2.carbon.identity.application.common.util.IdentityApplicationManagementUtil;
import org.wso2.carbon.identity.application.mgt.ApplicationManagementService;
import org.wso2.carbon.identity.common.testng.WithCarbonHome;
import org.wso2.carbon.identity.core.SAMLSSOServiceProviderManager;
import org.wso2.carbon.identity.core.model.SAMLSSOServiceProviderDO;
import org.wso2.carbon.identity.core.persistence.IdentityPersistenceManager;
import org.wso2.carbon.identity.core.util.IdentityTenantUtil;
import org.wso2.carbon.identity.core.util.IdentityUtil;
import org.wso2.carbon.identity.oauth.common.OAuthConstants;
Expand All @@ -76,7 +76,6 @@
import org.wso2.carbon.identity.testutil.powermock.PowerMockIdentityBaseTest;
import org.wso2.carbon.idp.mgt.IdentityProviderManagementException;
import org.wso2.carbon.idp.mgt.IdentityProviderManager;
import org.wso2.carbon.registry.core.Registry;
import org.wso2.carbon.user.api.UserStoreException;
import org.wso2.carbon.user.core.UserRealm;
import org.wso2.carbon.user.core.UserStoreManager;
Expand Down Expand Up @@ -113,7 +112,7 @@
@PrepareForTest({IdentityUtil.class, IdentityTenantUtil.class, IdentityProviderManager.class, MultitenantUtils.class,
IdentityApplicationManagementUtil.class, OAuthServerConfiguration.class, SSOServiceProviderConfigManager.class,
SAML2BearerGrantHandler.class, OAuthComponentServiceHolder.class, OAuth2ServiceComponentHolder.class,
OAuth2Util.class, IdentityPersistenceManager.class, SignatureValidator.class, UnmarshallUtils.class})
OAuth2Util.class, SAMLSSOServiceProviderManager.class, SignatureValidator.class, UnmarshallUtils.class})
@WithCarbonHome
public class SAML2BearerGrantHandlerTest extends PowerMockIdentityBaseTest {

Expand All @@ -131,6 +130,8 @@ public class SAML2BearerGrantHandlerTest extends PowerMockIdentityBaseTest {
@Mock
private OAuthComponentServiceHolder oAuthComponentServiceHolder;
@Mock
private OAuth2ServiceComponentHolder oAuth2ServiceComponentHolder;
@Mock
private RealmService realmService;
@Mock
private TenantManager tenantManager;
Expand All @@ -153,7 +154,7 @@ public class SAML2BearerGrantHandlerTest extends PowerMockIdentityBaseTest {
@Mock
private TokenPersistenceProcessor persistenceProcessor;
@Mock
private IdentityPersistenceManager identityPersistenceManager;
private SAMLSSOServiceProviderManager samlSSOServiceProviderManager;

@BeforeMethod
public void setUp() throws Exception {
Expand Down Expand Up @@ -419,6 +420,7 @@ private void mockOAuthComponents() throws Exception {
when(oAuthComponentServiceHolder.getRealmService()).thenReturn(realmService);
mockStatic(OAuth2ServiceComponentHolder.class);
when(OAuth2ServiceComponentHolder.getApplicationMgtService()).thenReturn(applicationManagementService);
when(OAuth2ServiceComponentHolder.getSamlSSOServiceProviderManager()).thenReturn(samlSSOServiceProviderManager);
when(applicationManagementService.getServiceProviderByClientId(anyString(), anyString(), anyString()))
.thenReturn(serviceProvider);
}
Expand Down Expand Up @@ -523,11 +525,10 @@ private void prepareForGetSAMLSSOServiceProvider() throws Exception {
samlssoServiceProviderDO.setIssuer(TestConstants.SAML_ISSUER);
samlssoServiceProviderDO.setIdpEntityIDAlias(TestConstants.IDP_ENTITY_ID_ALIAS);

when(identityPersistenceManager.getServiceProvider(any(Registry.class), anyString()))
when(samlSSOServiceProviderManager.getServiceProvider(anyString(), anyInt()))
.thenReturn(samlssoServiceProviderDO);
mockStatic(IdentityPersistenceManager.class);
when(IdentityPersistenceManager.getPersistanceManager()).thenReturn(identityPersistenceManager);
when(identityPersistenceManager.isServiceProviderExists(any(Registry.class), anyString())).thenReturn(true);

when(samlSSOServiceProviderManager.isServiceProviderExists(anyString(), anyInt())).thenReturn(true);

mockStatic(SSOServiceProviderConfigManager.class);
when(SSOServiceProviderConfigManager.getInstance()).thenReturn(ssoServiceProviderConfigManager);
Expand Down
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -863,8 +863,8 @@
<carbon.kernel.registry.imp.pkg.version.range>[1.0.1, 2.0.0)</carbon.kernel.registry.imp.pkg.version.range>

<!-- Carbon Identity Framework version -->
<carbon.identity.framework.version>5.25.221</carbon.identity.framework.version>
<carbon.identity.framework.imp.pkg.version.range>[5.17.5, 7.0.0)
<carbon.identity.framework.version>5.25.234</carbon.identity.framework.version>
<carbon.identity.framework.imp.pkg.version.range>[5.25.234, 7.0.0)
</carbon.identity.framework.imp.pkg.version.range>

<carbon.identity.organization.management.version>1.1.14
Expand Down

0 comments on commit 0d1874f

Please sign in to comment.