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/SAMLSSOServiceProviderDAOImpl.java index 9144f15549e8..34d7297e09ba 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/SAMLSSOServiceProviderDAOImpl.java @@ -231,8 +231,30 @@ public boolean isServiceProviderExists(String issuer) throws IdentityException { public SAMLSSOServiceProviderDO uploadServiceProvider(SAMLSSOServiceProviderDO serviceProviderDO) throws IdentityException { - addServiceProvider(serviceProviderDO); - return serviceProviderDO; + validateServiceProvider(serviceProviderDO); + if (serviceProviderDO.getDefaultAssertionConsumerUrl() == null) { + throw new IdentityException("No default assertion consumer URL provided for service provider :" + + serviceProviderDO.getIssuer()); + } + + try { + if (processIsServiceProviderExists(serviceProviderDO.getIssuer())) { + debugLog(serviceProviderInfo(serviceProviderDO) + " already exists."); + throw new IdentityException(serviceProviderInfo(serviceProviderDO) + " already exists."); + } + NamedJdbcTemplate namedJdbcTemplate = JdbcUtils.getNewNamedJdbcTemplate(); + namedJdbcTemplate.withTransaction(template -> { + processAddServiceProvider(serviceProviderDO); + processAddSPProperties(serviceProviderDO); + return null; + }); + debugLog(serviceProviderInfo(serviceProviderDO) + " is added successfully."); + return serviceProviderDO; + } catch (TransactionException | DataAccessException e) { + String msg = "Error while adding " + serviceProviderInfo(serviceProviderDO); + log.error(msg, e); + throw new IdentityException(msg, e); + } } private void debugLog(String message) {