Search in sources :

Example 26 with ClaimConfig

use of org.wso2.carbon.identity.application.common.model.xsd.ClaimConfig in project product-is by wso2.

the class TestPassiveSTS method testAddClaimConfiguration.

@Test(alwaysRun = true, description = "4.1.5.3", dependsOnMethods = { "testUpdateSP" })
public void testAddClaimConfiguration() throws Exception {
    serviceProvider.getClaimConfig().setClaimMappings(getClaimMappings());
    appMgtclient.updateApplicationData(serviceProvider);
    ServiceProvider updatedServiceProvider = appMgtclient.getApplication(SERVICE_PROVIDER_NAME);
    ClaimConfig updatedClaimConfig = updatedServiceProvider.getClaimConfig();
    Assert.assertNotNull(updatedClaimConfig.getClaimMappings(), "Claim mapping is null. Claim mapping creation failed.");
    for (ClaimMapping claimMapping : getClaimMappings()) {
        boolean success = false;
        for (ClaimMapping updatedClaimMapping : updatedClaimConfig.getClaimMappings()) {
            if (claimMapping.getLocalClaim().getClaimUri().equals(updatedClaimMapping.getLocalClaim().getClaimUri())) {
                success = true;
                break;
            }
        }
        Assert.assertTrue(success, "Failed to set claim uri: " + claimMapping.getLocalClaim().getClaimUri());
    }
}
Also used : ClaimMapping(org.wso2.carbon.identity.application.common.model.xsd.ClaimMapping) ClaimConfig(org.wso2.carbon.identity.application.common.model.xsd.ClaimConfig) ServiceProvider(org.wso2.carbon.identity.application.common.model.xsd.ServiceProvider) Test(org.testng.annotations.Test)

Example 27 with ClaimConfig

use of org.wso2.carbon.identity.application.common.model.xsd.ClaimConfig in project identity-api-server by wso2.

the class ServerIdpManagementService method updateClaims.

private void updateClaims(IdentityProvider idp, Claims claims) {
    if (claims != null) {
        ClaimConfig claimConfig = new ClaimConfig();
        List<ClaimMapping> claimMappings = new ArrayList<>();
        List<org.wso2.carbon.identity.application.common.model.Claim> idpClaims = new ArrayList<>();
        if (CollectionUtils.isNotEmpty(claims.getMappings())) {
            claimConfig.setLocalClaimDialect(false);
            for (org.wso2.carbon.identity.api.server.idp.v1.model.ClaimMapping mapping : claims.getMappings()) {
                String idpClaimUri = mapping.getIdpClaim();
                String localClaimUri = mapping.getLocalClaim().getUri();
                ClaimMapping internalMapping = new ClaimMapping();
                org.wso2.carbon.identity.application.common.model.Claim remoteClaim = new org.wso2.carbon.identity.application.common.model.Claim();
                remoteClaim.setClaimUri(idpClaimUri);
                org.wso2.carbon.identity.application.common.model.Claim localClaim = new org.wso2.carbon.identity.application.common.model.Claim();
                localClaim.setClaimUri(localClaimUri);
                internalMapping.setRemoteClaim(remoteClaim);
                internalMapping.setLocalClaim(localClaim);
                claimMappings.add(internalMapping);
                idpClaims.add(remoteClaim);
            }
        } else {
            claimConfig.setLocalClaimDialect(true);
        }
        if ((claims.getUserIdClaim() != null)) {
            claimConfig.setUserClaimURI(claims.getUserIdClaim().getUri());
        }
        if (claims.getRoleClaim() != null) {
            claimConfig.setRoleClaimURI(claims.getRoleClaim().getUri());
        }
        List<ProvisioningClaim> provClaims = claims.getProvisioningClaims();
        for (ProvisioningClaim provClaim : provClaims) {
            String provClaimUri = provClaim.getClaim().getUri();
            if (CollectionUtils.isNotEmpty(claims.getMappings())) {
                for (ClaimMapping internalMapping : claimMappings) {
                    if (StringUtils.equals(provClaimUri, internalMapping.getRemoteClaim().getClaimUri())) {
                        internalMapping.setDefaultValue(provClaim.getDefaultValue());
                        internalMapping.setRequested(true);
                    }
                }
            } else {
                ClaimMapping internalMapping = new ClaimMapping();
                org.wso2.carbon.identity.application.common.model.Claim localClaim = new org.wso2.carbon.identity.application.common.model.Claim();
                localClaim.setClaimUri(provClaimUri);
                internalMapping.setLocalClaim(localClaim);
                internalMapping.setDefaultValue(provClaim.getDefaultValue());
                internalMapping.setRequested(true);
                claimMappings.add(internalMapping);
            }
        }
        claimConfig.setClaimMappings(claimMappings.toArray(new ClaimMapping[0]));
        claimConfig.setIdpClaims(idpClaims.toArray(new org.wso2.carbon.identity.application.common.model.Claim[0]));
        idp.setClaimConfig(claimConfig);
    }
}
Also used : ProvisioningClaim(org.wso2.carbon.identity.api.server.idp.v1.model.ProvisioningClaim) ArrayList(java.util.ArrayList) ClaimMapping(org.wso2.carbon.identity.application.common.model.ClaimMapping) ClaimConfig(org.wso2.carbon.identity.application.common.model.ClaimConfig) Claim(org.wso2.carbon.identity.api.server.idp.v1.model.Claim) LocalClaim(org.wso2.carbon.identity.claim.metadata.mgt.model.LocalClaim) ProvisioningClaim(org.wso2.carbon.identity.api.server.idp.v1.model.ProvisioningClaim)

