Search in sources :

Example 1 with SAMLSSOServiceProviderDO

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);
}
Also used : SAMLSSOServiceProviderDO(org.wso2.carbon.identity.core.model.SAMLSSOServiceProviderDO) Resource(org.wso2.carbon.registry.core.Resource) Test(org.testng.annotations.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 2 with SAMLSSOServiceProviderDO

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");
}
Also used : SAMLSSOServiceProviderDO(org.wso2.carbon.identity.core.model.SAMLSSOServiceProviderDO) ResourceImpl(org.wso2.carbon.registry.core.ResourceImpl) Resource(org.wso2.carbon.registry.core.Resource) Properties(java.util.Properties) Test(org.testng.annotations.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 3 with SAMLSSOServiceProviderDO

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;
}
Also used : SAMLSSOServiceProviderDO(org.wso2.carbon.identity.core.model.SAMLSSOServiceProviderDO) Tenant(org.wso2.carbon.user.api.Tenant) SQLException(java.sql.SQLException) UserStoreException(org.wso2.carbon.user.api.UserStoreException) UserRegistry(org.wso2.carbon.registry.core.session.UserRegistry) RegistryException(org.wso2.carbon.registry.core.exceptions.RegistryException) CertificateRetrievingException(org.wso2.carbon.identity.core.CertificateRetrievingException)

Example 4 with SAMLSSOServiceProviderDO

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));
        }
    }
}
Also used : Resource(org.wso2.carbon.registry.core.Resource) Collection(org.wso2.carbon.registry.core.Collection)

Example 5 with SAMLSSOServiceProviderDO

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()]);
}
Also used : SAMLSSOServiceProviderDO(org.wso2.carbon.identity.core.model.SAMLSSOServiceProviderDO) ArrayList(java.util.ArrayList) Resource(org.wso2.carbon.registry.core.Resource) Collection(org.wso2.carbon.registry.core.Collection) RegistryException(org.wso2.carbon.registry.core.exceptions.RegistryException)

Aggregations

SAMLSSOServiceProviderDO (org.wso2.carbon.identity.core.model.SAMLSSOServiceProviderDO)14 Resource (org.wso2.carbon.registry.core.Resource)12 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)8 Test (org.testng.annotations.Test)8 Properties (java.util.Properties)6 ResourceImpl (org.wso2.carbon.registry.core.ResourceImpl)6 RegistryException (org.wso2.carbon.registry.core.exceptions.RegistryException)4 IdentityException (org.wso2.carbon.identity.base.IdentityException)3 Collection (org.wso2.carbon.registry.core.Collection)2 Registry (org.wso2.carbon.registry.core.Registry)2 UserStoreException (org.wso2.carbon.user.api.UserStoreException)2 RealmService (org.wso2.carbon.user.core.service.RealmService)2 SQLException (java.sql.SQLException)1 ArrayList (java.util.ArrayList)1 Audience (org.opensaml.saml.saml2.core.Audience)1 AudienceRestriction (org.opensaml.saml.saml2.core.AudienceRestriction)1 Conditions (org.opensaml.saml.saml2.core.Conditions)1 PrivilegedCarbonContext (org.wso2.carbon.context.PrivilegedCarbonContext)1 CertificateRetriever (org.wso2.carbon.identity.core.CertificateRetriever)1 CertificateRetrievingException (org.wso2.carbon.identity.core.CertificateRetrievingException)1