use of org.wso2.carbon.identity.core.model.SAMLSSOServiceProviderDO in project carbon-identity-framework by wso2.
the class SAMLSSOServiceProviderDAOTest method testAddServiceProviderRegistryError.
@Test(expectedExceptions = { IdentityException.class })
public void testAddServiceProviderRegistryError() throws Exception {
SAMLSSOServiceProviderDO serviceProviderDO = new SAMLSSOServiceProviderDO();
String existingPath = getPath("erringIssuer");
serviceProviderDO.setIssuer("erringIssuer");
doThrow(RegistryException.class).when(mockRegistry).put(eq(existingPath), any(Resource.class));
objUnderTest.addServiceProvider(serviceProviderDO);
}
use of org.wso2.carbon.identity.core.model.SAMLSSOServiceProviderDO in project carbon-identity-framework by wso2.
the class SAMLSSOServiceProviderDAOTest method testAddServiceProvider.
@Test(dataProvider = "ResourceToObjectData")
public void testAddServiceProvider(Object paramMapObj) throws Exception {
Properties properties = new Properties();
properties.putAll((Map<?, ?>) paramMapObj);
Resource dummyResource = new ResourceImpl();
dummyResource.setProperties(properties);
SAMLSSOServiceProviderDO serviceProviderDO = objUnderTest.resourceToObject(dummyResource);
ArgumentCaptor<String> captor = ArgumentCaptor.forClass(String.class);
String expectedPath = getPath(dummyResource.getProperty(IdentityRegistryResources.PROP_SAML_SSO_ISSUER));
if (StringUtils.isNotBlank(serviceProviderDO.getIssuerQualifier())) {
expectedPath = getPath(dummyResource.getProperty(IdentityRegistryResources.PROP_SAML_SSO_ISSUER) + IdentityRegistryResources.QUALIFIER_ID + dummyResource.getProperty(IdentityRegistryResources.PROP_SAML_SSO_ISSUER_QUALIFIER));
}
objUnderTest.addServiceProvider(serviceProviderDO);
verify(mockRegistry).put(captor.capture(), any(Resource.class));
assertEquals(captor.getValue(), expectedPath, "Resource is not added at correct path");
}
use of org.wso2.carbon.identity.core.model.SAMLSSOServiceProviderDO in project carbon-identity-framework by wso2.
the class SAMLSSOServiceProviderDAO method getServiceProvider.
/**
* Get the service provider.
*
* @param issuer
* @return
* @throws IdentityException
*/
public SAMLSSOServiceProviderDO getServiceProvider(String issuer) throws IdentityException {
String path = IdentityRegistryResources.SAML_SSO_SERVICE_PROVIDERS + encodePath(issuer);
SAMLSSOServiceProviderDO serviceProviderDO = null;
UserRegistry userRegistry = null;
String tenantDomain = null;
try {
userRegistry = (UserRegistry) registry;
tenantDomain = IdentityTenantUtil.getRealmService().getTenantManager().getDomain(userRegistry.getTenantId());
if (registry.resourceExists(path)) {
serviceProviderDO = resourceToObject(registry.get(path));
// Load the certificate stored in the database, if signature validation is enabled..
if (serviceProviderDO.isDoValidateSignatureInRequests() || serviceProviderDO.isDoValidateSignatureInArtifactResolve() || serviceProviderDO.isDoEnableEncryptedAssertion()) {
Tenant tenant = new Tenant();
tenant.setDomain(tenantDomain);
tenant.setId(userRegistry.getTenantId());
serviceProviderDO.setX509Certificate(getApplicationCertificate(serviceProviderDO, tenant));
}
serviceProviderDO.setTenantDomain(tenantDomain);
}
} catch (RegistryException e) {
throw IdentityException.error("Error occurred while checking if resource path \'" + path + "\' exists in " + "registry for tenant domain : " + tenantDomain, e);
} catch (UserStoreException e) {
throw IdentityException.error("Error occurred while getting tenant domain from tenant ID : " + userRegistry.getTenantId(), e);
} catch (SQLException e) {
throw IdentityException.error(String.format("An error occurred while getting the " + "application certificate id for validating the requests from the issuer '%s'", issuer), e);
} catch (CertificateRetrievingException e) {
throw IdentityException.error(String.format("An error occurred while getting the " + "application certificate for validating the requests from the issuer '%s'", issuer), e);
}
return serviceProviderDO;
}
use of org.wso2.carbon.identity.core.model.SAMLSSOServiceProviderDO in project carbon-identity-framework by wso2.
the class SAMLSSOServiceProviderDAO method getChildResources.
/**
* This helps to find resources in a recursive manner.
*
* @param parentResource parent resource Name.
* @param serviceProviderList child resource list.
* @throws RegistryException
*/
private void getChildResources(String parentResource, List<SAMLSSOServiceProviderDO> serviceProviderList) throws RegistryException {
if (registry.resourceExists(parentResource)) {
Resource resource = registry.get(parentResource);
if (resource instanceof Collection) {
Collection collection = (Collection) resource;
String[] resources = collection.getChildren();
for (String res : resources) {
getChildResources(res, serviceProviderList);
}
} else {
serviceProviderList.add(resourceToObject(resource));
}
}
}
use of org.wso2.carbon.identity.core.model.SAMLSSOServiceProviderDO in project carbon-identity-framework by wso2.
the class SAMLSSOServiceProviderDAO method getServiceProviders.
public SAMLSSOServiceProviderDO[] getServiceProviders() throws IdentityException {
List<SAMLSSOServiceProviderDO> serviceProvidersList = new ArrayList<>();
try {
if (registry.resourceExists(IdentityRegistryResources.SAML_SSO_SERVICE_PROVIDERS)) {
Resource samlSSOServiceProvidersResource = registry.get(IdentityRegistryResources.SAML_SSO_SERVICE_PROVIDERS);
if (samlSSOServiceProvidersResource instanceof Collection) {
Collection samlSSOServiceProvidersCollection = (Collection) samlSSOServiceProvidersResource;
String[] resources = samlSSOServiceProvidersCollection.getChildren();
for (String resource : resources) {
getChildResources(resource, serviceProvidersList);
}
}
}
} catch (RegistryException e) {
log.error("Error reading Service Providers from Registry", e);
throw IdentityException.error("Error reading Service Providers from Registry", e);
}
return serviceProvidersList.toArray(new SAMLSSOServiceProviderDO[serviceProvidersList.size()]);
}
Aggregations