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 5c7a6b7bd740..8eec70e5d47b 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 @@ -23,8 +23,8 @@ import org.apache.commons.logging.LogFactory; import org.wso2.carbon.identity.base.IdentityException; import org.wso2.carbon.identity.core.dao.SAMLSSOServiceProviderDAO; -import org.wso2.carbon.identity.core.dao.SAMLSSOServiceProviderDAOImpl; -import org.wso2.carbon.identity.core.dao.SAMLSSOServiceProviderRegistryDAOImpl; +import org.wso2.carbon.identity.core.dao.JDBCSAMLSSOServiceProviderDAOImpl; +import org.wso2.carbon.identity.core.dao.RegistrySAMLSSOServiceProviderDAOImpl; import org.wso2.carbon.identity.core.model.SAMLSSOServiceProviderDO; import org.wso2.carbon.identity.core.util.IdentityTenantUtil; import org.wso2.carbon.identity.core.util.IdentityUtil; @@ -52,7 +52,7 @@ public class SAMLSSOServiceProviderManager { */ private SAMLSSOServiceProviderDAO buildSAMLSSOProvider(int tenantId) throws IdentityException { - SAMLSSOServiceProviderDAO samlSSOServiceProviderDAO = new SAMLSSOServiceProviderDAOImpl(tenantId); + SAMLSSOServiceProviderDAO samlSSOServiceProviderDAO = new JDBCSAMLSSOServiceProviderDAOImpl(tenantId); if (StringUtils.isNotBlank(SAML_STORAGE_TYPE)) { switch (SAML_STORAGE_TYPE) { case HYBRID: @@ -61,7 +61,7 @@ private SAMLSSOServiceProviderDAO buildSAMLSSOProvider(int tenantId) throws Iden case REGISTRY: try { Registry registry = IdentityTenantUtil.getRegistryService().getConfigSystemRegistry(tenantId); - samlSSOServiceProviderDAO = new SAMLSSOServiceProviderRegistryDAOImpl(registry); + samlSSOServiceProviderDAO = new RegistrySAMLSSOServiceProviderDAOImpl(registry); } catch (RegistryException e) { LOG.error("Error while retrieving registry", e); throw new IdentityException("Error while retrieving registry", e); @@ -119,8 +119,8 @@ public boolean updateServiceProvider(SAMLSSOServiceProviderDO serviceProviderDO, public SAMLSSOServiceProviderDO[] getServiceProviders(int tenantId) throws IdentityException { - SAMLSSOServiceProviderDAO serviceProviderDOA = buildSAMLSSOProvider(tenantId); - return serviceProviderDOA.getServiceProviders(); + SAMLSSOServiceProviderDAO serviceProviderDAO = buildSAMLSSOProvider(tenantId); + return serviceProviderDAO.getServiceProviders(); } /** diff --git a/components/identity-core/org.wso2.carbon.identity.core/src/main/java/org/wso2/carbon/identity/core/dao/SAMLSSOServiceProviderDAOImpl.java b/components/identity-core/org.wso2.carbon.identity.core/src/main/java/org/wso2/carbon/identity/core/dao/JDBCSAMLSSOServiceProviderDAOImpl.java similarity index 97% rename from components/identity-core/org.wso2.carbon.identity.core/src/main/java/org/wso2/carbon/identity/core/dao/SAMLSSOServiceProviderDAOImpl.java rename to components/identity-core/org.wso2.carbon.identity.core/src/main/java/org/wso2/carbon/identity/core/dao/JDBCSAMLSSOServiceProviderDAOImpl.java index 34d7297e09ba..33558cd04f46 100644 --- a/components/identity-core/org.wso2.carbon.identity.core/src/main/java/org/wso2/carbon/identity/core/dao/SAMLSSOServiceProviderDAOImpl.java +++ b/components/identity-core/org.wso2.carbon.identity.core/src/main/java/org/wso2/carbon/identity/core/dao/JDBCSAMLSSOServiceProviderDAOImpl.java @@ -31,7 +31,7 @@ import org.wso2.carbon.identity.core.DatabaseCertificateRetriever; import org.wso2.carbon.identity.core.IdentityRegistryResources; import org.wso2.carbon.identity.core.KeyStoreCertificateRetriever; -import org.wso2.carbon.identity.core.model.SPProperty; +import org.wso2.carbon.identity.core.model.ServiceProviderProperty; import org.wso2.carbon.identity.core.model.SAMLSSOServiceProviderDO; import org.wso2.carbon.identity.core.util.IdentityTenantUtil; import org.wso2.carbon.identity.core.util.JdbcUtils; @@ -77,9 +77,9 @@ import static org.wso2.carbon.identity.core.dao.SAMLSSOServiceProviderConstants.SAML2TableColumns.PROPERTY_VALUE; import static org.wso2.carbon.identity.core.dao.SAMLSSOServiceProviderConstants.SAML2TableColumns.SP_ID; -public class SAMLSSOServiceProviderDAOImpl implements SAMLSSOServiceProviderDAO { +public class JDBCSAMLSSOServiceProviderDAOImpl implements SAMLSSOServiceProviderDAO { - private static final Log log = LogFactory.getLog(SAMLSSOServiceProviderDAOImpl.class); + private static final Log log = LogFactory.getLog(JDBCSAMLSSOServiceProviderDAOImpl.class); private final int tenantId; private static final String CERTIFICATE_PROPERTY_NAME = "CERTIFICATE"; private static final String QUERY_TO_GET_APPLICATION_CERTIFICATE_ID = "SELECT " + @@ -89,7 +89,7 @@ public class SAMLSSOServiceProviderDAOImpl implements SAMLSSOServiceProviderDAO "META.`VALUE` FROM SP_INBOUND_AUTH INBOUND, SP_APP SP, SP_METADATA META WHERE SP.ID = INBOUND.APP_ID AND " + "SP.ID = META.SP_ID AND META.NAME = ? AND INBOUND.INBOUND_AUTH_KEY = ? AND META.TENANT_ID = ?"; - public SAMLSSOServiceProviderDAOImpl(int tenantId) { + public JDBCSAMLSSOServiceProviderDAOImpl(int tenantId) { this.tenantId = tenantId; } @@ -366,9 +366,9 @@ private void addProperties(int serviceProviderId, SAMLSSOServiceProviderDO servi throws DataAccessException { NamedJdbcTemplate namedJdbcTemplate = JdbcUtils.getNewNamedJdbcTemplate(); - List properties = + List properties = namedJdbcTemplate.executeQuery(SAMLSSOServiceProviderConstants.SQLQueries.GET_SAML_SSO_ATTR_BY_ID, - (resultSet, rowNumber) -> new SPProperty(resultSet.getString(PROPERTY_NAME), + (resultSet, rowNumber) -> new ServiceProviderProperty(resultSet.getString(PROPERTY_NAME), resultSet.getString(PROPERTY_VALUE)), namedPreparedStatement -> namedPreparedStatement.setInt(SP_ID, serviceProviderId)); serviceProviderDO.addMultiValuedProperties(properties); @@ -434,14 +434,14 @@ private void processAddServiceProvider(SAMLSSOServiceProviderDO serviceProviderD private void processAddSPProperties(SAMLSSOServiceProviderDO serviceProviderDO) throws DataAccessException { - List properties = serviceProviderDO.getMultiValuedProperties(); + List properties = serviceProviderDO.getMultiValuedProperties(); int serviceProviderId = processGetServiceProviderId(serviceProviderDO.getIssuer()); NamedJdbcTemplate namedJdbcTemplate = JdbcUtils.getNewNamedJdbcTemplate(); namedJdbcTemplate.executeBatchInsert(SAMLSSOServiceProviderConstants.SQLQueries.ADD_SAML_SSO_ATTR, (namedPreparedStatement -> { - for (SPProperty property : properties) { + for (ServiceProviderProperty property : properties) { namedPreparedStatement.setInt(SP_ID, serviceProviderId); namedPreparedStatement.setString(PROPERTY_NAME, property.getKey()); namedPreparedStatement.setString(PROPERTY_VALUE, property.getValue()); @@ -464,7 +464,7 @@ private void processUpdateServiceProvider(SAMLSSOServiceProviderDO serviceProvid private void processUpdateSPProperties(SAMLSSOServiceProviderDO serviceProviderDO, int serviceProviderId) throws DataAccessException { - List properties = serviceProviderDO.getMultiValuedProperties(); + List properties = serviceProviderDO.getMultiValuedProperties(); NamedJdbcTemplate namedJdbcTemplate = JdbcUtils.getNewNamedJdbcTemplate(); namedJdbcTemplate.executeUpdate(SAMLSSOServiceProviderConstants.SQLQueries.DELETE_SAML_SSO_ATTR_BY_ID, @@ -472,7 +472,7 @@ private void processUpdateSPProperties(SAMLSSOServiceProviderDO serviceProviderD namedJdbcTemplate.executeBatchInsert(SAMLSSOServiceProviderConstants.SQLQueries.ADD_SAML_SSO_ATTR, (namedPreparedStatement -> { - for (SPProperty property : properties) { + for (ServiceProviderProperty property : properties) { namedPreparedStatement.setInt(SP_ID, serviceProviderId); namedPreparedStatement.setString(PROPERTY_NAME, property.getKey()); namedPreparedStatement.setString(PROPERTY_VALUE, property.getValue()); 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 08ac0b769c89..074cc23c48d0 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 @@ -52,7 +52,7 @@ import static org.wso2.carbon.identity.core.util.JdbcUtils.isH2DB; -public class SAMLSSOServiceProviderRegistryDAOImpl extends AbstractDAO +public class RegistrySAMLSSOServiceProviderDAOImpl extends AbstractDAO implements SAMLSSOServiceProviderDAO { private static final String CERTIFICATE_PROPERTY_NAME = "CERTIFICATE"; private static final String QUERY_TO_GET_APPLICATION_CERTIFICATE_ID = "SELECT " + @@ -65,7 +65,7 @@ public class SAMLSSOServiceProviderRegistryDAOImpl extends AbstractDAO getMultiValuedProperties() { + public List getMultiValuedProperties() { - List multiValuedProperties = new ArrayList<>(); + List multiValuedProperties = new ArrayList<>(); // Multi-valued attributes. getAssertionConsumerUrlList().forEach(assertionConUrl -> - putIfNotNull(multiValuedProperties, ASSERTION_CONSUMER_URLS, + putIfNotNull(multiValuedProperties, MultiValuedPropertyKey.ASSERTION_CONSUMER_URLS.toString(), assertionConUrl)); getRequestedRecipientsList().forEach(requestedRecipient -> - putIfNotNull(multiValuedProperties, RECIPIENTS, + putIfNotNull(multiValuedProperties, MultiValuedPropertyKey.RECIPIENTS.toString(), requestedRecipient)); getRequestedAudiencesList().forEach(requestedAudience -> - putIfNotNull(multiValuedProperties, AUDIENCES, + putIfNotNull(multiValuedProperties, MultiValuedPropertyKey.AUDIENCES.toString(), requestedAudience)); getIdpInitSLOReturnToURLList().forEach(idpInitSLOReturnToURL -> - putIfNotNull(multiValuedProperties, SLO_RETURN_TO_URLS, + putIfNotNull(multiValuedProperties, MultiValuedPropertyKey.SLO_RETURN_TO_URLS.toString(), idpInitSLOReturnToURL)); return multiValuedProperties; @@ -698,9 +695,9 @@ public List getMultiValuedProperties() { /** * Add a list of multivalued properties. * - * @param multiValuedProperties List of SPProperty. + * @param multiValuedProperties List of ServiceProviderProperty. */ - public void addMultiValuedProperties(List multiValuedProperties) { + public void addMultiValuedProperties(List multiValuedProperties) { if (multiValuedProperties == null) { return; @@ -712,9 +709,9 @@ public void addMultiValuedProperties(List multiValuedProperties) { /** * Add a multivalued property. * - * @param multiValuedProperty SPProperty. + * @param multiValuedProperty ServiceProviderProperty. */ - private void addMultiValuedProperty(SPProperty multiValuedProperty) { + private void addMultiValuedProperty(ServiceProviderProperty multiValuedProperty) { if (multiValuedProperty == null) { return; @@ -722,28 +719,28 @@ private void addMultiValuedProperty(SPProperty multiValuedProperty) { String key = multiValuedProperty.getKey(); String value = multiValuedProperty.getValue(); - if (ASSERTION_CONSUMER_URLS.equals(key)) { + if (MultiValuedPropertyKey.ASSERTION_CONSUMER_URLS.toString().equals(key)) { List attributeList = getAssertionConsumerUrlList(); if (attributeList.isEmpty()) { attributeList = new ArrayList<>(); } attributeList.add(value); setAssertionConsumerUrls(attributeList); - } else if (RECIPIENTS.equals(key)) { + } else if (MultiValuedPropertyKey.RECIPIENTS.toString().equals(key)) { List attributeList = getRequestedRecipientsList(); if (attributeList.isEmpty()) { attributeList = new ArrayList<>(); } attributeList.add(value); setRequestedRecipients(attributeList); - } else if (AUDIENCES.equals(key)) { + } else if (MultiValuedPropertyKey.AUDIENCES.toString().equals(key)) { List attributeList = getRequestedAudiencesList(); if (attributeList.isEmpty()) { attributeList = new ArrayList<>(); } attributeList.add(value); setRequestedAudiences(attributeList); - } else if (SLO_RETURN_TO_URLS.equals(key)) { + } else if (MultiValuedPropertyKey.SLO_RETURN_TO_URLS.toString().equals(key)) { List attributeList = getIdpInitSLOReturnToURLList(); if (attributeList.isEmpty()) { attributeList = new ArrayList<>(); @@ -756,14 +753,14 @@ private void addMultiValuedProperty(SPProperty multiValuedProperty) { /** * Put a key value pair to a list if the value is not null. * - * @param list List of SPProperty. + * @param list List of ServiceProviderProperty. * @param key Key. * @param value Value. */ - private void putIfNotNull(List list, String key, String value) { + private void putIfNotNull(List list, String key, String value) { if (StringUtils.isNotBlank(value)) { - list.add(new SPProperty(key, value)); + list.add(new ServiceProviderProperty(key, value)); } } diff --git a/components/identity-core/org.wso2.carbon.identity.core/src/main/java/org/wso2/carbon/identity/core/model/SPProperty.java b/components/identity-core/org.wso2.carbon.identity.core/src/main/java/org/wso2/carbon/identity/core/model/ServiceProviderProperty.java similarity index 92% rename from components/identity-core/org.wso2.carbon.identity.core/src/main/java/org/wso2/carbon/identity/core/model/SPProperty.java rename to components/identity-core/org.wso2.carbon.identity.core/src/main/java/org/wso2/carbon/identity/core/model/ServiceProviderProperty.java index 48cba8e76455..de606ba57143 100644 --- a/components/identity-core/org.wso2.carbon.identity.core/src/main/java/org/wso2/carbon/identity/core/model/SPProperty.java +++ b/components/identity-core/org.wso2.carbon.identity.core/src/main/java/org/wso2/carbon/identity/core/model/ServiceProviderProperty.java @@ -21,12 +21,12 @@ /** * This class represents a tuple of key and value. */ -public class SPProperty { +public class ServiceProviderProperty { private String key; private String value; - public SPProperty(String key, String value) { + public ServiceProviderProperty(String key, String value) { this.key = key; this.value = value; } diff --git a/components/identity-core/org.wso2.carbon.identity.core/src/main/java/org/wso2/carbon/identity/core/persistence/IdentityPersistenceManager.java b/components/identity-core/org.wso2.carbon.identity.core/src/main/java/org/wso2/carbon/identity/core/persistence/IdentityPersistenceManager.java index 93234f57d6b6..e53ef8a945b5 100644 --- a/components/identity-core/org.wso2.carbon.identity.core/src/main/java/org/wso2/carbon/identity/core/persistence/IdentityPersistenceManager.java +++ b/components/identity-core/org.wso2.carbon.identity.core/src/main/java/org/wso2/carbon/identity/core/persistence/IdentityPersistenceManager.java @@ -22,7 +22,7 @@ import org.wso2.carbon.identity.core.dao.OpenIDUserDAO; import org.wso2.carbon.identity.core.dao.ParameterDAO; import org.wso2.carbon.identity.core.dao.SAMLSSOServiceProviderDAO; -import org.wso2.carbon.identity.core.dao.SAMLSSOServiceProviderRegistryDAOImpl; +import org.wso2.carbon.identity.core.dao.RegistrySAMLSSOServiceProviderDAOImpl; import org.wso2.carbon.identity.core.dao.XMPPSettingsDAO; import org.wso2.carbon.identity.core.model.OpenIDAdminDO; import org.wso2.carbon.identity.core.model.OpenIDUserDO; @@ -236,7 +236,7 @@ public void removeOpenIDSignUp(Registry registry, UserRealm realm, String openID */ public boolean addServiceProvider(Registry registry, SAMLSSOServiceProviderDO serviceProviderDO) throws IdentityException { - SAMLSSOServiceProviderDAO serviceProviderDAO = new SAMLSSOServiceProviderRegistryDAOImpl(registry); + SAMLSSOServiceProviderDAO serviceProviderDAO = new RegistrySAMLSSOServiceProviderDAOImpl(registry); return serviceProviderDAO.addServiceProvider(serviceProviderDO); } /** @@ -247,7 +247,7 @@ public boolean addServiceProvider(Registry registry, SAMLSSOServiceProviderDO se * @throws IdentityException */ public SAMLSSOServiceProviderDO uploadServiceProvider(Registry registry, SAMLSSOServiceProviderDO samlssoServiceProviderDO) throws IdentityException { - SAMLSSOServiceProviderDAO serviceProviderDAO = new SAMLSSOServiceProviderRegistryDAOImpl(registry); + SAMLSSOServiceProviderDAO serviceProviderDAO = new RegistrySAMLSSOServiceProviderDAOImpl(registry); return serviceProviderDAO.uploadServiceProvider(samlssoServiceProviderDO); } @@ -259,23 +259,23 @@ public SAMLSSOServiceProviderDO uploadServiceProvider(Registry registry, SAMLSSO */ public SAMLSSOServiceProviderDO[] getServiceProviders(Registry registry) throws IdentityException { - SAMLSSOServiceProviderDAO serviceProviderDOA = new SAMLSSOServiceProviderRegistryDAOImpl(registry); + SAMLSSOServiceProviderDAO serviceProviderDOA = new RegistrySAMLSSOServiceProviderDAOImpl(registry); return serviceProviderDOA.getServiceProviders(); } public boolean removeServiceProvider(Registry registry, String issuer) throws IdentityException { - SAMLSSOServiceProviderDAO serviceProviderDAO = new SAMLSSOServiceProviderRegistryDAOImpl(registry); + SAMLSSOServiceProviderDAO serviceProviderDAO = new RegistrySAMLSSOServiceProviderDAOImpl(registry); return serviceProviderDAO.removeServiceProvider(issuer); } public SAMLSSOServiceProviderDO getServiceProvider(Registry registry, String issuer) throws IdentityException { - SAMLSSOServiceProviderDAO serviceProviderDAO = new SAMLSSOServiceProviderRegistryDAOImpl(registry); + SAMLSSOServiceProviderDAO serviceProviderDAO = new RegistrySAMLSSOServiceProviderDAOImpl(registry); return serviceProviderDAO.getServiceProvider(issuer); } public boolean isServiceProviderExists(Registry registry, String issuer) throws IdentityException { - SAMLSSOServiceProviderDAO serviceProviderDAO = new SAMLSSOServiceProviderRegistryDAOImpl(registry); + SAMLSSOServiceProviderDAO serviceProviderDAO = new RegistrySAMLSSOServiceProviderDAOImpl(registry); return serviceProviderDAO.isServiceProviderExists(issuer); } 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 e50fe8ad1da0..9497eb8ac51e 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 @@ -69,7 +69,7 @@ */ public class SAMLSSOServiceProviderDAOTest { - private SAMLSSOServiceProviderRegistryDAOImpl objUnderTest; + private RegistrySAMLSSOServiceProviderDAOImpl objUnderTest; private boolean transactionStarted = false; private Registry mockRegistry; @@ -103,7 +103,7 @@ public Object answer(InvocationOnMock invocationOnMock) throws Throwable { } }).when(mockRegistry).beginTransaction(); - objUnderTest = new SAMLSSOServiceProviderRegistryDAOImpl(mockRegistry); + objUnderTest = new RegistrySAMLSSOServiceProviderDAOImpl(mockRegistry); when(mockRegistry.newResource()).thenReturn(new ResourceImpl()); }