Example 28 with ClaimConfig

use of org.wso2.carbon.identity.application.common.model.xsd.ClaimConfig in project identity-api-server by wso2.

the class ServerIdpManagementService method createClaimResponse.

private Claims createClaimResponse(ClaimConfig claimConfig) {
    Claims apiClaims = new Claims();
    List<org.wso2.carbon.identity.api.server.idp.v1.model.ClaimMapping> apiMappings = new ArrayList<>();
    List<ProvisioningClaim> provClaims = new ArrayList<>();
    if (claimConfig != null) {
        if (claimConfig.getClaimMappings() != null) {
            for (ClaimMapping mapping : claimConfig.getClaimMappings()) {
                org.wso2.carbon.identity.api.server.idp.v1.model.ClaimMapping apiMapping = new org.wso2.carbon.identity.api.server.idp.v1.model.ClaimMapping();
                Claim localClaim = new Claim();
                localClaim.setId(base64URLEncode(mapping.getLocalClaim().getClaimUri()));
                localClaim.setUri(mapping.getLocalClaim().getClaimUri());
                localClaim.setDisplayName(getDisplayNameOfLocalClaim(mapping.getLocalClaim().getClaimUri()));
                apiMapping.setLocalClaim(localClaim);
                // need to validate this here.
                if (StringUtils.isNotBlank(mapping.getRemoteClaim().getClaimUri())) {
                    apiMapping.setIdpClaim(mapping.getRemoteClaim().getClaimUri());
                    apiMappings.add(apiMapping);
                }
                if (StringUtils.isNotBlank(mapping.getDefaultValue()) && mapping.isRequested()) {
                    ProvisioningClaim provClaimResponse = new ProvisioningClaim();
                    Claim provClaim = new Claim();
                    if (StringUtils.isNotBlank(mapping.getRemoteClaim().getClaimUri())) {
                        provClaim.setUri(mapping.getRemoteClaim().getClaimUri());
                    } else {
                        provClaim.setId(base64URLEncode(mapping.getLocalClaim().getClaimUri()));
                        provClaim.setUri(mapping.getLocalClaim().getClaimUri());
                        provClaim.setDisplayName(getDisplayNameOfLocalClaim(mapping.getLocalClaim().getClaimUri()));
                    }
                    provClaimResponse.setClaim(provClaim);
                    provClaimResponse.setDefaultValue(mapping.getDefaultValue());
                    provClaims.add(provClaimResponse);
                }
            }
        }
        Claim roleClaim = new Claim();
        if (getLocalClaim(claimConfig.getRoleClaimURI()) != null) {
            roleClaim.setId(base64URLEncode(claimConfig.getRoleClaimURI()));
            roleClaim.setDisplayName(getDisplayNameOfLocalClaim(claimConfig.getRoleClaimURI()));
        }
        roleClaim.setUri(claimConfig.getRoleClaimURI());
        apiClaims.setRoleClaim(roleClaim);
        Claim userIdClaim = new Claim();
        if (getLocalClaim(claimConfig.getUserClaimURI()) != null) {
            userIdClaim.setId(base64URLEncode(claimConfig.getUserClaimURI()));
            userIdClaim.setDisplayName(getDisplayNameOfLocalClaim(claimConfig.getUserClaimURI()));
        }
        userIdClaim.setUri(claimConfig.getUserClaimURI());
        apiClaims.setUserIdClaim(userIdClaim);
    }
    apiClaims.setMappings(apiMappings);
    apiClaims.setProvisioningClaims(provClaims);
    return apiClaims;
}
Also used : ProvisioningClaim(org.wso2.carbon.identity.api.server.idp.v1.model.ProvisioningClaim) Claims(org.wso2.carbon.identity.api.server.idp.v1.model.Claims) ArrayList(java.util.ArrayList) ClaimMapping(org.wso2.carbon.identity.application.common.model.ClaimMapping) Claim(org.wso2.carbon.identity.api.server.idp.v1.model.Claim) LocalClaim(org.wso2.carbon.identity.claim.metadata.mgt.model.LocalClaim) ProvisioningClaim(org.wso2.carbon.identity.api.server.idp.v1.model.ProvisioningClaim)

Example 29 with ClaimConfig

use of org.wso2.carbon.identity.application.common.model.xsd.ClaimConfig in project identity-api-server by wso2.

the class UpdateClaimConfiguration method updateSubjectClaimConfigs.

private void updateSubjectClaimConfigs(SubjectConfig subjectApiModel, ServiceProvider application) {
    if (subjectApiModel != null) {
        LocalAndOutboundAuthenticationConfig authConfig = getLocalAndOutboundConfig(application);
        if (subjectApiModel.getClaim() != null) {
            setIfNotNull(subjectApiModel.getClaim().getUri(), authConfig::setSubjectClaimUri);
        }
        setIfNotNull(subjectApiModel.getIncludeTenantDomain(), authConfig::setUseTenantDomainInLocalSubjectIdentifier);
        setIfNotNull(subjectApiModel.getIncludeUserDomain(), authConfig::setUseUserstoreDomainInLocalSubjectIdentifier);
        ClaimConfig claimConfig = getClaimConfig(application);
        setIfNotNull(subjectApiModel.getUseMappedLocalSubject(), claimConfig::setAlwaysSendMappedLocalSubjectId);
    }
}
Also used : LocalAndOutboundAuthenticationConfig(org.wso2.carbon.identity.application.common.model.LocalAndOutboundAuthenticationConfig) ClaimConfig(org.wso2.carbon.identity.application.common.model.ClaimConfig)

Example 30 with ClaimConfig

use of org.wso2.carbon.identity.application.common.model.xsd.ClaimConfig in project carbon-apimgt by wso2.

the class APIAdminImpl method mergeIdpWithKeyManagerConfiguration.

