From 0eb17c6defa214fcc36bf5177e7ac571e38ebb54 Mon Sep 17 00:00:00 2001 From: Udara Pathum Date: Tue, 13 Jun 2023 21:23:05 +0530 Subject: [PATCH 1/4] Remove IdentityPersistentManager --- .../query/saml/util/SAMLQueryRequestUtil.java | 38 ++++++++----------- .../sso/saml/admin/SAMLSSOConfigAdmin.java | 35 ++++++++--------- .../IdPInitSSOAuthnRequestProcessor.java | 17 ++++----- .../SPInitLogoutRequestProcessor.java | 15 +++----- .../SPInitSSOAuthnRequestProcessor.java | 20 +++++----- .../saml/servlet/SAMLSSOProviderServlet.java | 17 ++++----- .../identity/sso/saml/util/SAMLSSOUtil.java | 25 +++++------- .../saml/admin/SAMLSSOConfigAdminTest.java | 32 ++++++++-------- .../sso/saml/util/AssertionBuildingTest.java | 21 +++++----- .../sso/saml/util/SAMLSSOUtilTest.java | 23 ++++++----- 10 files changed, 105 insertions(+), 138 deletions(-) diff --git a/components/org.wso2.carbon.identity.query.saml/src/main/java/org/wso2/carbon/identity/query/saml/util/SAMLQueryRequestUtil.java b/components/org.wso2.carbon.identity.query.saml/src/main/java/org/wso2/carbon/identity/query/saml/util/SAMLQueryRequestUtil.java index f3d82ed99..ca3dc6107 100644 --- a/components/org.wso2.carbon.identity.query.saml/src/main/java/org/wso2/carbon/identity/query/saml/util/SAMLQueryRequestUtil.java +++ b/components/org.wso2.carbon.identity.query.saml/src/main/java/org/wso2/carbon/identity/query/saml/util/SAMLQueryRequestUtil.java @@ -1,19 +1,19 @@ /* - * Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * Copyright (c) (2016-2023), WSO2 LLC. (http://www.wso2.com). * - * WSO2 Inc. 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 + * 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 * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. */ package org.wso2.carbon.identity.query.saml.util; @@ -71,9 +71,10 @@ import org.w3c.dom.ls.LSOutput; import org.w3c.dom.ls.LSSerializer; import org.wso2.carbon.context.CarbonContext; +import org.wso2.carbon.identity.application.common.IdentityApplicationManagementException; import org.wso2.carbon.identity.base.IdentityException; +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.query.saml.SignKeyDataHolder; import org.wso2.carbon.identity.query.saml.exception.IdentitySAML2QueryException; import org.wso2.carbon.identity.saml.common.util.SAMLInitializer; @@ -212,19 +213,10 @@ public static SAMLSSOServiceProviderDO getServiceProviderConfig(String issuer) SSOServiceProviderConfigManager.getInstance(); SAMLSSOServiceProviderDO ssoIdpConfigs = idPConfigManager.getServiceProvider(issuer); if (ssoIdpConfigs == null) { - IdentityPersistenceManager persistenceManager = - IdentityPersistenceManager.getPersistanceManager(); int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId(); - UserRegistry registry = - SAMLSSOUtil.getRegistryService() - .getConfigSystemRegistry(tenantId); - ssoIdpConfigs = persistenceManager.getServiceProvider(registry, issuer); + ssoIdpConfigs = SAMLSSOServiceProviderManager.getInstance().getServiceProvider(issuer, tenantId); } return ssoIdpConfigs; - } catch (RegistryException e) { - log.error("Unable to load registry service", e); - throw new IdentitySAML2QueryException("Unable to load registry service"); - } catch (IdentityException e) { log.error("Unable to load Identity persistence service manager", e); throw new IdentitySAML2QueryException("Unable to load Identity persistence service manager"); diff --git a/components/org.wso2.carbon.identity.sso.saml/src/main/java/org/wso2/carbon/identity/sso/saml/admin/SAMLSSOConfigAdmin.java b/components/org.wso2.carbon.identity.sso.saml/src/main/java/org/wso2/carbon/identity/sso/saml/admin/SAMLSSOConfigAdmin.java index 4d7ad6204..87ede2cbb 100644 --- a/components/org.wso2.carbon.identity.sso.saml/src/main/java/org/wso2/carbon/identity/sso/saml/admin/SAMLSSOConfigAdmin.java +++ b/components/org.wso2.carbon.identity.sso.saml/src/main/java/org/wso2/carbon/identity/sso/saml/admin/SAMLSSOConfigAdmin.java @@ -1,8 +1,8 @@ /* - * Copyright (c) 2007, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * Copyright (c) (2007-2023), WSO2 LLC. (http://www.wso2.com). * - * WSO2 Inc. licenses this file to you under the Apache License, - * Version 2.0 (the "License"); you may not use this file except + * 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 * @@ -26,8 +26,8 @@ import org.wso2.carbon.context.CarbonContext; import org.wso2.carbon.core.util.KeyStoreManager; import org.wso2.carbon.identity.base.IdentityException; +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.sp.metadata.saml2.exception.InvalidMetadataException; @@ -58,9 +58,11 @@ public class SAMLSSOConfigAdmin { private static final Log log = LogFactory.getLog(SAMLSSOConfigAdmin.class); private UserRegistry registry; + private final int tenantId; public SAMLSSOConfigAdmin(Registry userRegistry) { registry = (UserRegistry) userRegistry; + tenantId = ((UserRegistry) userRegistry).getTenantId(); } /** @@ -73,8 +75,6 @@ public SAMLSSOConfigAdmin(Registry userRegistry) { public boolean addRelyingPartyServiceProvider(SAMLSSOServiceProviderDTO serviceProviderDTO) throws IdentityException { SAMLSSOServiceProviderDO serviceProviderDO = createSAMLSSOServiceProviderDO(serviceProviderDTO); - IdentityPersistenceManager persistenceManager = IdentityPersistenceManager - .getPersistanceManager(); try { String issuer = getIssuerWithQualifier(serviceProviderDO); SAMLSSOServiceProviderDO samlssoServiceProviderDO = SSOServiceProviderConfigManager.getInstance(). @@ -86,7 +86,7 @@ public boolean addRelyingPartyServiceProvider(SAMLSSOServiceProviderDTO serviceP log.error(message); return false; } - return persistenceManager.addServiceProvider(registry, serviceProviderDO); + return SAMLSSOServiceProviderManager.getInstance().addServiceProvider(serviceProviderDO, tenantId); } catch (IdentityException e) { String message = "Error obtaining a registry for adding a new service provider"; throw new IdentityException(message, e); @@ -130,8 +130,8 @@ private String getIssuerWithQualifier(SAMLSSOServiceProviderDO serviceProviderDO private SAMLSSOServiceProviderDTO persistSAMLServiceProvider(SAMLSSOServiceProviderDO samlssoServiceProviderDO) throws IdentityException { - IdentityPersistenceManager persistenceManager = IdentityPersistenceManager.getPersistanceManager(); - boolean response = persistenceManager.addServiceProvider(registry, samlssoServiceProviderDO); + boolean response = SAMLSSOServiceProviderManager.getInstance() + .addServiceProvider(samlssoServiceProviderDO, tenantId); if (response) { return createSAMLSSOServiceProviderDTO(samlssoServiceProviderDO); } else { @@ -150,10 +150,10 @@ private SAMLSSOServiceProviderDTO persistSAMLServiceProvider(SAMLSSOServiceProvi */ private void saveCertificateToKeyStore(SAMLSSOServiceProviderDO serviceProviderDO) throws Exception { - KeyStoreManager manager = KeyStoreManager.getInstance(registry.getTenantId(), IdentitySAMLSSOServiceComponent + KeyStoreManager manager = KeyStoreManager.getInstance(tenantId, IdentitySAMLSSOServiceComponent .getServerConfigurationService(), IdentityTenantUtil.getRegistryService()); - if (MultitenantConstants.SUPER_TENANT_ID == registry.getTenantId()) { + if (MultitenantConstants.SUPER_TENANT_ID == tenantId) { KeyStore keyStore = manager.getPrimaryKeyStore(); @@ -167,7 +167,7 @@ private void saveCertificateToKeyStore(SAMLSSOServiceProviderDO serviceProviderD } } else { - String keyStoreName = getKeyStoreName(registry.getTenantId()); + String keyStoreName = getKeyStoreName(tenantId); KeyStore keyStore = manager.getKeyStore(keyStoreName); // Add new certificate @@ -196,7 +196,6 @@ private String getKeyStoreName(int tenantId) { */ public SAMLSSOServiceProviderDTO uploadRelyingPartyServiceProvider(String metadata) throws IdentityException { - IdentityPersistenceManager persistenceManager = IdentityPersistenceManager.getPersistanceManager(); Parser parser = new Parser(registry); SAMLSSOServiceProviderDO samlssoServiceProviderDO = new SAMLSSOServiceProviderDO(); @@ -411,9 +410,8 @@ private SAMLSSOServiceProviderDTO createSAMLSSOServiceProviderDTO(SAMLSSOService public SAMLSSOServiceProviderInfoDTO getServiceProviders() throws IdentityException { SAMLSSOServiceProviderDTO[] serviceProviders = null; try { - IdentityPersistenceManager persistenceManager = IdentityPersistenceManager - .getPersistanceManager(); - SAMLSSOServiceProviderDO[] providersSet = persistenceManager.getServiceProviders(registry); + SAMLSSOServiceProviderDO[] providersSet = SAMLSSOServiceProviderManager.getInstance() + .getServiceProviders(tenantId); serviceProviders = new SAMLSSOServiceProviderDTO[providersSet.length]; for (int i = 0; i < providersSet.length; i++) { @@ -486,7 +484,7 @@ public SAMLSSOServiceProviderInfoDTO getServiceProviders() throws IdentityExcept serviceProviderInfoDTO.setServiceProviders(serviceProviders); //if it is tenant zero - if (registry.getTenantId() == 0) { + if (tenantId == 0) { serviceProviderInfoDTO.setTenantZero(true); } return serviceProviderInfoDTO; @@ -501,8 +499,7 @@ public SAMLSSOServiceProviderInfoDTO getServiceProviders() throws IdentityExcept */ public boolean removeServiceProvider(String issuer) throws IdentityException { try { - IdentityPersistenceManager persistenceManager = IdentityPersistenceManager.getPersistanceManager(); - return persistenceManager.removeServiceProvider(registry, issuer); + return SAMLSSOServiceProviderManager.getInstance().removeServiceProvider(issuer, tenantId); } catch (IdentityException e) { throw new IdentityException("Error removing a Service Provider with issuer: " + issuer, e); } diff --git a/components/org.wso2.carbon.identity.sso.saml/src/main/java/org/wso2/carbon/identity/sso/saml/processors/IdPInitSSOAuthnRequestProcessor.java b/components/org.wso2.carbon.identity.sso.saml/src/main/java/org/wso2/carbon/identity/sso/saml/processors/IdPInitSSOAuthnRequestProcessor.java index 5eac7f090..5097aa67a 100644 --- a/components/org.wso2.carbon.identity.sso.saml/src/main/java/org/wso2/carbon/identity/sso/saml/processors/IdPInitSSOAuthnRequestProcessor.java +++ b/components/org.wso2.carbon.identity.sso.saml/src/main/java/org/wso2/carbon/identity/sso/saml/processors/IdPInitSSOAuthnRequestProcessor.java @@ -1,8 +1,8 @@ /* - * Copyright (c) 2010, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * Copyright (c) (2010-2023), WSO2 LLC. (http://www.wso2.com). * - * WSO2 Inc. licenses this file to you under the Apache License, - * Version 2.0 (the "License"); you may not use this file except + * 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 * @@ -22,10 +22,9 @@ import org.apache.commons.logging.LogFactory; import org.opensaml.saml.saml2.core.Response; import org.wso2.carbon.context.PrivilegedCarbonContext; -import org.wso2.carbon.context.RegistryType; import org.wso2.carbon.identity.base.IdentityException; +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.sso.saml.SAMLSSOConstants; import org.wso2.carbon.identity.sso.saml.SSOServiceProviderConfigManager; import org.wso2.carbon.identity.sso.saml.builders.ErrorResponseBuilder; @@ -35,7 +34,6 @@ import org.wso2.carbon.identity.sso.saml.dto.SAMLSSORespDTO; import org.wso2.carbon.identity.sso.saml.session.SSOSessionPersistenceManager; import org.wso2.carbon.identity.sso.saml.util.SAMLSSOUtil; -import org.wso2.carbon.registry.core.Registry; import org.wso2.carbon.registry.core.utils.UUIDGenerator; import java.util.ArrayList; @@ -232,10 +230,9 @@ private SAMLSSOServiceProviderDO getServiceProviderConfig(SAMLSSOAuthnReqDTO aut SAMLSSOServiceProviderDO ssoIdpConfigs = stratosIdpConfigManager .getServiceProvider(authnReqDTO.getIssuer()); if (ssoIdpConfigs == null) { - IdentityPersistenceManager persistenceManager = IdentityPersistenceManager - .getPersistanceManager(); - Registry registry = (Registry) PrivilegedCarbonContext.getThreadLocalCarbonContext().getRegistry(RegistryType.SYSTEM_CONFIGURATION); - ssoIdpConfigs = persistenceManager.getServiceProvider(registry,authnReqDTO.getIssuer()); + int tenantID = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(); + ssoIdpConfigs = SAMLSSOServiceProviderManager.getInstance() + .getServiceProvider(authnReqDTO.getIssuer(), tenantID); authnReqDTO.setStratosDeployment(false); // not stratos } else { authnReqDTO.setStratosDeployment(true); // stratos deployment diff --git a/components/org.wso2.carbon.identity.sso.saml/src/main/java/org/wso2/carbon/identity/sso/saml/processors/SPInitLogoutRequestProcessor.java b/components/org.wso2.carbon.identity.sso.saml/src/main/java/org/wso2/carbon/identity/sso/saml/processors/SPInitLogoutRequestProcessor.java index 4a5c3ca2d..96ddba53d 100644 --- a/components/org.wso2.carbon.identity.sso.saml/src/main/java/org/wso2/carbon/identity/sso/saml/processors/SPInitLogoutRequestProcessor.java +++ b/components/org.wso2.carbon.identity.sso.saml/src/main/java/org/wso2/carbon/identity/sso/saml/processors/SPInitLogoutRequestProcessor.java @@ -1,8 +1,8 @@ /* - * Copyright (c) 2010, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * Copyright (c) (2010-2023), WSO2 LLC. (http://www.wso2.com). * - * WSO2 Inc. licenses this file to you under the Apache License, - * Version 2.0 (the "License"); you may not use this file except + * 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 * @@ -23,11 +23,10 @@ import org.opensaml.saml.saml2.core.LogoutRequest; import org.opensaml.saml.saml2.core.LogoutResponse; import org.wso2.carbon.context.PrivilegedCarbonContext; -import org.wso2.carbon.context.RegistryType; import org.wso2.carbon.identity.application.common.util.IdentityApplicationManagementUtil; import org.wso2.carbon.identity.base.IdentityException; +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.sso.saml.SAMLSSOConstants; @@ -39,7 +38,6 @@ import org.wso2.carbon.identity.sso.saml.util.LambdaExceptionUtils; import org.wso2.carbon.identity.sso.saml.util.SAMLSSOUtil; import org.wso2.carbon.identity.sso.saml.validators.ValidationResult; -import org.wso2.carbon.registry.core.Registry; import org.wso2.carbon.user.api.UserStoreException; import org.wso2.carbon.user.core.UserCoreConstants; import org.wso2.carbon.utils.multitenancy.MultitenantConstants; @@ -271,10 +269,7 @@ private SAMLSSOServiceProviderDO getServiceProviderConfig(String issuer, String privilegedCarbonContext.setTenantId(tenantId); privilegedCarbonContext.setTenantDomain(tenantDomain); IdentityTenantUtil.initializeRegistry(tenantId, tenantDomain); - IdentityPersistenceManager persistenceManager = IdentityPersistenceManager.getPersistanceManager(); - Registry registry = (Registry) PrivilegedCarbonContext.getThreadLocalCarbonContext().getRegistry - (RegistryType.SYSTEM_CONFIGURATION); - ssoIdpConfigs = persistenceManager.getServiceProvider(registry, issuer); + ssoIdpConfigs = SAMLSSOServiceProviderManager.getInstance().getServiceProvider(issuer, tenantId); } finally { PrivilegedCarbonContext.endTenantFlow(); } diff --git a/components/org.wso2.carbon.identity.sso.saml/src/main/java/org/wso2/carbon/identity/sso/saml/processors/SPInitSSOAuthnRequestProcessor.java b/components/org.wso2.carbon.identity.sso.saml/src/main/java/org/wso2/carbon/identity/sso/saml/processors/SPInitSSOAuthnRequestProcessor.java index 504d01df2..b7a6c8579 100644 --- a/components/org.wso2.carbon.identity.sso.saml/src/main/java/org/wso2/carbon/identity/sso/saml/processors/SPInitSSOAuthnRequestProcessor.java +++ b/components/org.wso2.carbon.identity.sso.saml/src/main/java/org/wso2/carbon/identity/sso/saml/processors/SPInitSSOAuthnRequestProcessor.java @@ -1,8 +1,8 @@ /* - * Copyright (c) 2010, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * Copyright (c) (2010-2023), WSO2 LLC. (http://www.wso2.com). * - * WSO2 Inc. licenses this file to you under the Apache License, - * Version 2.0 (the "License"); you may not use this file except + * 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 * @@ -15,6 +15,7 @@ * specific language governing permissions and limitations * under the License. */ + package org.wso2.carbon.identity.sso.saml.processors; import org.apache.commons.lang.StringUtils; @@ -22,12 +23,11 @@ import org.apache.commons.logging.LogFactory; import org.opensaml.saml.saml2.core.Response; import org.wso2.carbon.context.PrivilegedCarbonContext; -import org.wso2.carbon.context.RegistryType; import org.wso2.carbon.identity.base.IdentityException; +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.IdentityTenantUtil; import org.wso2.carbon.identity.sso.saml.SAMLSSOConstants; import org.wso2.carbon.identity.sso.saml.SSOServiceProviderConfigManager; import org.wso2.carbon.identity.sso.saml.builders.ErrorResponseBuilder; @@ -37,7 +37,6 @@ import org.wso2.carbon.identity.sso.saml.dto.SAMLSSORespDTO; import org.wso2.carbon.identity.sso.saml.session.SSOSessionPersistenceManager; import org.wso2.carbon.identity.sso.saml.util.SAMLSSOUtil; -import org.wso2.carbon.registry.core.Registry; import org.wso2.carbon.registry.core.utils.UUIDGenerator; import java.util.ArrayList; @@ -219,10 +218,9 @@ private SAMLSSOServiceProviderDO getServiceProviderConfig(SAMLSSOAuthnReqDTO aut if (ssoIdpConfigs == null) { IdentityTenantUtil.initializeRegistry(PrivilegedCarbonContext.getThreadLocalCarbonContext() .getTenantId(), PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantDomain()); - IdentityPersistenceManager persistenceManager = IdentityPersistenceManager.getPersistanceManager(); - Registry registry = (Registry) PrivilegedCarbonContext.getThreadLocalCarbonContext().getRegistry - (RegistryType.SYSTEM_CONFIGURATION); - ssoIdpConfigs = persistenceManager.getServiceProvider(registry, authnReqDTO.getIssuer()); + int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(); + ssoIdpConfigs = SAMLSSOServiceProviderManager.getInstance() + .getServiceProvider(authnReqDTO.getIssuer(), tenantId); authnReqDTO.setStratosDeployment(false); // not stratos } else { authnReqDTO.setStratosDeployment(true); // stratos deployment diff --git a/components/org.wso2.carbon.identity.sso.saml/src/main/java/org/wso2/carbon/identity/sso/saml/servlet/SAMLSSOProviderServlet.java b/components/org.wso2.carbon.identity.sso.saml/src/main/java/org/wso2/carbon/identity/sso/saml/servlet/SAMLSSOProviderServlet.java index 9f136e565..9e364c603 100644 --- a/components/org.wso2.carbon.identity.sso.saml/src/main/java/org/wso2/carbon/identity/sso/saml/servlet/SAMLSSOProviderServlet.java +++ b/components/org.wso2.carbon.identity.sso.saml/src/main/java/org/wso2/carbon/identity/sso/saml/servlet/SAMLSSOProviderServlet.java @@ -1,8 +1,8 @@ /* - * Copyright (c) 2010, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * Copyright (c) (2010-2023), WSO2 LLC. (http://www.wso2.com). * - * WSO2 Inc. licenses this file to you under the Apache License, - * Version 2.0 (the "License"); you may not use this file except + * 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 * @@ -15,6 +15,7 @@ * specific language governing permissions and limitations * under the License. */ + package org.wso2.carbon.identity.sso.saml.servlet; import org.apache.commons.lang.StringUtils; @@ -25,7 +26,6 @@ import org.opensaml.core.xml.XMLObject; import org.owasp.encoder.Encode; import org.wso2.carbon.context.PrivilegedCarbonContext; -import org.wso2.carbon.context.RegistryType; import org.wso2.carbon.core.SameSiteCookie; import org.wso2.carbon.core.ServletCookie; import org.wso2.carbon.identity.application.authentication.framework.AuthenticatorFlowStatus; @@ -46,11 +46,11 @@ import org.wso2.carbon.identity.application.mgt.ApplicationManagementService; import org.wso2.carbon.identity.base.IdentityConstants; import org.wso2.carbon.identity.base.IdentityException; +import org.wso2.carbon.identity.core.SAMLSSOServiceProviderManager; import org.wso2.carbon.identity.core.ServiceURLBuilder; import org.wso2.carbon.identity.core.URLBuilderException; import org.wso2.carbon.identity.core.model.IdentityCookieConfig; 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.sso.saml.FrontChannelSLOParticipantInfo; @@ -82,7 +82,6 @@ import org.wso2.carbon.identity.sso.saml.util.SAMLSOAPUtils; import org.wso2.carbon.identity.sso.saml.util.SAMLSSOUtil; import org.wso2.carbon.idp.mgt.util.IdPManagementUtil; -import org.wso2.carbon.registry.core.Registry; import org.wso2.carbon.registry.core.utils.UUIDGenerator; import org.wso2.carbon.user.api.UserStoreException; import org.wso2.carbon.utils.multitenancy.MultitenantConstants; @@ -1799,10 +1798,8 @@ private SAMLSSOServiceProviderDO getServiceProviderConfig(SAMLSSOAuthnReqDTO aut privilegedCarbonContext.setTenantId(tenantId); privilegedCarbonContext.setTenantDomain(tenantDomain); - IdentityPersistenceManager persistenceManager = IdentityPersistenceManager.getPersistanceManager(); - Registry registry = (Registry) PrivilegedCarbonContext.getThreadLocalCarbonContext().getRegistry - (RegistryType.SYSTEM_CONFIGURATION); - serviceProviderConfigs = persistenceManager.getServiceProvider(registry, issuer); + serviceProviderConfigs = SAMLSSOServiceProviderManager.getInstance() + .getServiceProvider(issuer, tenantId); authnReqDTO.setStratosDeployment(false); // not stratos } catch (IdentityException e) { throw new IdentitySAML2SSOException("Error occurred while retrieving SAML service provider for " diff --git a/components/org.wso2.carbon.identity.sso.saml/src/main/java/org/wso2/carbon/identity/sso/saml/util/SAMLSSOUtil.java b/components/org.wso2.carbon.identity.sso.saml/src/main/java/org/wso2/carbon/identity/sso/saml/util/SAMLSSOUtil.java index 34e2603c9..2f1df6bdb 100644 --- a/components/org.wso2.carbon.identity.sso.saml/src/main/java/org/wso2/carbon/identity/sso/saml/util/SAMLSSOUtil.java +++ b/components/org.wso2.carbon.identity.sso.saml/src/main/java/org/wso2/carbon/identity/sso/saml/util/SAMLSSOUtil.java @@ -1,8 +1,8 @@ /* - * Copyright (c) 2010, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * Copyright (c) (2010-2023), WSO2 LLC. (http://www.wso2.com). * - * WSO2 Inc. licenses this file to you under the Apache License, - * Version 2.0 (the "License"); you may not use this file except + * 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 * @@ -62,6 +62,7 @@ import org.wso2.carbon.context.RegistryType; import org.wso2.carbon.core.util.KeyStoreManager; import org.wso2.carbon.identity.application.authentication.framework.util.FrameworkUtils; +import org.wso2.carbon.identity.application.common.IdentityApplicationManagementException; import org.wso2.carbon.identity.application.common.model.ClaimMapping; import org.wso2.carbon.identity.application.common.model.FederatedAuthenticatorConfig; import org.wso2.carbon.identity.application.common.model.IdentityProvider; @@ -73,10 +74,10 @@ import org.wso2.carbon.identity.base.IdentityException; import org.wso2.carbon.identity.base.IdentityRuntimeException; import org.wso2.carbon.identity.core.IdentityRegistryResources; +import org.wso2.carbon.identity.core.SAMLSSOServiceProviderManager; import org.wso2.carbon.identity.core.ServiceURLBuilder; import org.wso2.carbon.identity.core.URLBuilderException; 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.saml.common.util.SAMLInitializer; @@ -1842,10 +1843,7 @@ public static boolean isSAMLIssuerExists(String issuerName, String tenantDomain) privilegedCarbonContext.setTenantDomain(tenantDomain); IdentityTenantUtil.initializeRegistry(tenantId, tenantDomain); - IdentityPersistenceManager persistenceManager = IdentityPersistenceManager.getPersistanceManager(); - Registry registry = (Registry) PrivilegedCarbonContext.getThreadLocalCarbonContext().getRegistry - (RegistryType.SYSTEM_CONFIGURATION); - return persistenceManager.isServiceProviderExists(registry, issuerName); + return SAMLSSOServiceProviderManager.getInstance().isServiceProviderExists(issuerName, tenantId); } catch (IdentityException e) { throw new IdentitySAML2SSOException("Error occurred while validating existence of SAML service provider " + "'" + issuerName + "' in the tenant domain '" + tenantDomain + "'"); @@ -1900,10 +1898,8 @@ public static boolean validateACS(String tenantDomain, String issuerName, String privilegedCarbonContext.setTenantId(tenantId); privilegedCarbonContext.setTenantDomain(tenantDomain); - IdentityPersistenceManager persistenceManager = IdentityPersistenceManager.getPersistanceManager(); - Registry registry = (Registry) PrivilegedCarbonContext.getThreadLocalCarbonContext().getRegistry - (RegistryType.SYSTEM_CONFIGURATION); - SAMLSSOServiceProviderDO spDO=persistenceManager.getServiceProvider(registry, issuerName); + SAMLSSOServiceProviderDO spDO = SAMLSSOServiceProviderManager.getInstance().getServiceProvider(issuerName, + tenantId); if (StringUtils.isBlank(requestedACSUrl) || !spDO.getAssertionConsumerUrlList().contains (requestedACSUrl)) { String msg = "ALERT: Invalid Assertion Consumer URL value '" + requestedACSUrl + "' in the " + @@ -2684,10 +2680,7 @@ private static SAMLSSOServiceProviderDO getSAMLServiceProviderFromRegistry(Strin privilegedCarbonContext.setTenantDomain(tenantDomain); IdentityTenantUtil.getTenantRegistryLoader().loadTenantRegistry(tenantId); - IdentityPersistenceManager persistenceManager = IdentityPersistenceManager.getPersistanceManager(); - Registry registry = (Registry) PrivilegedCarbonContext.getThreadLocalCarbonContext(). - getRegistry(RegistryType.SYSTEM_CONFIGURATION); - return persistenceManager.getServiceProvider(registry, issuer); + return SAMLSSOServiceProviderManager.getInstance().getServiceProvider(issuer, tenantId); } catch (IdentityException | RegistryException e) { throw new IdentitySAML2SSOException("Error occurred while retrieving SAML service provider for " diff --git a/components/org.wso2.carbon.identity.sso.saml/src/test/java/org/wso2/carbon/identity/sso/saml/admin/SAMLSSOConfigAdminTest.java b/components/org.wso2.carbon.identity.sso.saml/src/test/java/org/wso2/carbon/identity/sso/saml/admin/SAMLSSOConfigAdminTest.java index fc76a3a68..b3804e3cb 100644 --- a/components/org.wso2.carbon.identity.sso.saml/src/test/java/org/wso2/carbon/identity/sso/saml/admin/SAMLSSOConfigAdminTest.java +++ b/components/org.wso2.carbon.identity.sso.saml/src/test/java/org/wso2/carbon/identity/sso/saml/admin/SAMLSSOConfigAdminTest.java @@ -1,8 +1,8 @@ /* - * Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * Copyright (c) (2017-2023), WSO2 LLC. (http://www.wso2.com). * - * WSO2 Inc. licenses this file to you under the Apache License, - * Version 2.0 (the "License"); you may not use this file except + * 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 * @@ -29,23 +29,22 @@ import org.testng.annotations.DataProvider; import org.testng.annotations.Test; import org.wso2.carbon.identity.base.IdentityException; +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.sp.metadata.saml2.util.Parser; import org.wso2.carbon.identity.sso.saml.SSOServiceProviderConfigManager; import org.wso2.carbon.identity.sso.saml.TestUtils; import org.wso2.carbon.identity.sso.saml.dto.SAMLSSOServiceProviderDTO; import org.wso2.carbon.identity.sso.saml.exception.IdentitySAML2ClientException; -import org.wso2.carbon.registry.core.Registry; import org.wso2.carbon.registry.core.session.UserRegistry; import org.wso2.carbon.utils.multitenancy.MultitenantConstants; import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyInt; import static org.mockito.ArgumentMatchers.anyString; -import static org.mockito.MockitoAnnotations.initMocks; import static org.powermock.api.mockito.PowerMockito.*; -@PrepareForTest({IdentityPersistenceManager.class, SSOServiceProviderConfigManager.class, +@PrepareForTest({SAMLSSOServiceProviderManager.class, SSOServiceProviderConfigManager.class, SAMLSSOServiceProviderDO.class, Parser.class, UserRegistry.class, SAMLSSOConfigAdmin.class}) @PowerMockIgnore({"javax.xml.*", "org.xml.*", "org.apache.xerces.*", "org.w3c.dom.*"}) public class SAMLSSOConfigAdminTest extends PowerMockTestCase { @@ -57,7 +56,7 @@ public class SAMLSSOConfigAdminTest extends PowerMockTestCase { UserRegistry userRegistry; @Mock - private IdentityPersistenceManager identityPersistenceManager; + private SAMLSSOServiceProviderManager samlSSOServiceProviderManager; @Mock SAMLSSOServiceProviderDO samlssoServiceProvDO; @@ -73,8 +72,8 @@ public void setUp() throws Exception { TestUtils.startTenantFlow(MultitenantConstants.SUPER_TENANT_DOMAIN_NAME); samlssoConfigAdmin = new SAMLSSOConfigAdmin(userRegistry); - mockStatic(IdentityPersistenceManager.class); - when(IdentityPersistenceManager.getPersistanceManager()).thenReturn(identityPersistenceManager); + mockStatic(SAMLSSOServiceProviderManager.class); + when(SAMLSSOServiceProviderManager.getInstance()).thenReturn(samlSSOServiceProviderManager); mockStatic(SAMLSSOServiceProviderDO.class); } @@ -88,7 +87,7 @@ public void testAddRelyingPartyServiceProvider() throws IdentityException { mockStatic(SSOServiceProviderConfigManager.class); when(SSOServiceProviderConfigManager.getInstance()).thenReturn(ssoServiceProviderConfigManager); - when(identityPersistenceManager.addServiceProvider(any(Registry.class), any(SAMLSSOServiceProviderDO.class))) + when(samlSSOServiceProviderManager.addServiceProvider(any(SAMLSSOServiceProviderDO.class), anyInt())) .thenReturn(true); SAMLSSOServiceProviderDTO samlssoServiceProviderDTO = new SAMLSSOServiceProviderDTO(); samlssoServiceProviderDTO.setIssuer("testUser"); @@ -131,8 +130,8 @@ public void testCreateSAMLSSOServiceProviderDOWithInvalidIssuerQualifier() throw public void testUploadRelyingPartyServiceProvider() throws Exception { String metadata = "metadata"; - when(identityPersistenceManager.addServiceProvider(any(Registry.class), any(SAMLSSOServiceProviderDO.class))). - thenReturn(true); + when(samlSSOServiceProviderManager.addServiceProvider(any(SAMLSSOServiceProviderDO.class), anyInt())) + .thenReturn(true); whenNew(SAMLSSOServiceProviderDO.class).withNoArguments().thenReturn(samlssoServiceProvDO); when(samlssoServiceProvDO.getIssuer()).thenReturn("issuer"); whenNew(Parser.class).withArguments(any(UserRegistry.class)).thenReturn(parser); @@ -147,7 +146,8 @@ public void testUploadRelyingPartyServiceProvider1() throws Exception { String metadata = "metadata"; whenNew(SAMLSSOServiceProviderDO.class).withNoArguments().thenReturn(samlssoServiceProvDO); when(samlssoServiceProvDO.getIssuer()).thenReturn("issuer"); - when(identityPersistenceManager.addServiceProvider(userRegistry, samlssoServiceProvDO)).thenReturn(false); + when(samlSSOServiceProviderManager.addServiceProvider(samlssoServiceProvDO, userRegistry.getTenantId())) + .thenReturn(false); whenNew(Parser.class).withArguments(any(UserRegistry.class)).thenReturn(parser); when(parser.parse(anyString(), any(SAMLSSOServiceProviderDO.class))).thenReturn(samlssoServiceProvDO); samlssoConfigAdmin.uploadRelyingPartyServiceProvider(metadata); @@ -157,7 +157,7 @@ public void testUploadRelyingPartyServiceProvider1() throws Exception { public void testUploadRelyingPartyServiceProvider2(String issuer) throws Exception { String metadata = "metadata"; - when(identityPersistenceManager.addServiceProvider(any(Registry.class), any(SAMLSSOServiceProviderDO.class))) + when(samlSSOServiceProviderManager.addServiceProvider(any(SAMLSSOServiceProviderDO.class), anyInt())) .thenReturn(true); whenNew(SAMLSSOServiceProviderDO.class).withNoArguments().thenReturn(samlssoServiceProvDO); when(samlssoServiceProvDO.getIssuer()).thenReturn(issuer); @@ -172,7 +172,7 @@ public void testGetServiceProviders() throws Exception { mockStatic(UserRegistry.class); SAMLSSOServiceProviderDO[] serviceProvidersList = new SAMLSSOServiceProviderDO[3]; when(userRegistry.getTenantId()).thenReturn(0); - when(identityPersistenceManager.getServiceProviders(any(UserRegistry.class))).thenReturn(serviceProvidersList); + when(samlSSOServiceProviderManager.getServiceProviders(anyInt())).thenReturn(serviceProvidersList); SAMLSSOServiceProviderDO samlssoServiceProviderDO = new SAMLSSOServiceProviderDO(); samlssoServiceProviderDO.setIssuer("issuer"); diff --git a/components/org.wso2.carbon.identity.sso.saml/src/test/java/org/wso2/carbon/identity/sso/saml/util/AssertionBuildingTest.java b/components/org.wso2.carbon.identity.sso.saml/src/test/java/org/wso2/carbon/identity/sso/saml/util/AssertionBuildingTest.java index 5d30a5a6e..858bdb253 100644 --- a/components/org.wso2.carbon.identity.sso.saml/src/test/java/org/wso2/carbon/identity/sso/saml/util/AssertionBuildingTest.java +++ b/components/org.wso2.carbon.identity.sso.saml/src/test/java/org/wso2/carbon/identity/sso/saml/util/AssertionBuildingTest.java @@ -1,8 +1,8 @@ /* - * Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * Copyright (c) (2017-2023), WSO2 LLC. (http://www.wso2.com). * - * WSO2 Inc. licenses this file to you under the Apache License, - * Version 2.0 (the "License"); you may not use this file except + * 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 * @@ -46,8 +46,8 @@ import org.wso2.carbon.identity.application.common.util.IdentityApplicationConstants; import org.wso2.carbon.identity.base.IdentityException; 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.saml.common.util.SAMLInitializer; @@ -59,7 +59,6 @@ import org.wso2.carbon.identity.sso.saml.dto.SAMLSSOAuthnReqDTO; import org.wso2.carbon.identity.sso.saml.validators.SSOAuthnRequestValidator; import org.wso2.carbon.idp.mgt.IdentityProviderManager; -import org.wso2.carbon.registry.core.Registry; import org.wso2.carbon.registry.core.exceptions.RegistryException; import org.wso2.carbon.registry.core.service.RegistryService; import org.wso2.carbon.registry.core.session.UserRegistry; @@ -75,8 +74,8 @@ import java.util.Map; import java.util.concurrent.TimeUnit; -import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anyBoolean; +import static org.mockito.ArgumentMatchers.anyInt; import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.ArgumentMatchers.eq; import static org.powermock.api.mockito.PowerMockito.mockStatic; @@ -91,7 +90,7 @@ * Tests Assertion building functionality. */ @PrepareForTest({IdentityUtil.class, IdentityTenantUtil.class, IdentityProviderManager.class, OSGiDataHolder.class, - SSOServiceProviderConfigManager.class, IdentityPersistenceManager.class}) + SSOServiceProviderConfigManager.class, SAMLSSOServiceProviderManager.class}) @WithCarbonHome @PowerMockIgnore({"javax.net.*", "javax.xml.*", "org.xml.*", "org.w3c.dom.*", "javax.security.*", "org.mockito.*"}) @@ -106,7 +105,7 @@ public IObjectFactory getObjectFactory() { private RealmService realmService; @Mock - private IdentityPersistenceManager identityPersistenceManager; + private SAMLSSOServiceProviderManager samlssoServiceProviderManager; @Mock private TenantManager tenantManager; @@ -385,10 +384,10 @@ private void prepareIdentityPersistentManager(String attrConsumerIndex, String i samlssoServiceProviderDO.setEnableAttributesByDefault(true); samlssoServiceProviderDO.setIssuer(issuer); samlssoServiceProviderDO.setAssertionConsumerUrls(acsList); - when(identityPersistenceManager.getServiceProvider(any(Registry.class), eq(issuer))) + when(samlssoServiceProviderManager.getServiceProvider(eq(issuer), anyInt())) .thenReturn(samlssoServiceProviderDO); - mockStatic(IdentityPersistenceManager.class); - when(IdentityPersistenceManager.getPersistanceManager()).thenReturn(identityPersistenceManager); + mockStatic(SAMLSSOServiceProviderManager.class); + when(SAMLSSOServiceProviderManager.getInstance()).thenReturn(samlssoServiceProviderManager); } private void setRegistryAndTenantDomain() throws UserStoreException, IdentityException, RegistryException { diff --git a/components/org.wso2.carbon.identity.sso.saml/src/test/java/org/wso2/carbon/identity/sso/saml/util/SAMLSSOUtilTest.java b/components/org.wso2.carbon.identity.sso.saml/src/test/java/org/wso2/carbon/identity/sso/saml/util/SAMLSSOUtilTest.java index f65ed2395..7d65a3843 100644 --- a/components/org.wso2.carbon.identity.sso.saml/src/test/java/org/wso2/carbon/identity/sso/saml/util/SAMLSSOUtilTest.java +++ b/components/org.wso2.carbon.identity.sso.saml/src/test/java/org/wso2/carbon/identity/sso/saml/util/SAMLSSOUtilTest.java @@ -1,8 +1,8 @@ /* - * Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * Copyright (c) (2017-2023), WSO2 LLC. (http://www.wso2.com). * - * WSO2 Inc. licenses this file to you under the Apache License, - * Version 2.0 (the "License"); you may not use this file except + * 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 * @@ -39,11 +39,11 @@ import org.wso2.carbon.identity.application.common.util.IdentityApplicationManagementUtil; import org.wso2.carbon.identity.base.IdentityConstants; import org.wso2.carbon.identity.base.IdentityException; +import org.wso2.carbon.identity.core.SAMLSSOServiceProviderManager; import org.wso2.carbon.identity.core.ServiceURL; import org.wso2.carbon.identity.core.ServiceURLBuilder; import org.wso2.carbon.identity.core.URLBuilderException; 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.sso.saml.SAMLSSOConstants; @@ -57,7 +57,6 @@ import org.wso2.carbon.identity.sso.saml.session.SessionInfoData; 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.service.RealmService; import org.wso2.carbon.user.core.tenant.TenantManager; @@ -67,7 +66,7 @@ import java.util.List; import static org.mockito.ArgumentMatchers.any; -import static org.mockito.ArgumentMatchers.anyBoolean; +import static org.mockito.ArgumentMatchers.anyInt; import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.ArgumentMatchers.eq; import static org.powermock.api.mockito.PowerMockito.mockStatic; @@ -83,7 +82,7 @@ * Unit test cases for SAMLSSOUtil. */ @PrepareForTest({IdentityProviderManager.class, IdentityUtil.class, IdentityApplicationManagementUtil.class, - KeyStoreManager.class, IdentityPersistenceManager.class, SSOServiceProviderConfigManager.class, + KeyStoreManager.class, SAMLSSOServiceProviderManager.class, SSOServiceProviderConfigManager.class, IdentityTenantUtil.class, ServiceURLBuilder.class, IdentityConstants.class, FrameworkServiceComponent.class}) @PowerMockIgnore({"javax.xml.*", "org.xml.*", "org.w3c.dom.*", "org.apache.xerces.*"}) public class SAMLSSOUtilTest extends PowerMockTestCase { @@ -111,7 +110,7 @@ public class SAMLSSOUtilTest extends PowerMockTestCase { private SessionInfoData sessionInfoData; @Mock - private IdentityPersistenceManager identityPersistenceManager; + private SAMLSSOServiceProviderManager samlSSOServiceProviderManager; @Mock private SSOServiceProviderConfigManager ssoServiceProviderConfigManager; @@ -154,11 +153,11 @@ private void prepareForGetSPConfig() throws Exception { samlssoServiceProviderDO.setIssuerQualifier(TestConstants.ISSUER_QUALIFIER); 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); + mockStatic(SAMLSSOServiceProviderManager.class); + when(SAMLSSOServiceProviderManager.getInstance()).thenReturn(samlSSOServiceProviderManager); + when(samlSSOServiceProviderManager.isServiceProviderExists(anyString(), anyInt())).thenReturn(true); mockStatic(SSOServiceProviderConfigManager.class); when(SSOServiceProviderConfigManager.getInstance()).thenReturn(ssoServiceProviderConfigManager); From 2a0b2006967955723b2ec6f12b2c98e92f8943f4 Mon Sep 17 00:00:00 2001 From: Udara Pathum Date: Thu, 15 Jun 2023 15:27:45 +0530 Subject: [PATCH 2/4] Remove unused dependencies --- .../query/saml/util/SAMLQueryRequestUtil.java | 3 -- .../identity/sso/saml/util/SAMLSSOUtil.java | 1 - .../sso/saml/util/AssertionBuildingTest.java | 35 +------------------ 3 files changed, 1 insertion(+), 38 deletions(-) diff --git a/components/org.wso2.carbon.identity.query.saml/src/main/java/org/wso2/carbon/identity/query/saml/util/SAMLQueryRequestUtil.java b/components/org.wso2.carbon.identity.query.saml/src/main/java/org/wso2/carbon/identity/query/saml/util/SAMLQueryRequestUtil.java index ca3dc6107..1e203816e 100644 --- a/components/org.wso2.carbon.identity.query.saml/src/main/java/org/wso2/carbon/identity/query/saml/util/SAMLQueryRequestUtil.java +++ b/components/org.wso2.carbon.identity.query.saml/src/main/java/org/wso2/carbon/identity/query/saml/util/SAMLQueryRequestUtil.java @@ -71,7 +71,6 @@ import org.w3c.dom.ls.LSOutput; import org.w3c.dom.ls.LSSerializer; import org.wso2.carbon.context.CarbonContext; -import org.wso2.carbon.identity.application.common.IdentityApplicationManagementException; import org.wso2.carbon.identity.base.IdentityException; import org.wso2.carbon.identity.core.SAMLSSOServiceProviderManager; import org.wso2.carbon.identity.core.model.SAMLSSOServiceProviderDO; @@ -81,8 +80,6 @@ import org.wso2.carbon.identity.sso.saml.SAMLSSOConstants; import org.wso2.carbon.identity.sso.saml.SSOServiceProviderConfigManager; import org.wso2.carbon.identity.sso.saml.util.SAMLSSOUtil; -import org.wso2.carbon.registry.core.exceptions.RegistryException; -import org.wso2.carbon.registry.core.session.UserRegistry; import org.xml.sax.SAXException; import javax.xml.XMLConstants; diff --git a/components/org.wso2.carbon.identity.sso.saml/src/main/java/org/wso2/carbon/identity/sso/saml/util/SAMLSSOUtil.java b/components/org.wso2.carbon.identity.sso.saml/src/main/java/org/wso2/carbon/identity/sso/saml/util/SAMLSSOUtil.java index 2f1df6bdb..df4510227 100644 --- a/components/org.wso2.carbon.identity.sso.saml/src/main/java/org/wso2/carbon/identity/sso/saml/util/SAMLSSOUtil.java +++ b/components/org.wso2.carbon.identity.sso.saml/src/main/java/org/wso2/carbon/identity/sso/saml/util/SAMLSSOUtil.java @@ -62,7 +62,6 @@ import org.wso2.carbon.context.RegistryType; import org.wso2.carbon.core.util.KeyStoreManager; import org.wso2.carbon.identity.application.authentication.framework.util.FrameworkUtils; -import org.wso2.carbon.identity.application.common.IdentityApplicationManagementException; import org.wso2.carbon.identity.application.common.model.ClaimMapping; import org.wso2.carbon.identity.application.common.model.FederatedAuthenticatorConfig; import org.wso2.carbon.identity.application.common.model.IdentityProvider; diff --git a/components/org.wso2.carbon.identity.sso.saml/src/test/java/org/wso2/carbon/identity/sso/saml/util/AssertionBuildingTest.java b/components/org.wso2.carbon.identity.sso.saml/src/test/java/org/wso2/carbon/identity/sso/saml/util/AssertionBuildingTest.java index 858bdb253..d1ecc26e0 100644 --- a/components/org.wso2.carbon.identity.sso.saml/src/test/java/org/wso2/carbon/identity/sso/saml/util/AssertionBuildingTest.java +++ b/components/org.wso2.carbon.identity.sso.saml/src/test/java/org/wso2/carbon/identity/sso/saml/util/AssertionBuildingTest.java @@ -34,11 +34,9 @@ import org.powermock.modules.testng.PowerMockObjectFactory; import org.powermock.modules.testng.PowerMockTestCase; import org.testng.IObjectFactory; -import org.testng.annotations.BeforeTest; import org.testng.annotations.DataProvider; import org.testng.annotations.ObjectFactory; import org.testng.annotations.Test; -import org.wso2.carbon.context.internal.OSGiDataHolder; import org.wso2.carbon.core.util.KeyStoreManager; import org.wso2.carbon.identity.application.common.model.FederatedAuthenticatorConfig; import org.wso2.carbon.identity.application.common.model.IdentityProvider; @@ -59,10 +57,6 @@ import org.wso2.carbon.identity.sso.saml.dto.SAMLSSOAuthnReqDTO; import org.wso2.carbon.identity.sso.saml.validators.SSOAuthnRequestValidator; import org.wso2.carbon.idp.mgt.IdentityProviderManager; -import org.wso2.carbon.registry.core.exceptions.RegistryException; -import org.wso2.carbon.registry.core.service.RegistryService; -import org.wso2.carbon.registry.core.session.UserRegistry; -import org.wso2.carbon.user.api.UserStoreException; import org.wso2.carbon.user.core.service.RealmService; import org.wso2.carbon.user.core.tenant.TenantManager; import org.wso2.carbon.utils.multitenancy.MultitenantConstants; @@ -89,7 +83,7 @@ /** * Tests Assertion building functionality. */ -@PrepareForTest({IdentityUtil.class, IdentityTenantUtil.class, IdentityProviderManager.class, OSGiDataHolder.class, +@PrepareForTest({IdentityUtil.class, IdentityTenantUtil.class, IdentityProviderManager.class, SSOServiceProviderConfigManager.class, SAMLSSOServiceProviderManager.class}) @WithCarbonHome @PowerMockIgnore({"javax.net.*", "javax.xml.*", "org.xml.*", "org.w3c.dom.*", @@ -128,20 +122,6 @@ public IObjectFactory getObjectFactory() { @Mock private X509Credential x509Credential; - @Mock - private UserRegistry registry; - - @Mock - private RegistryService registryService; - - private static OSGiDataHolder dataHolder = OSGiDataHolder.getInstance(); - - @BeforeTest - public void setUp() throws Exception { - - TestUtils.startTenantFlow(MultitenantConstants.SUPER_TENANT_DOMAIN_NAME); - } - @Test public void testBuildAssertion() throws Exception { @@ -210,7 +190,6 @@ public void validateACS() throws Exception { @Test public void validateACSWithoutIssuer() throws Exception { - setRegistryAndTenantDomain(); prepareIdentityPersistentManager(TestConstants.ATTRIBUTE_CONSUMER_INDEX, TestConstants.TRAVELOCITY_ISSUER, Collections.emptyList()); boolean isACSValied = SAMLSSOUtil.validateACS(MultitenantConstants.SUPER_TENANT_DOMAIN_NAME, TestConstants @@ -223,7 +202,6 @@ public void validateACSWithACSInSP() throws Exception { List acs = new ArrayList(); acs.add(TestConstants.ACS_URL); - setRegistryAndTenantDomain(); prepareIdentityPersistentManager(TestConstants.ATTRIBUTE_CONSUMER_INDEX, TestConstants.TRAVELOCITY_ISSUER, acs); boolean isACSValied = SAMLSSOUtil.validateACS(MultitenantConstants.SUPER_TENANT_DOMAIN_NAME, TestConstants .TRAVELOCITY_ISSUER, TestConstants.ACS_URL); @@ -390,17 +368,6 @@ private void prepareIdentityPersistentManager(String attrConsumerIndex, String i when(SAMLSSOServiceProviderManager.getInstance()).thenReturn(samlssoServiceProviderManager); } - private void setRegistryAndTenantDomain() throws UserStoreException, IdentityException, RegistryException { - - when(realmService.getTenantManager()).thenReturn(tenantManager); - SAMLSSOUtil.setRealmService(realmService); - SAMLSSOUtil.setTenantDomainInThreadLocal(MultitenantConstants.SUPER_TENANT_DOMAIN_NAME); - - mockStatic(OSGiDataHolder.class); - dataHolder.setRegistryService(registryService); - when(registryService.getConfigSystemRegistry(eq(0))).thenReturn(registry); - } - @Test public void testisSAMLNotOnOrAfterPeriodDefined() { From 7123cb3bbc7c5e69dabac4f5a252017bc50524d8 Mon Sep 17 00:00:00 2001 From: Udara Pathum Date: Wed, 21 Jun 2023 00:21:32 +0530 Subject: [PATCH 3/4] Use SAMLSSOServiceProviderManager OSGI service --- .../internal/SAMLQueryServiceComponent.java | 45 ++++++++++++++ .../query/saml/util/SAMLQueryRequestUtil.java | 5 +- .../sso/saml/admin/SAMLSSOConfigAdmin.java | 10 ++-- .../IdentitySAMLSSOServiceComponent.java | 24 ++++++++ ...IdentitySAMLSSOServiceComponentHolder.java | 60 +++++++++++++++++++ .../IdPInitSSOAuthnRequestProcessor.java | 4 +- .../SPInitLogoutRequestProcessor.java | 5 +- .../SPInitSSOAuthnRequestProcessor.java | 4 +- .../saml/servlet/SAMLSSOProviderServlet.java | 6 +- .../identity/sso/saml/util/SAMLSSOUtil.java | 10 +++- .../saml/admin/SAMLSSOConfigAdminTest.java | 12 +++- .../sso/saml/util/AssertionBuildingTest.java | 13 +++- .../sso/saml/util/SAMLSSOUtilTest.java | 13 +++- pom.xml | 4 +- 14 files changed, 185 insertions(+), 30 deletions(-) create mode 100644 components/org.wso2.carbon.identity.sso.saml/src/main/java/org/wso2/carbon/identity/sso/saml/internal/IdentitySAMLSSOServiceComponentHolder.java diff --git a/components/org.wso2.carbon.identity.query.saml/src/main/java/org/wso2/carbon/identity/query/saml/internal/SAMLQueryServiceComponent.java b/components/org.wso2.carbon.identity.query.saml/src/main/java/org/wso2/carbon/identity/query/saml/internal/SAMLQueryServiceComponent.java index 9f6402c8b..bed86b047 100644 --- a/components/org.wso2.carbon.identity.query.saml/src/main/java/org/wso2/carbon/identity/query/saml/internal/SAMLQueryServiceComponent.java +++ b/components/org.wso2.carbon.identity.query.saml/src/main/java/org/wso2/carbon/identity/query/saml/internal/SAMLQueryServiceComponent.java @@ -27,6 +27,7 @@ import org.osgi.service.component.annotations.Reference; import org.osgi.service.component.annotations.ReferenceCardinality; import org.osgi.service.component.annotations.ReferencePolicy; +import org.wso2.carbon.identity.core.SAMLSSOServiceProviderManager; import org.wso2.carbon.user.core.service.RealmService; /** @@ -41,6 +42,8 @@ public class SAMLQueryServiceComponent { private static RealmService realmservice = null; + private static SAMLSSOServiceProviderManager samlSSOServiceProviderManager = null; + /** * This method is used to get created realm service * @@ -106,4 +109,46 @@ protected void unsetRealmService(RealmService realmService) { log.debug("DefaultUserRealm unset in to bundle"); } } + + /** + * This method is used to set SAMLSSOServiceProviderManager instance + * + * @param samlSSOServiceProviderManager SAMLSSOServiceProviderManager instance + */ + @Reference( + name = "saml.sso.service.provider.manager", + service = SAMLSSOServiceProviderManager.class, + cardinality = ReferenceCardinality.MANDATORY, + policy = ReferencePolicy.DYNAMIC, + unbind = "unsetSAMLSSOServiceProviderManager") + protected void setSAMLSSOServiceProviderManager(SAMLSSOServiceProviderManager samlSSOServiceProviderManager) { + + this.samlSSOServiceProviderManager = samlSSOServiceProviderManager; + if (log.isDebugEnabled()) { + log.debug("SAMLSSOServiceProviderManager set in to bundle"); + } + } + + /** + * This method is used to un-set SAMLSSOServiceProviderManager instance + * + * @param samlSSOServiceProviderManager SAMLSSOServiceProviderManager instance + */ + protected void unsetSAMLSSOServiceProviderManager(SAMLSSOServiceProviderManager samlSSOServiceProviderManager) { + + this.samlSSOServiceProviderManager = null; + if (log.isDebugEnabled()) { + log.debug("SAMLSSOServiceProviderManager unset in to bundle"); + } + } + + /** + * This method is used to get SAMLSSOServiceProviderManager instance + * + * @return SAMLSSOServiceProviderManager instance + */ + public static SAMLSSOServiceProviderManager getSAMLSSOServiceProviderManager() { + + return samlSSOServiceProviderManager; + } } diff --git a/components/org.wso2.carbon.identity.query.saml/src/main/java/org/wso2/carbon/identity/query/saml/util/SAMLQueryRequestUtil.java b/components/org.wso2.carbon.identity.query.saml/src/main/java/org/wso2/carbon/identity/query/saml/util/SAMLQueryRequestUtil.java index 1e203816e..36c865df7 100644 --- a/components/org.wso2.carbon.identity.query.saml/src/main/java/org/wso2/carbon/identity/query/saml/util/SAMLQueryRequestUtil.java +++ b/components/org.wso2.carbon.identity.query.saml/src/main/java/org/wso2/carbon/identity/query/saml/util/SAMLQueryRequestUtil.java @@ -72,10 +72,10 @@ import org.w3c.dom.ls.LSSerializer; import org.wso2.carbon.context.CarbonContext; import org.wso2.carbon.identity.base.IdentityException; -import org.wso2.carbon.identity.core.SAMLSSOServiceProviderManager; import org.wso2.carbon.identity.core.model.SAMLSSOServiceProviderDO; import org.wso2.carbon.identity.query.saml.SignKeyDataHolder; import org.wso2.carbon.identity.query.saml.exception.IdentitySAML2QueryException; +import org.wso2.carbon.identity.query.saml.internal.SAMLQueryServiceComponent; import org.wso2.carbon.identity.saml.common.util.SAMLInitializer; import org.wso2.carbon.identity.sso.saml.SAMLSSOConstants; import org.wso2.carbon.identity.sso.saml.SSOServiceProviderConfigManager; @@ -211,7 +211,8 @@ public static SAMLSSOServiceProviderDO getServiceProviderConfig(String issuer) SAMLSSOServiceProviderDO ssoIdpConfigs = idPConfigManager.getServiceProvider(issuer); if (ssoIdpConfigs == null) { int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId(); - ssoIdpConfigs = SAMLSSOServiceProviderManager.getInstance().getServiceProvider(issuer, tenantId); + ssoIdpConfigs = SAMLQueryServiceComponent.getSAMLSSOServiceProviderManager() + .getServiceProvider(issuer, tenantId); } return ssoIdpConfigs; } catch (IdentityException e) { diff --git a/components/org.wso2.carbon.identity.sso.saml/src/main/java/org/wso2/carbon/identity/sso/saml/admin/SAMLSSOConfigAdmin.java b/components/org.wso2.carbon.identity.sso.saml/src/main/java/org/wso2/carbon/identity/sso/saml/admin/SAMLSSOConfigAdmin.java index 87ede2cbb..3f780473a 100644 --- a/components/org.wso2.carbon.identity.sso.saml/src/main/java/org/wso2/carbon/identity/sso/saml/admin/SAMLSSOConfigAdmin.java +++ b/components/org.wso2.carbon.identity.sso.saml/src/main/java/org/wso2/carbon/identity/sso/saml/admin/SAMLSSOConfigAdmin.java @@ -26,7 +26,6 @@ import org.wso2.carbon.context.CarbonContext; import org.wso2.carbon.core.util.KeyStoreManager; import org.wso2.carbon.identity.base.IdentityException; -import org.wso2.carbon.identity.core.SAMLSSOServiceProviderManager; import org.wso2.carbon.identity.core.model.SAMLSSOServiceProviderDO; import org.wso2.carbon.identity.core.util.IdentityTenantUtil; import org.wso2.carbon.identity.core.util.IdentityUtil; @@ -38,6 +37,7 @@ import org.wso2.carbon.identity.sso.saml.dto.SAMLSSOServiceProviderInfoDTO; import org.wso2.carbon.identity.sso.saml.exception.IdentitySAML2ClientException; import org.wso2.carbon.identity.sso.saml.internal.IdentitySAMLSSOServiceComponent; +import org.wso2.carbon.identity.sso.saml.internal.IdentitySAMLSSOServiceComponentHolder; import org.wso2.carbon.identity.sso.saml.util.SAMLSSOUtil; import org.wso2.carbon.registry.core.Registry; import org.wso2.carbon.registry.core.session.UserRegistry; @@ -86,7 +86,7 @@ public boolean addRelyingPartyServiceProvider(SAMLSSOServiceProviderDTO serviceP log.error(message); return false; } - return SAMLSSOServiceProviderManager.getInstance().addServiceProvider(serviceProviderDO, tenantId); + return IdentitySAMLSSOServiceComponentHolder.getInstance().getSAMLSSOServiceProviderManager().addServiceProvider(serviceProviderDO, tenantId); } catch (IdentityException e) { String message = "Error obtaining a registry for adding a new service provider"; throw new IdentityException(message, e); @@ -130,7 +130,7 @@ private String getIssuerWithQualifier(SAMLSSOServiceProviderDO serviceProviderDO private SAMLSSOServiceProviderDTO persistSAMLServiceProvider(SAMLSSOServiceProviderDO samlssoServiceProviderDO) throws IdentityException { - boolean response = SAMLSSOServiceProviderManager.getInstance() + boolean response = IdentitySAMLSSOServiceComponentHolder.getInstance().getSAMLSSOServiceProviderManager() .addServiceProvider(samlssoServiceProviderDO, tenantId); if (response) { return createSAMLSSOServiceProviderDTO(samlssoServiceProviderDO); @@ -410,7 +410,7 @@ private SAMLSSOServiceProviderDTO createSAMLSSOServiceProviderDTO(SAMLSSOService public SAMLSSOServiceProviderInfoDTO getServiceProviders() throws IdentityException { SAMLSSOServiceProviderDTO[] serviceProviders = null; try { - SAMLSSOServiceProviderDO[] providersSet = SAMLSSOServiceProviderManager.getInstance() + SAMLSSOServiceProviderDO[] providersSet = IdentitySAMLSSOServiceComponentHolder.getInstance().getSAMLSSOServiceProviderManager() .getServiceProviders(tenantId); serviceProviders = new SAMLSSOServiceProviderDTO[providersSet.length]; @@ -499,7 +499,7 @@ public SAMLSSOServiceProviderInfoDTO getServiceProviders() throws IdentityExcept */ public boolean removeServiceProvider(String issuer) throws IdentityException { try { - return SAMLSSOServiceProviderManager.getInstance().removeServiceProvider(issuer, tenantId); + return IdentitySAMLSSOServiceComponentHolder.getInstance().getSAMLSSOServiceProviderManager().removeServiceProvider(issuer, tenantId); } catch (IdentityException e) { throw new IdentityException("Error removing a Service Provider with issuer: " + issuer, e); } diff --git a/components/org.wso2.carbon.identity.sso.saml/src/main/java/org/wso2/carbon/identity/sso/saml/internal/IdentitySAMLSSOServiceComponent.java b/components/org.wso2.carbon.identity.sso.saml/src/main/java/org/wso2/carbon/identity/sso/saml/internal/IdentitySAMLSSOServiceComponent.java index d5dd9b1a2..166c6132a 100644 --- a/components/org.wso2.carbon.identity.sso.saml/src/main/java/org/wso2/carbon/identity/sso/saml/internal/IdentitySAMLSSOServiceComponent.java +++ b/components/org.wso2.carbon.identity.sso.saml/src/main/java/org/wso2/carbon/identity/sso/saml/internal/IdentitySAMLSSOServiceComponent.java @@ -34,6 +34,7 @@ import org.wso2.carbon.identity.application.mgt.ApplicationManagementService; import org.wso2.carbon.identity.application.mgt.listener.ApplicationMgtListener; import org.wso2.carbon.identity.base.IdentityConstants; +import org.wso2.carbon.identity.core.SAMLSSOServiceProviderManager; import org.wso2.carbon.identity.core.util.IdentityCoreInitializedEvent; import org.wso2.carbon.identity.core.util.IdentityUtil; import org.wso2.carbon.identity.event.handler.AbstractEventHandler; @@ -458,4 +459,27 @@ protected void unsetApplicationManagementService(ApplicationManagementService ap log.debug("Unset the ApplicationManagementService"); } } + + + @Reference( + name = "saml.sso.service.provider.manager", + service = org.wso2.carbon.identity.core.SAMLSSOServiceProviderManager.class, + cardinality = ReferenceCardinality.MANDATORY, + policy = ReferencePolicy.DYNAMIC, + unbind = "unsetSAMLSSOServiceProviderManager") + protected void setSAMLSSOServiceProviderManager(SAMLSSOServiceProviderManager samlSSOServiceProviderManager) { + + IdentitySAMLSSOServiceComponentHolder.getInstance().setSAMLSSOServiceProviderManager(samlSSOServiceProviderManager); + if (log.isDebugEnabled()) { + log.debug("SAMLSSOServiceProviderManager set in to bundle"); + } + } + + protected void unsetSAMLSSOServiceProviderManager(SAMLSSOServiceProviderManager samlSSOServiceProviderManager) { + + IdentitySAMLSSOServiceComponentHolder.getInstance().setSAMLSSOServiceProviderManager(null); + if (log.isDebugEnabled()) { + log.debug("SAMLSSOServiceProviderManager unset in to bundle"); + } + } } diff --git a/components/org.wso2.carbon.identity.sso.saml/src/main/java/org/wso2/carbon/identity/sso/saml/internal/IdentitySAMLSSOServiceComponentHolder.java b/components/org.wso2.carbon.identity.sso.saml/src/main/java/org/wso2/carbon/identity/sso/saml/internal/IdentitySAMLSSOServiceComponentHolder.java new file mode 100644 index 000000000..a68b32368 --- /dev/null +++ b/components/org.wso2.carbon.identity.sso.saml/src/main/java/org/wso2/carbon/identity/sso/saml/internal/IdentitySAMLSSOServiceComponentHolder.java @@ -0,0 +1,60 @@ +/* + * Copyright (c) 2023, WSO2 LLC. (http://www.wso2.com). + * + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.wso2.carbon.identity.sso.saml.internal; + +import org.wso2.carbon.identity.core.SAMLSSOServiceProviderManager; + +/** + * Identity SAML SSO Service Component Holder. + */ +public class IdentitySAMLSSOServiceComponentHolder { + + private SAMLSSOServiceProviderManager samlSSOServiceProviderManager; + + private static final IdentitySAMLSSOServiceComponentHolder instance = new IdentitySAMLSSOServiceComponentHolder(); + + private IdentitySAMLSSOServiceComponentHolder() { + + } + + public static IdentitySAMLSSOServiceComponentHolder getInstance() { + + return instance; + } + + /** + * Set SAMLSSOServiceProviderManager. + * + * @param samlSSOServiceProviderManager SAMLSSOServiceProviderManager. + */ + public void setSAMLSSOServiceProviderManager(SAMLSSOServiceProviderManager samlSSOServiceProviderManager) { + this.samlSSOServiceProviderManager = samlSSOServiceProviderManager; + } + + /** + * Get SAMLSSOServiceProviderManager. + * + * @return SAMLSSOServiceProviderManager. + */ + public SAMLSSOServiceProviderManager getSAMLSSOServiceProviderManager() { + return samlSSOServiceProviderManager; + } + + +} diff --git a/components/org.wso2.carbon.identity.sso.saml/src/main/java/org/wso2/carbon/identity/sso/saml/processors/IdPInitSSOAuthnRequestProcessor.java b/components/org.wso2.carbon.identity.sso.saml/src/main/java/org/wso2/carbon/identity/sso/saml/processors/IdPInitSSOAuthnRequestProcessor.java index 5097aa67a..a42fcd4ea 100644 --- a/components/org.wso2.carbon.identity.sso.saml/src/main/java/org/wso2/carbon/identity/sso/saml/processors/IdPInitSSOAuthnRequestProcessor.java +++ b/components/org.wso2.carbon.identity.sso.saml/src/main/java/org/wso2/carbon/identity/sso/saml/processors/IdPInitSSOAuthnRequestProcessor.java @@ -23,7 +23,6 @@ import org.opensaml.saml.saml2.core.Response; import org.wso2.carbon.context.PrivilegedCarbonContext; import org.wso2.carbon.identity.base.IdentityException; -import org.wso2.carbon.identity.core.SAMLSSOServiceProviderManager; import org.wso2.carbon.identity.core.model.SAMLSSOServiceProviderDO; import org.wso2.carbon.identity.sso.saml.SAMLSSOConstants; import org.wso2.carbon.identity.sso.saml.SSOServiceProviderConfigManager; @@ -32,6 +31,7 @@ import org.wso2.carbon.identity.sso.saml.builders.SAMLArtifactBuilder; import org.wso2.carbon.identity.sso.saml.dto.SAMLSSOAuthnReqDTO; import org.wso2.carbon.identity.sso.saml.dto.SAMLSSORespDTO; +import org.wso2.carbon.identity.sso.saml.internal.IdentitySAMLSSOServiceComponentHolder; import org.wso2.carbon.identity.sso.saml.session.SSOSessionPersistenceManager; import org.wso2.carbon.identity.sso.saml.util.SAMLSSOUtil; import org.wso2.carbon.registry.core.utils.UUIDGenerator; @@ -231,7 +231,7 @@ private SAMLSSOServiceProviderDO getServiceProviderConfig(SAMLSSOAuthnReqDTO aut .getServiceProvider(authnReqDTO.getIssuer()); if (ssoIdpConfigs == null) { int tenantID = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(); - ssoIdpConfigs = SAMLSSOServiceProviderManager.getInstance() + ssoIdpConfigs = IdentitySAMLSSOServiceComponentHolder.getInstance().getSAMLSSOServiceProviderManager() .getServiceProvider(authnReqDTO.getIssuer(), tenantID); authnReqDTO.setStratosDeployment(false); // not stratos } else { diff --git a/components/org.wso2.carbon.identity.sso.saml/src/main/java/org/wso2/carbon/identity/sso/saml/processors/SPInitLogoutRequestProcessor.java b/components/org.wso2.carbon.identity.sso.saml/src/main/java/org/wso2/carbon/identity/sso/saml/processors/SPInitLogoutRequestProcessor.java index 96ddba53d..f07b14d8d 100644 --- a/components/org.wso2.carbon.identity.sso.saml/src/main/java/org/wso2/carbon/identity/sso/saml/processors/SPInitLogoutRequestProcessor.java +++ b/components/org.wso2.carbon.identity.sso.saml/src/main/java/org/wso2/carbon/identity/sso/saml/processors/SPInitLogoutRequestProcessor.java @@ -25,7 +25,6 @@ import org.wso2.carbon.context.PrivilegedCarbonContext; import org.wso2.carbon.identity.application.common.util.IdentityApplicationManagementUtil; import org.wso2.carbon.identity.base.IdentityException; -import org.wso2.carbon.identity.core.SAMLSSOServiceProviderManager; import org.wso2.carbon.identity.core.model.SAMLSSOServiceProviderDO; import org.wso2.carbon.identity.core.util.IdentityTenantUtil; import org.wso2.carbon.identity.core.util.IdentityUtil; @@ -33,6 +32,7 @@ import org.wso2.carbon.identity.sso.saml.SSOServiceProviderConfigManager; import org.wso2.carbon.identity.sso.saml.builders.SingleLogoutMessageBuilder; import org.wso2.carbon.identity.sso.saml.dto.SAMLSSOReqValidationResponseDTO; +import org.wso2.carbon.identity.sso.saml.internal.IdentitySAMLSSOServiceComponentHolder; import org.wso2.carbon.identity.sso.saml.session.SSOSessionPersistenceManager; import org.wso2.carbon.identity.sso.saml.session.SessionInfoData; import org.wso2.carbon.identity.sso.saml.util.LambdaExceptionUtils; @@ -269,7 +269,8 @@ private SAMLSSOServiceProviderDO getServiceProviderConfig(String issuer, String privilegedCarbonContext.setTenantId(tenantId); privilegedCarbonContext.setTenantDomain(tenantDomain); IdentityTenantUtil.initializeRegistry(tenantId, tenantDomain); - ssoIdpConfigs = SAMLSSOServiceProviderManager.getInstance().getServiceProvider(issuer, tenantId); + ssoIdpConfigs = IdentitySAMLSSOServiceComponentHolder.getInstance().getSAMLSSOServiceProviderManager() + .getServiceProvider(issuer, tenantId); } finally { PrivilegedCarbonContext.endTenantFlow(); } diff --git a/components/org.wso2.carbon.identity.sso.saml/src/main/java/org/wso2/carbon/identity/sso/saml/processors/SPInitSSOAuthnRequestProcessor.java b/components/org.wso2.carbon.identity.sso.saml/src/main/java/org/wso2/carbon/identity/sso/saml/processors/SPInitSSOAuthnRequestProcessor.java index b7a6c8579..b9ae527ea 100644 --- a/components/org.wso2.carbon.identity.sso.saml/src/main/java/org/wso2/carbon/identity/sso/saml/processors/SPInitSSOAuthnRequestProcessor.java +++ b/components/org.wso2.carbon.identity.sso.saml/src/main/java/org/wso2/carbon/identity/sso/saml/processors/SPInitSSOAuthnRequestProcessor.java @@ -24,7 +24,6 @@ import org.opensaml.saml.saml2.core.Response; import org.wso2.carbon.context.PrivilegedCarbonContext; import org.wso2.carbon.identity.base.IdentityException; -import org.wso2.carbon.identity.core.SAMLSSOServiceProviderManager; import org.wso2.carbon.identity.core.model.SAMLSSOServiceProviderDO; import org.wso2.carbon.identity.core.util.IdentityTenantUtil; @@ -35,6 +34,7 @@ import org.wso2.carbon.identity.sso.saml.builders.SAMLArtifactBuilder; import org.wso2.carbon.identity.sso.saml.dto.SAMLSSOAuthnReqDTO; import org.wso2.carbon.identity.sso.saml.dto.SAMLSSORespDTO; +import org.wso2.carbon.identity.sso.saml.internal.IdentitySAMLSSOServiceComponentHolder; import org.wso2.carbon.identity.sso.saml.session.SSOSessionPersistenceManager; import org.wso2.carbon.identity.sso.saml.util.SAMLSSOUtil; import org.wso2.carbon.registry.core.utils.UUIDGenerator; @@ -219,7 +219,7 @@ private SAMLSSOServiceProviderDO getServiceProviderConfig(SAMLSSOAuthnReqDTO aut IdentityTenantUtil.initializeRegistry(PrivilegedCarbonContext.getThreadLocalCarbonContext() .getTenantId(), PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantDomain()); int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(); - ssoIdpConfigs = SAMLSSOServiceProviderManager.getInstance() + ssoIdpConfigs = IdentitySAMLSSOServiceComponentHolder.getInstance().getSAMLSSOServiceProviderManager() .getServiceProvider(authnReqDTO.getIssuer(), tenantId); authnReqDTO.setStratosDeployment(false); // not stratos } else { diff --git a/components/org.wso2.carbon.identity.sso.saml/src/main/java/org/wso2/carbon/identity/sso/saml/servlet/SAMLSSOProviderServlet.java b/components/org.wso2.carbon.identity.sso.saml/src/main/java/org/wso2/carbon/identity/sso/saml/servlet/SAMLSSOProviderServlet.java index 9e364c603..96540bcf4 100644 --- a/components/org.wso2.carbon.identity.sso.saml/src/main/java/org/wso2/carbon/identity/sso/saml/servlet/SAMLSSOProviderServlet.java +++ b/components/org.wso2.carbon.identity.sso.saml/src/main/java/org/wso2/carbon/identity/sso/saml/servlet/SAMLSSOProviderServlet.java @@ -46,7 +46,6 @@ import org.wso2.carbon.identity.application.mgt.ApplicationManagementService; import org.wso2.carbon.identity.base.IdentityConstants; import org.wso2.carbon.identity.base.IdentityException; -import org.wso2.carbon.identity.core.SAMLSSOServiceProviderManager; import org.wso2.carbon.identity.core.ServiceURLBuilder; import org.wso2.carbon.identity.core.URLBuilderException; import org.wso2.carbon.identity.core.model.IdentityCookieConfig; @@ -77,6 +76,7 @@ import org.wso2.carbon.identity.sso.saml.exception.IdentitySAML2ClientException; import org.wso2.carbon.identity.sso.saml.exception.IdentitySAML2SSOException; import org.wso2.carbon.identity.sso.saml.internal.IdentitySAMLSSOServiceComponent; +import org.wso2.carbon.identity.sso.saml.internal.IdentitySAMLSSOServiceComponentHolder; import org.wso2.carbon.identity.sso.saml.session.SSOSessionPersistenceManager; import org.wso2.carbon.identity.sso.saml.session.SessionInfoData; import org.wso2.carbon.identity.sso.saml.util.SAMLSOAPUtils; @@ -1798,8 +1798,8 @@ private SAMLSSOServiceProviderDO getServiceProviderConfig(SAMLSSOAuthnReqDTO aut privilegedCarbonContext.setTenantId(tenantId); privilegedCarbonContext.setTenantDomain(tenantDomain); - serviceProviderConfigs = SAMLSSOServiceProviderManager.getInstance() - .getServiceProvider(issuer, tenantId); + serviceProviderConfigs = IdentitySAMLSSOServiceComponentHolder.getInstance() + .getSAMLSSOServiceProviderManager().getServiceProvider(issuer, tenantId); authnReqDTO.setStratosDeployment(false); // not stratos } catch (IdentityException e) { throw new IdentitySAML2SSOException("Error occurred while retrieving SAML service provider for " diff --git a/components/org.wso2.carbon.identity.sso.saml/src/main/java/org/wso2/carbon/identity/sso/saml/util/SAMLSSOUtil.java b/components/org.wso2.carbon.identity.sso.saml/src/main/java/org/wso2/carbon/identity/sso/saml/util/SAMLSSOUtil.java index df4510227..e5e58bd51 100644 --- a/components/org.wso2.carbon.identity.sso.saml/src/main/java/org/wso2/carbon/identity/sso/saml/util/SAMLSSOUtil.java +++ b/components/org.wso2.carbon.identity.sso.saml/src/main/java/org/wso2/carbon/identity/sso/saml/util/SAMLSSOUtil.java @@ -98,6 +98,7 @@ import org.wso2.carbon.identity.sso.saml.exception.IdentitySAML2ClientException; import org.wso2.carbon.identity.sso.saml.exception.IdentitySAML2SSOException; import org.wso2.carbon.identity.sso.saml.extension.SAMLExtensionProcessor; +import org.wso2.carbon.identity.sso.saml.internal.IdentitySAMLSSOServiceComponentHolder; import org.wso2.carbon.identity.sso.saml.processors.IdPInitLogoutRequestProcessor; import org.wso2.carbon.identity.sso.saml.processors.IdPInitSSOAuthnRequestProcessor; import org.wso2.carbon.identity.sso.saml.processors.SPInitLogoutRequestProcessor; @@ -1842,7 +1843,8 @@ public static boolean isSAMLIssuerExists(String issuerName, String tenantDomain) privilegedCarbonContext.setTenantDomain(tenantDomain); IdentityTenantUtil.initializeRegistry(tenantId, tenantDomain); - return SAMLSSOServiceProviderManager.getInstance().isServiceProviderExists(issuerName, tenantId); + return IdentitySAMLSSOServiceComponentHolder.getInstance().getSAMLSSOServiceProviderManager() + .isServiceProviderExists(issuerName, tenantId); } catch (IdentityException e) { throw new IdentitySAML2SSOException("Error occurred while validating existence of SAML service provider " + "'" + issuerName + "' in the tenant domain '" + tenantDomain + "'"); @@ -1897,7 +1899,8 @@ public static boolean validateACS(String tenantDomain, String issuerName, String privilegedCarbonContext.setTenantId(tenantId); privilegedCarbonContext.setTenantDomain(tenantDomain); - SAMLSSOServiceProviderDO spDO = SAMLSSOServiceProviderManager.getInstance().getServiceProvider(issuerName, + SAMLSSOServiceProviderDO spDO = IdentitySAMLSSOServiceComponentHolder.getInstance() + .getSAMLSSOServiceProviderManager().getServiceProvider(issuerName, tenantId); if (StringUtils.isBlank(requestedACSUrl) || !spDO.getAssertionConsumerUrlList().contains (requestedACSUrl)) { @@ -2679,7 +2682,8 @@ private static SAMLSSOServiceProviderDO getSAMLServiceProviderFromRegistry(Strin privilegedCarbonContext.setTenantDomain(tenantDomain); IdentityTenantUtil.getTenantRegistryLoader().loadTenantRegistry(tenantId); - return SAMLSSOServiceProviderManager.getInstance().getServiceProvider(issuer, tenantId); + return IdentitySAMLSSOServiceComponentHolder.getInstance().getSAMLSSOServiceProviderManager() + .getServiceProvider(issuer, tenantId); } catch (IdentityException | RegistryException e) { throw new IdentitySAML2SSOException("Error occurred while retrieving SAML service provider for " diff --git a/components/org.wso2.carbon.identity.sso.saml/src/test/java/org/wso2/carbon/identity/sso/saml/admin/SAMLSSOConfigAdminTest.java b/components/org.wso2.carbon.identity.sso.saml/src/test/java/org/wso2/carbon/identity/sso/saml/admin/SAMLSSOConfigAdminTest.java index b3804e3cb..0640cf921 100644 --- a/components/org.wso2.carbon.identity.sso.saml/src/test/java/org/wso2/carbon/identity/sso/saml/admin/SAMLSSOConfigAdminTest.java +++ b/components/org.wso2.carbon.identity.sso.saml/src/test/java/org/wso2/carbon/identity/sso/saml/admin/SAMLSSOConfigAdminTest.java @@ -36,6 +36,7 @@ import org.wso2.carbon.identity.sso.saml.TestUtils; import org.wso2.carbon.identity.sso.saml.dto.SAMLSSOServiceProviderDTO; import org.wso2.carbon.identity.sso.saml.exception.IdentitySAML2ClientException; +import org.wso2.carbon.identity.sso.saml.internal.IdentitySAMLSSOServiceComponentHolder; import org.wso2.carbon.registry.core.session.UserRegistry; import org.wso2.carbon.utils.multitenancy.MultitenantConstants; @@ -44,7 +45,7 @@ import static org.mockito.ArgumentMatchers.anyString; import static org.powermock.api.mockito.PowerMockito.*; -@PrepareForTest({SAMLSSOServiceProviderManager.class, SSOServiceProviderConfigManager.class, +@PrepareForTest({IdentitySAMLSSOServiceComponentHolder.class, SSOServiceProviderConfigManager.class, SAMLSSOServiceProviderDO.class, Parser.class, UserRegistry.class, SAMLSSOConfigAdmin.class}) @PowerMockIgnore({"javax.xml.*", "org.xml.*", "org.apache.xerces.*", "org.w3c.dom.*"}) public class SAMLSSOConfigAdminTest extends PowerMockTestCase { @@ -58,6 +59,8 @@ public class SAMLSSOConfigAdminTest extends PowerMockTestCase { @Mock private SAMLSSOServiceProviderManager samlSSOServiceProviderManager; + @Mock IdentitySAMLSSOServiceComponentHolder identitySAMLSSOServiceComponentHolder; + @Mock SAMLSSOServiceProviderDO samlssoServiceProvDO; @@ -72,8 +75,11 @@ public void setUp() throws Exception { TestUtils.startTenantFlow(MultitenantConstants.SUPER_TENANT_DOMAIN_NAME); samlssoConfigAdmin = new SAMLSSOConfigAdmin(userRegistry); - mockStatic(SAMLSSOServiceProviderManager.class); - when(SAMLSSOServiceProviderManager.getInstance()).thenReturn(samlSSOServiceProviderManager); + mockStatic(IdentitySAMLSSOServiceComponentHolder.class); + when(IdentitySAMLSSOServiceComponentHolder.getInstance()) + .thenReturn(identitySAMLSSOServiceComponentHolder); + when(identitySAMLSSOServiceComponentHolder.getSAMLSSOServiceProviderManager()) + .thenReturn(samlSSOServiceProviderManager); mockStatic(SAMLSSOServiceProviderDO.class); } diff --git a/components/org.wso2.carbon.identity.sso.saml/src/test/java/org/wso2/carbon/identity/sso/saml/util/AssertionBuildingTest.java b/components/org.wso2.carbon.identity.sso.saml/src/test/java/org/wso2/carbon/identity/sso/saml/util/AssertionBuildingTest.java index d1ecc26e0..7fa2d7ac6 100644 --- a/components/org.wso2.carbon.identity.sso.saml/src/test/java/org/wso2/carbon/identity/sso/saml/util/AssertionBuildingTest.java +++ b/components/org.wso2.carbon.identity.sso.saml/src/test/java/org/wso2/carbon/identity/sso/saml/util/AssertionBuildingTest.java @@ -55,6 +55,7 @@ import org.wso2.carbon.identity.sso.saml.TestConstants; import org.wso2.carbon.identity.sso.saml.TestUtils; import org.wso2.carbon.identity.sso.saml.dto.SAMLSSOAuthnReqDTO; +import org.wso2.carbon.identity.sso.saml.internal.IdentitySAMLSSOServiceComponentHolder; import org.wso2.carbon.identity.sso.saml.validators.SSOAuthnRequestValidator; import org.wso2.carbon.idp.mgt.IdentityProviderManager; import org.wso2.carbon.user.core.service.RealmService; @@ -84,7 +85,7 @@ * Tests Assertion building functionality. */ @PrepareForTest({IdentityUtil.class, IdentityTenantUtil.class, IdentityProviderManager.class, - SSOServiceProviderConfigManager.class, SAMLSSOServiceProviderManager.class}) + SSOServiceProviderConfigManager.class, IdentitySAMLSSOServiceComponentHolder.class}) @WithCarbonHome @PowerMockIgnore({"javax.net.*", "javax.xml.*", "org.xml.*", "org.w3c.dom.*", "javax.security.*", "org.mockito.*"}) @@ -98,6 +99,9 @@ public IObjectFactory getObjectFactory() { @Mock private RealmService realmService; + @Mock + private IdentitySAMLSSOServiceComponentHolder identitySAMLSSOServiceComponentHolder; + @Mock private SAMLSSOServiceProviderManager samlssoServiceProviderManager; @@ -364,8 +368,11 @@ private void prepareIdentityPersistentManager(String attrConsumerIndex, String i samlssoServiceProviderDO.setAssertionConsumerUrls(acsList); when(samlssoServiceProviderManager.getServiceProvider(eq(issuer), anyInt())) .thenReturn(samlssoServiceProviderDO); - mockStatic(SAMLSSOServiceProviderManager.class); - when(SAMLSSOServiceProviderManager.getInstance()).thenReturn(samlssoServiceProviderManager); + mockStatic(IdentitySAMLSSOServiceComponentHolder.class); + when(IdentitySAMLSSOServiceComponentHolder.getInstance()) + .thenReturn(identitySAMLSSOServiceComponentHolder); + when(identitySAMLSSOServiceComponentHolder.getSAMLSSOServiceProviderManager()) + .thenReturn(samlssoServiceProviderManager); } @Test diff --git a/components/org.wso2.carbon.identity.sso.saml/src/test/java/org/wso2/carbon/identity/sso/saml/util/SAMLSSOUtilTest.java b/components/org.wso2.carbon.identity.sso.saml/src/test/java/org/wso2/carbon/identity/sso/saml/util/SAMLSSOUtilTest.java index 7d65a3843..846ebcecb 100644 --- a/components/org.wso2.carbon.identity.sso.saml/src/test/java/org/wso2/carbon/identity/sso/saml/util/SAMLSSOUtilTest.java +++ b/components/org.wso2.carbon.identity.sso.saml/src/test/java/org/wso2/carbon/identity/sso/saml/util/SAMLSSOUtilTest.java @@ -53,6 +53,7 @@ import org.wso2.carbon.identity.sso.saml.builders.X509CredentialImpl; import org.wso2.carbon.identity.sso.saml.exception.IdentitySAML2SSOException; import org.wso2.carbon.identity.sso.saml.extension.eidas.EidasExtensionProcessor; +import org.wso2.carbon.identity.sso.saml.internal.IdentitySAMLSSOServiceComponentHolder; import org.wso2.carbon.identity.sso.saml.session.SSOSessionPersistenceManager; import org.wso2.carbon.identity.sso.saml.session.SessionInfoData; import org.wso2.carbon.idp.mgt.IdentityProviderManagementException; @@ -82,7 +83,7 @@ * Unit test cases for SAMLSSOUtil. */ @PrepareForTest({IdentityProviderManager.class, IdentityUtil.class, IdentityApplicationManagementUtil.class, - KeyStoreManager.class, SAMLSSOServiceProviderManager.class, SSOServiceProviderConfigManager.class, + KeyStoreManager.class, IdentitySAMLSSOServiceComponentHolder.class, SSOServiceProviderConfigManager.class, IdentityTenantUtil.class, ServiceURLBuilder.class, IdentityConstants.class, FrameworkServiceComponent.class}) @PowerMockIgnore({"javax.xml.*", "org.xml.*", "org.w3c.dom.*", "org.apache.xerces.*"}) public class SAMLSSOUtilTest extends PowerMockTestCase { @@ -112,6 +113,9 @@ public class SAMLSSOUtilTest extends PowerMockTestCase { @Mock private SAMLSSOServiceProviderManager samlSSOServiceProviderManager; + @Mock + private IdentitySAMLSSOServiceComponentHolder identitySAMLSSOServiceComponentHolder; + @Mock private SSOServiceProviderConfigManager ssoServiceProviderConfigManager; @@ -155,8 +159,11 @@ private void prepareForGetSPConfig() throws Exception { when(samlSSOServiceProviderManager.getServiceProvider(anyString(), anyInt())) .thenReturn(samlssoServiceProviderDO); - mockStatic(SAMLSSOServiceProviderManager.class); - when(SAMLSSOServiceProviderManager.getInstance()).thenReturn(samlSSOServiceProviderManager); + mockStatic(IdentitySAMLSSOServiceComponentHolder.class); + when(IdentitySAMLSSOServiceComponentHolder.getInstance()) + .thenReturn(identitySAMLSSOServiceComponentHolder); + when(identitySAMLSSOServiceComponentHolder.getSAMLSSOServiceProviderManager()) + .thenReturn(samlSSOServiceProviderManager); when(samlSSOServiceProviderManager.isServiceProviderExists(anyString(), anyInt())).thenReturn(true); mockStatic(SSOServiceProviderConfigManager.class); diff --git a/pom.xml b/pom.xml index a44fad625..54e521e00 100644 --- a/pom.xml +++ b/pom.xml @@ -452,8 +452,8 @@ 4.9.0 4.9.0 - 5.25.157 - [5.15.0, 7.0.0) + 5.25.234 + [5.25.234, 7.0.0) 1.0.0 From 5e4d3638a106650b0db979d01595c065817c8416 Mon Sep 17 00:00:00 2001 From: Udara Pathum Date: Thu, 22 Jun 2023 15:01:38 +0530 Subject: [PATCH 4/4] Fix formatting issues --- .../identity/sso/saml/admin/SAMLSSOConfigAdmin.java | 10 ++++++---- .../IdentitySAMLSSOServiceComponentHolder.java | 2 ++ .../carbon/identity/sso/saml/util/SAMLSSOUtil.java | 3 +-- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/components/org.wso2.carbon.identity.sso.saml/src/main/java/org/wso2/carbon/identity/sso/saml/admin/SAMLSSOConfigAdmin.java b/components/org.wso2.carbon.identity.sso.saml/src/main/java/org/wso2/carbon/identity/sso/saml/admin/SAMLSSOConfigAdmin.java index 3f780473a..d5a3beb83 100644 --- a/components/org.wso2.carbon.identity.sso.saml/src/main/java/org/wso2/carbon/identity/sso/saml/admin/SAMLSSOConfigAdmin.java +++ b/components/org.wso2.carbon.identity.sso.saml/src/main/java/org/wso2/carbon/identity/sso/saml/admin/SAMLSSOConfigAdmin.java @@ -86,7 +86,8 @@ public boolean addRelyingPartyServiceProvider(SAMLSSOServiceProviderDTO serviceP log.error(message); return false; } - return IdentitySAMLSSOServiceComponentHolder.getInstance().getSAMLSSOServiceProviderManager().addServiceProvider(serviceProviderDO, tenantId); + return IdentitySAMLSSOServiceComponentHolder.getInstance().getSAMLSSOServiceProviderManager() + .addServiceProvider(serviceProviderDO, tenantId); } catch (IdentityException e) { String message = "Error obtaining a registry for adding a new service provider"; throw new IdentityException(message, e); @@ -410,8 +411,8 @@ private SAMLSSOServiceProviderDTO createSAMLSSOServiceProviderDTO(SAMLSSOService public SAMLSSOServiceProviderInfoDTO getServiceProviders() throws IdentityException { SAMLSSOServiceProviderDTO[] serviceProviders = null; try { - SAMLSSOServiceProviderDO[] providersSet = IdentitySAMLSSOServiceComponentHolder.getInstance().getSAMLSSOServiceProviderManager() - .getServiceProviders(tenantId); + SAMLSSOServiceProviderDO[] providersSet = IdentitySAMLSSOServiceComponentHolder.getInstance() + .getSAMLSSOServiceProviderManager().getServiceProviders(tenantId); serviceProviders = new SAMLSSOServiceProviderDTO[providersSet.length]; for (int i = 0; i < providersSet.length; i++) { @@ -499,7 +500,8 @@ public SAMLSSOServiceProviderInfoDTO getServiceProviders() throws IdentityExcept */ public boolean removeServiceProvider(String issuer) throws IdentityException { try { - return IdentitySAMLSSOServiceComponentHolder.getInstance().getSAMLSSOServiceProviderManager().removeServiceProvider(issuer, tenantId); + return IdentitySAMLSSOServiceComponentHolder.getInstance() + .getSAMLSSOServiceProviderManager().removeServiceProvider(issuer, tenantId); } catch (IdentityException e) { throw new IdentityException("Error removing a Service Provider with issuer: " + issuer, e); } diff --git a/components/org.wso2.carbon.identity.sso.saml/src/main/java/org/wso2/carbon/identity/sso/saml/internal/IdentitySAMLSSOServiceComponentHolder.java b/components/org.wso2.carbon.identity.sso.saml/src/main/java/org/wso2/carbon/identity/sso/saml/internal/IdentitySAMLSSOServiceComponentHolder.java index a68b32368..b2c109cf2 100644 --- a/components/org.wso2.carbon.identity.sso.saml/src/main/java/org/wso2/carbon/identity/sso/saml/internal/IdentitySAMLSSOServiceComponentHolder.java +++ b/components/org.wso2.carbon.identity.sso.saml/src/main/java/org/wso2/carbon/identity/sso/saml/internal/IdentitySAMLSSOServiceComponentHolder.java @@ -44,6 +44,7 @@ public static IdentitySAMLSSOServiceComponentHolder getInstance() { * @param samlSSOServiceProviderManager SAMLSSOServiceProviderManager. */ public void setSAMLSSOServiceProviderManager(SAMLSSOServiceProviderManager samlSSOServiceProviderManager) { + this.samlSSOServiceProviderManager = samlSSOServiceProviderManager; } @@ -53,6 +54,7 @@ public void setSAMLSSOServiceProviderManager(SAMLSSOServiceProviderManager samlS * @return SAMLSSOServiceProviderManager. */ public SAMLSSOServiceProviderManager getSAMLSSOServiceProviderManager() { + return samlSSOServiceProviderManager; } diff --git a/components/org.wso2.carbon.identity.sso.saml/src/main/java/org/wso2/carbon/identity/sso/saml/util/SAMLSSOUtil.java b/components/org.wso2.carbon.identity.sso.saml/src/main/java/org/wso2/carbon/identity/sso/saml/util/SAMLSSOUtil.java index e5e58bd51..d152bb25e 100644 --- a/components/org.wso2.carbon.identity.sso.saml/src/main/java/org/wso2/carbon/identity/sso/saml/util/SAMLSSOUtil.java +++ b/components/org.wso2.carbon.identity.sso.saml/src/main/java/org/wso2/carbon/identity/sso/saml/util/SAMLSSOUtil.java @@ -1900,8 +1900,7 @@ public static boolean validateACS(String tenantDomain, String issuerName, String privilegedCarbonContext.setTenantDomain(tenantDomain); SAMLSSOServiceProviderDO spDO = IdentitySAMLSSOServiceComponentHolder.getInstance() - .getSAMLSSOServiceProviderManager().getServiceProvider(issuerName, - tenantId); + .getSAMLSSOServiceProviderManager().getServiceProvider(issuerName, tenantId); if (StringUtils.isBlank(requestedACSUrl) || !spDO.getAssertionConsumerUrlList().contains (requestedACSUrl)) { String msg = "ALERT: Invalid Assertion Consumer URL value '" + requestedACSUrl + "' in the " +