From d7d8318dc12c082c1781973dcca02b2e69d142c4 Mon Sep 17 00:00:00 2001 From: Osara-B Date: Fri, 20 Dec 2024 14:17:14 +0530 Subject: [PATCH] Introduce SAMLSSOServiceProviderDAO Factory class --- .../core/SAMLSSOServiceProviderManager.java | 5 +- ...egistrySAMLSSOServiceProviderDAOImpl.java} | 6 +- .../dao/SAMLSSOPersistenceManagerFactory.java | 58 ++++++++++++++ .../IdentityPersistenceManager.java | 8 +- .../SAMLSSOPersistenceManagerFactoryTest.java | 78 +++++++++++++++++++ .../dao/SAMLSSOServiceProviderDAOTest.java | 4 +- .../src/test/resources/testng.xml | 1 + 7 files changed, 149 insertions(+), 11 deletions(-) rename components/identity-core/org.wso2.carbon.identity.core/src/main/java/org/wso2/carbon/identity/core/dao/{SAMLSSOServiceProviderRegistryDAOImpl.java => RegistrySAMLSSOServiceProviderDAOImpl.java} (99%) create mode 100644 components/identity-core/org.wso2.carbon.identity.core/src/main/java/org/wso2/carbon/identity/core/dao/SAMLSSOPersistenceManagerFactory.java create mode 100644 components/identity-core/org.wso2.carbon.identity.core/src/test/java/org/wso2/carbon/identity/core/dao/SAMLSSOPersistenceManagerFactoryTest.java diff --git a/components/identity-core/org.wso2.carbon.identity.core/src/main/java/org/wso2/carbon/identity/core/SAMLSSOServiceProviderManager.java b/components/identity-core/org.wso2.carbon.identity.core/src/main/java/org/wso2/carbon/identity/core/SAMLSSOServiceProviderManager.java index 297c8205258f..e3ce1f05d743 100644 --- a/components/identity-core/org.wso2.carbon.identity.core/src/main/java/org/wso2/carbon/identity/core/SAMLSSOServiceProviderManager.java +++ b/components/identity-core/org.wso2.carbon.identity.core/src/main/java/org/wso2/carbon/identity/core/SAMLSSOServiceProviderManager.java @@ -19,8 +19,8 @@ package org.wso2.carbon.identity.core; import org.wso2.carbon.identity.base.IdentityException; +import org.wso2.carbon.identity.core.dao.SAMLSSOPersistenceManagerFactory; import org.wso2.carbon.identity.core.dao.SAMLSSOServiceProviderDAO; -import org.wso2.carbon.identity.core.dao.SAMLSSOServiceProviderRegistryDAOImpl; import org.wso2.carbon.identity.core.model.SAMLSSOServiceProviderDO; /** @@ -29,7 +29,8 @@ */ public class SAMLSSOServiceProviderManager { - private static SAMLSSOServiceProviderDAO serviceProviderDAO = new SAMLSSOServiceProviderRegistryDAOImpl(); + SAMLSSOPersistenceManagerFactory samlSSOPersistenceManagerFactory = new SAMLSSOPersistenceManagerFactory(); + SAMLSSOServiceProviderDAO serviceProviderDAO = samlSSOPersistenceManagerFactory.getSAMLServiceProviderPersistenceManager(); /** * Add a saml service provider. diff --git a/components/identity-core/org.wso2.carbon.identity.core/src/main/java/org/wso2/carbon/identity/core/dao/SAMLSSOServiceProviderRegistryDAOImpl.java b/components/identity-core/org.wso2.carbon.identity.core/src/main/java/org/wso2/carbon/identity/core/dao/RegistrySAMLSSOServiceProviderDAOImpl.java similarity index 99% rename from components/identity-core/org.wso2.carbon.identity.core/src/main/java/org/wso2/carbon/identity/core/dao/SAMLSSOServiceProviderRegistryDAOImpl.java rename to components/identity-core/org.wso2.carbon.identity.core/src/main/java/org/wso2/carbon/identity/core/dao/RegistrySAMLSSOServiceProviderDAOImpl.java index 84e410a5d70e..f07d50eb03b5 100644 --- a/components/identity-core/org.wso2.carbon.identity.core/src/main/java/org/wso2/carbon/identity/core/dao/SAMLSSOServiceProviderRegistryDAOImpl.java +++ b/components/identity-core/org.wso2.carbon.identity.core/src/main/java/org/wso2/carbon/identity/core/dao/RegistrySAMLSSOServiceProviderDAOImpl.java @@ -55,7 +55,7 @@ /** * This class is used for managing SAML SSO service providers in the Registry. */ -public class SAMLSSOServiceProviderRegistryDAOImpl extends AbstractDAO +public class RegistrySAMLSSOServiceProviderDAOImpl extends AbstractDAO implements SAMLSSOServiceProviderDAO { private static final String CERTIFICATE_PROPERTY_NAME = "CERTIFICATE"; @@ -67,9 +67,9 @@ public class SAMLSSOServiceProviderRegistryDAOImpl extends AbstractDAO clazz, String fieldName, Object newValue) + throws NoSuchFieldException, IllegalAccessException { + + Field field = clazz.getDeclaredField(fieldName); + field.setAccessible(true); + field.set(null, newValue); + } +} \ No newline at end of file diff --git a/components/identity-core/org.wso2.carbon.identity.core/src/test/java/org/wso2/carbon/identity/core/dao/SAMLSSOServiceProviderDAOTest.java b/components/identity-core/org.wso2.carbon.identity.core/src/test/java/org/wso2/carbon/identity/core/dao/SAMLSSOServiceProviderDAOTest.java index d7cbcb256b8c..6b3636f4744a 100644 --- a/components/identity-core/org.wso2.carbon.identity.core/src/test/java/org/wso2/carbon/identity/core/dao/SAMLSSOServiceProviderDAOTest.java +++ b/components/identity-core/org.wso2.carbon.identity.core/src/test/java/org/wso2/carbon/identity/core/dao/SAMLSSOServiceProviderDAOTest.java @@ -70,7 +70,7 @@ */ public class SAMLSSOServiceProviderDAOTest { - private SAMLSSOServiceProviderRegistryDAOImpl objUnderTest; + private RegistrySAMLSSOServiceProviderDAOImpl objUnderTest; private boolean transactionStarted = false; private Registry mockRegistry; @@ -106,7 +106,7 @@ public Object answer(InvocationOnMock invocationOnMock) throws Throwable { } }).when(mockRegistry).beginTransaction(); - objUnderTest = new SAMLSSOServiceProviderRegistryDAOImpl(); + objUnderTest = new RegistrySAMLSSOServiceProviderDAOImpl(); identityTenantUtil = mockStatic(IdentityTenantUtil.class); when(IdentityTenantUtil.getRegistryService()).thenReturn(mockRegistryService); when(mockRegistryService.getConfigSystemRegistry(TENANT_ID)).thenReturn((UserRegistry) mockRegistry); diff --git a/components/identity-core/org.wso2.carbon.identity.core/src/test/resources/testng.xml b/components/identity-core/org.wso2.carbon.identity.core/src/test/resources/testng.xml index 043fa43d7ae7..d5830c1c2bf9 100644 --- a/components/identity-core/org.wso2.carbon.identity.core/src/test/resources/testng.xml +++ b/components/identity-core/org.wso2.carbon.identity.core/src/test/resources/testng.xml @@ -25,6 +25,7 @@ +