private void mergeIdpWithKeyManagerConfiguration(IdentityProvider identityProvider, KeyManagerConfigurationDTO keyManagerDTO) {
    keyManagerDTO.setDisplayName(identityProvider.getDisplayName());
    keyManagerDTO.setDescription(identityProvider.getIdentityProviderDescription());
    IdentityProviderProperty[] identityProviderProperties = identityProvider.getIdpProperties();
    if (identityProviderProperties.length > 0) {
        for (IdentityProviderProperty identityProviderProperty : identityProviderProperties) {
            if (StringUtils.equals(identityProviderProperty.getName(), APIConstants.JWKS_URI)) {
                keyManagerDTO.addProperty(APIConstants.KeyManager.CERTIFICATE_TYPE, APIConstants.KeyManager.CERTIFICATE_TYPE_JWKS_ENDPOINT);
                keyManagerDTO.addProperty(APIConstants.KeyManager.CERTIFICATE_VALUE, identityProviderProperty.getValue());
            }
            if (StringUtils.equals(identityProviderProperty.getName(), IdentityApplicationConstants.IDP_ISSUER_NAME)) {
                keyManagerDTO.addProperty(APIConstants.KeyManager.ISSUER, identityProviderProperty.getValue());
            }
        }
    } else if (StringUtils.isNotBlank(identityProvider.getCertificate())) {
        keyManagerDTO.addProperty(APIConstants.KeyManager.CERTIFICATE_TYPE, APIConstants.KeyManager.CERTIFICATE_TYPE_PEM_FILE);
        keyManagerDTO.addProperty(APIConstants.KeyManager.CERTIFICATE_VALUE, identityProvider.getCertificate());
    }
    keyManagerDTO.setEnabled(identityProvider.isEnable());
    keyManagerDTO.setAlias(identityProvider.getAlias());
    ClaimConfig claimConfig = identityProvider.getClaimConfig();
    JsonArray claimArray = new JsonArray();
    for (ClaimMapping claimMapping : claimConfig.getClaimMappings()) {
        JsonObject claimMappingEntryDTO = new JsonObject();
        claimMappingEntryDTO.addProperty("localClaim", claimMapping.getLocalClaim().getClaimUri());
        claimMappingEntryDTO.addProperty("remoteClaim", claimMapping.getRemoteClaim().getClaimUri());
        claimArray.add(claimMappingEntryDTO);
    }
    keyManagerDTO.addProperty(APIConstants.KeyManager.CLAIM_MAPPING, claimArray);
}
Also used : JsonArray(com.google.gson.JsonArray) ClaimMapping(org.wso2.carbon.identity.application.common.model.ClaimMapping) IdentityProviderProperty(org.wso2.carbon.identity.application.common.model.IdentityProviderProperty) ClaimConfig(org.wso2.carbon.identity.application.common.model.ClaimConfig) JsonObject(com.google.gson.JsonObject)

Aggregations

ClaimConfig (org.wso2.carbon.identity.application.common.model.ClaimConfig)38 ClaimMapping (org.wso2.carbon.identity.application.common.model.ClaimMapping)28 ArrayList (java.util.ArrayList)22 ClaimConfig (org.wso2.carbon.identity.application.common.model.xsd.ClaimConfig)17 IdentityProvider (org.wso2.carbon.identity.application.common.model.IdentityProvider)14 ClaimMapping (org.wso2.carbon.identity.application.common.model.xsd.ClaimMapping)13 Claim (org.wso2.carbon.identity.application.common.model.Claim)12 ServiceProvider (org.wso2.carbon.identity.application.common.model.ServiceProvider)12 IdentityProviderProperty (org.wso2.carbon.identity.application.common.model.IdentityProviderProperty)11 PreparedStatement (java.sql.PreparedStatement)10 ProvisioningConnectorConfig (org.wso2.carbon.identity.application.common.model.ProvisioningConnectorConfig)10 Claim (org.wso2.carbon.identity.application.common.model.xsd.Claim)10 ResultSet (java.sql.ResultSet)9 Test (org.testng.annotations.Test)9 PermissionsAndRoleConfig (org.wso2.carbon.identity.application.common.model.PermissionsAndRoleConfig)9 ServiceProvider (org.wso2.carbon.identity.application.common.model.xsd.ServiceProvider)9 FederatedAuthenticatorConfig (org.wso2.carbon.identity.application.common.model.FederatedAuthenticatorConfig)8 RoleMapping (org.wso2.carbon.identity.application.common.model.RoleMapping)8 LocalAndOutboundAuthenticationConfig (org.wso2.carbon.identity.application.common.model.LocalAndOutboundAuthenticationConfig)7 Property (org.wso2.carbon.identity.application.common.model.Property)7