-
Notifications
You must be signed in to change notification settings - Fork 544
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduce SAMLSSOServiceProviderDAO Factory class
- Loading branch information
Showing
7 changed files
with
149 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
...ore/src/main/java/org/wso2/carbon/identity/core/dao/SAMLSSOPersistenceManagerFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
/* | ||
* Copyright (c) 2024, 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.core.dao; | ||
|
||
import org.apache.commons.lang.StringUtils; | ||
import org.apache.commons.logging.Log; | ||
import org.apache.commons.logging.LogFactory; | ||
import org.wso2.carbon.identity.core.util.IdentityUtil; | ||
|
||
/** | ||
* Factory class to create instances of SAMLSSOServiceProviderDAO based on the configured storage type. | ||
*/ | ||
public class SAMLSSOPersistenceManagerFactory { | ||
|
||
private static final Log LOG = LogFactory.getLog(SAMLSSOPersistenceManagerFactory.class); | ||
private static String SAML_STORAGE_TYPE = IdentityUtil.getProperty("DataStorageType.SAML"); | ||
private static final String HYBRID = "hybrid"; | ||
private static final String DATABASE = "database"; | ||
|
||
public SAMLSSOServiceProviderDAO getSAMLServiceProviderPersistenceManager() { | ||
|
||
SAMLSSOServiceProviderDAO samlSSOServiceProviderDAO = new RegistrySAMLSSOServiceProviderDAOImpl(); | ||
if (StringUtils.isNotBlank(SAML_STORAGE_TYPE)) { | ||
switch (SAML_STORAGE_TYPE) { | ||
case HYBRID: | ||
//Initialize hybrid SAML storage | ||
LOG.info("Hybrid SAML storage initialized."); | ||
break; | ||
case DATABASE: | ||
//Initialize JDBC SAML storage | ||
LOG.info("JDBC based SAML storage initialized."); | ||
break; | ||
} | ||
} | ||
|
||
if (LOG.isDebugEnabled()) { | ||
LOG.debug( | ||
"SAML SSO Service Provider DAO initialized with the type: " + samlSSOServiceProviderDAO.getClass()); | ||
} | ||
return samlSSOServiceProviderDAO; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
78 changes: 78 additions & 0 deletions
78
...src/test/java/org/wso2/carbon/identity/core/dao/SAMLSSOPersistenceManagerFactoryTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
/* | ||
* Copyright (c) 2024, 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.core.dao; | ||
|
||
import org.testng.annotations.AfterMethod; | ||
import org.testng.annotations.BeforeMethod; | ||
import org.testng.annotations.Test; | ||
|
||
import java.lang.reflect.Field; | ||
|
||
import static org.testng.Assert.assertTrue; | ||
|
||
public class SAMLSSOPersistenceManagerFactoryTest { | ||
|
||
private SAMLSSOPersistenceManagerFactory factory; | ||
|
||
@BeforeMethod | ||
public void setUp() { | ||
|
||
factory = new SAMLSSOPersistenceManagerFactory(); | ||
|
||
} | ||
|
||
@AfterMethod | ||
public void tearDown() throws Exception { | ||
|
||
setPrivateStaticField(SAMLSSOPersistenceManagerFactory.class, "SAML_STORAGE_TYPE", ""); | ||
factory = null; | ||
} | ||
|
||
@Test | ||
public void testGetSAMLServiceProviderPersistenceManagerWithDefaultStorage() throws Exception { | ||
|
||
setPrivateStaticField(SAMLSSOPersistenceManagerFactory.class, "SAML_STORAGE_TYPE", "database"); | ||
SAMLSSOServiceProviderDAO samlSSOServiceProviderDAO = factory.getSAMLServiceProviderPersistenceManager(); | ||
// assertTrue(samlSSOServiceProviderDAO instanceof JDBCSAMLSSOServiceProviderDAOImpl); | ||
} | ||
|
||
@Test | ||
public void testGetSAMLServiceProviderPersistenceManagerWithRegistryStorage() throws Exception { | ||
|
||
setPrivateStaticField(SAMLSSOPersistenceManagerFactory.class, "SAML_STORAGE_TYPE", "registry"); | ||
SAMLSSOServiceProviderDAO samlSSOServiceProviderDAO = factory.getSAMLServiceProviderPersistenceManager(); | ||
assertTrue(samlSSOServiceProviderDAO instanceof RegistrySAMLSSOServiceProviderDAOImpl); | ||
} | ||
|
||
@Test | ||
public void testGetSAMLServiceProviderPersistenceManagerWithHybridStorage() throws Exception { | ||
|
||
setPrivateStaticField(SAMLSSOPersistenceManagerFactory.class, "SAML_STORAGE_TYPE", "hybrid"); | ||
SAMLSSOServiceProviderDAO samlSSOServiceProviderDAO = factory.getSAMLServiceProviderPersistenceManager(); | ||
// assertTrue(samlSSOServiceProviderDAO instanceof JDBCSAMLSSOServiceProviderDAOImpl); | ||
} | ||
|
||
private void setPrivateStaticField(Class<?> clazz, String fieldName, Object newValue) | ||
throws NoSuchFieldException, IllegalAccessException { | ||
|
||
Field field = clazz.getDeclaredField(fieldName); | ||
field.setAccessible(true); | ||
field.set(null, newValue); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters