Search in sources :

Example 21 with ClaimMapping

use of org.wso2.carbon.identity.application.common.model.xsd.ClaimMapping in project carbon-identity-framework by wso2.

the class IdPManagementDAOTest method addIdPData.

@DataProvider
public Object[][] addIdPData() {
    // Initialize Test Identity Provider 1.
    IdentityProvider idp1 = new IdentityProvider();
    idp1.setIdentityProviderName("testIdP1");
    idp1.setEnable(true);
    idp1.setPrimary(true);
    idp1.setFederationHub(true);
    idp1.setCertificate("");
    RoleMapping roleMapping1 = new RoleMapping(new LocalRole("1", "LocalRole1"), "Role1");
    RoleMapping roleMapping2 = new RoleMapping(new LocalRole("2", "LocalRole2"), "Role2");
    PermissionsAndRoleConfig permissionsAndRoleConfig = new PermissionsAndRoleConfig();
    permissionsAndRoleConfig.setIdpRoles(new String[] { "Role1", "Role2" });
    permissionsAndRoleConfig.setRoleMappings(new RoleMapping[] { roleMapping1, roleMapping2 });
    idp1.setPermissionAndRoleConfig(permissionsAndRoleConfig);
    FederatedAuthenticatorConfig federatedAuthenticatorConfig = new FederatedAuthenticatorConfig();
    federatedAuthenticatorConfig.setDisplayName("DisplayName1");
    federatedAuthenticatorConfig.setName("Name");
    federatedAuthenticatorConfig.setEnabled(true);
    Property property1 = new Property();
    property1.setName("Property1");
    property1.setValue("value1");
    property1.setConfidential(false);
    Property property2 = new Property();
    property2.setName("Property2");
    property2.setValue("value2");
    property2.setConfidential(true);
    federatedAuthenticatorConfig.setProperties(new Property[] { property1, property2 });
    idp1.setFederatedAuthenticatorConfigs(new FederatedAuthenticatorConfig[] { federatedAuthenticatorConfig });
    ProvisioningConnectorConfig provisioningConnectorConfig1 = new ProvisioningConnectorConfig();
    provisioningConnectorConfig1.setName("ProvisiningConfig1");
    provisioningConnectorConfig1.setProvisioningProperties(new Property[] { property1 });
    ProvisioningConnectorConfig provisioningConnectorConfig2 = new ProvisioningConnectorConfig();
    provisioningConnectorConfig2.setName("ProvisiningConfig2");
    provisioningConnectorConfig2.setProvisioningProperties(new Property[] { property2 });
    provisioningConnectorConfig2.setEnabled(true);
    provisioningConnectorConfig2.setBlocking(true);
    idp1.setProvisioningConnectorConfigs(new ProvisioningConnectorConfig[] { provisioningConnectorConfig1, provisioningConnectorConfig2 });
    ClaimConfig claimConfig = new ClaimConfig();
    claimConfig.setLocalClaimDialect(false);
    claimConfig.setRoleClaimURI("Country");
    claimConfig.setUserClaimURI("Country");
    ClaimMapping claimMapping = ClaimMapping.build("http://wso2.org/claims/country", "Country", "", true);
    claimConfig.setClaimMappings(new ClaimMapping[] { claimMapping });
    Claim remoteClaim = new Claim();
    remoteClaim.setClaimId(0);
    remoteClaim.setClaimUri("Country");
    claimConfig.setIdpClaims(new Claim[] { remoteClaim });
    idp1.setClaimConfig(claimConfig);
    // Initialize Test Identity Provider 2.
    IdentityProvider idp2 = new IdentityProvider();
    idp2.setIdentityProviderName("testIdP2");
    ClaimConfig claimConfig2 = new ClaimConfig();
    claimConfig2.setLocalClaimDialect(true);
    claimConfig2.setRoleClaimURI("http://wso2.org/claims/role");
    claimConfig2.setUserClaimURI("http://wso2.org/claims/fullname");
    ClaimMapping claimMapping2 = new ClaimMapping();
    Claim localClaim2 = new Claim();
    localClaim2.setClaimId(0);
    localClaim2.setClaimUri("http://wso2.org/claims/fullname");
    claimMapping2.setLocalClaim(localClaim2);
    claimConfig2.setClaimMappings(new ClaimMapping[] { claimMapping2 });
    idp2.setClaimConfig(claimConfig2);
    // Initialize Test Identity Provider 3.
    IdentityProvider idp3 = new IdentityProvider();
    idp3.setIdentityProviderName("testIdP3");
    return new Object[][] { // IDP with PermissionsAndRoleConfig,FederatedAuthenticatorConfigs,ProvisioningConnectorConfigs,Claims.
    { idp1, SAMPLE_TENANT_ID }, // IDP with Local Cliam Dialect ClaimConfigs.
    { idp2, SAMPLE_TENANT_ID }, // IDP with Only name.
    { idp3, SAMPLE_TENANT_ID2 } };
}
Also used : ClaimMapping(org.wso2.carbon.identity.application.common.model.ClaimMapping) PermissionsAndRoleConfig(org.wso2.carbon.identity.application.common.model.PermissionsAndRoleConfig) FederatedAuthenticatorConfig(org.wso2.carbon.identity.application.common.model.FederatedAuthenticatorConfig) ClaimConfig(org.wso2.carbon.identity.application.common.model.ClaimConfig) IdentityProvider(org.wso2.carbon.identity.application.common.model.IdentityProvider) LocalRole(org.wso2.carbon.identity.application.common.model.LocalRole) RoleMapping(org.wso2.carbon.identity.application.common.model.RoleMapping) Property(org.wso2.carbon.identity.application.common.model.Property) IdentityProviderProperty(org.wso2.carbon.identity.application.common.model.IdentityProviderProperty) ProvisioningConnectorConfig(org.wso2.carbon.identity.application.common.model.ProvisioningConnectorConfig) Claim(org.wso2.carbon.identity.application.common.model.Claim) DataProvider(org.testng.annotations.DataProvider)

Example 22 with ClaimMapping

use of org.wso2.carbon.identity.application.common.model.xsd.ClaimMapping in project carbon-identity-framework by wso2.

the class OutboundProvisioningManager method provision.

/**
 * Outbound provisioning method.
 *
 * @param provisioningEntity        Provisioning entity.
 * @param serviceProviderIdentifier Identifier of the service provider.
 * @param inboundClaimDialect       Inbound claim dialect.
 * @param spTenantDomainName        Tenant domain of the service provider.
 * @param jitProvisioning           Is JIT provisioning enabled.
 * @throws IdentityProvisioningException if error occurred while user provisioning.
 */
public void provision(ProvisioningEntity provisioningEntity, String serviceProviderIdentifier, String inboundClaimDialect, String spTenantDomainName, boolean jitProvisioning) throws IdentityProvisioningException {
    try {
        if (provisioningEntity.getEntityName() == null) {
            setProvisioningEntityName(provisioningEntity);
        }
        // get details about the service provider.any in-bound provisioning request via
        // the SOAP based API (or the management console) - or SCIM API with HTTP Basic
        // Authentication is considered as coming from the local service provider.
        ServiceProvider serviceProvider = ApplicationManagementService.getInstance().getServiceProvider(serviceProviderIdentifier, spTenantDomainName);
        if (serviceProvider == null) {
            throw new IdentityProvisioningException("Invalid service provider name : " + serviceProviderIdentifier);
        }
        String provisioningEntityTenantDomainName = spTenantDomainName;
        if (serviceProvider.isSaasApp() && isUserTenantBasedOutboundProvisioningEnabled()) {
            provisioningEntityTenantDomainName = CarbonContext.getThreadLocalCarbonContext().getTenantDomain();
        }
        ClaimMapping[] spClaimMappings = null;
        // if we know the serviceProviderClaimDialect - we do not need to find it again.
        if (inboundClaimDialect == null && serviceProvider.getClaimConfig() != null) {
            spClaimMappings = serviceProvider.getClaimConfig().getClaimMappings();
        }
        // get all the provisioning connectors associated with local service provider for
        // out-bound provisioning.
        // TODO: stop loading connectors all the time.
        Map<String, RuntimeProvisioningConfig> connectors = getOutboundProvisioningConnectors(serviceProvider, spTenantDomainName);
        ProvisioningEntity outboundProEntity;
        ExecutorService executors = null;
        if (MapUtils.isNotEmpty(connectors)) {
            executors = Executors.newFixedThreadPool(connectors.size());
        }
        for (Iterator<Entry<String, RuntimeProvisioningConfig>> iterator = connectors.entrySet().iterator(); iterator.hasNext(); ) {
            Entry<String, RuntimeProvisioningConfig> entry = iterator.next();
            Entry<String, AbstractOutboundProvisioningConnector> connectorEntry = entry.getValue().getProvisioningConnectorEntry();
            AbstractOutboundProvisioningConnector connector = connectorEntry.getValue();
            String connectorType = connectorEntry.getKey();
            String idPName = entry.getKey();
            IdentityProvider provisioningIdp = IdentityProviderManager.getInstance().getIdPByName(idPName, spTenantDomainName);
            if (provisioningIdp == null) {
                // by its name.
                throw new IdentityProvisioningException("Invalid identity provider name : " + idPName);
            }
            String outboundClaimDialect = connector.getClaimDialectUri();
            if (outboundClaimDialect == null && (provisioningIdp.getClaimConfig() == null || provisioningIdp.getClaimConfig().isLocalClaimDialect())) {
                outboundClaimDialect = IdentityProvisioningConstants.WSO2_CARBON_DIALECT;
            }
            ClaimMapping[] idpClaimMappings = null;
            if (provisioningIdp.getClaimConfig() != null) {
                idpClaimMappings = provisioningIdp.getClaimConfig().getClaimMappings();
            }
            // TODO: this should happen asynchronously in a different thread.
            // create a new provisioning entity object for each provisioning identity
            // provider.
            Map<ClaimMapping, List<String>> mapppedClaims;
            // get mapped claims.
            mapppedClaims = getMappedClaims(inboundClaimDialect, outboundClaimDialect, provisioningEntity, spClaimMappings, idpClaimMappings, spTenantDomainName);
            if (provisioningIdp.getPermissionAndRoleConfig() != null) {
                // update with mapped user groups.
                updateProvisioningUserWithMappedRoles(provisioningEntity, provisioningIdp.getPermissionAndRoleConfig().getRoleMappings());
            }
            // check whether we already have the provisioned identifier - if
            // so set it.
            ProvisionedIdentifier provisionedIdentifier;
            provisionedIdentifier = getProvisionedEntityIdentifier(idPName, connectorType, provisioningEntity, spTenantDomainName);
            ProvisioningOperation provisioningOp = provisioningEntity.getOperation();
            if (ProvisioningOperation.DELETE.equals(provisioningOp) && (provisionedIdentifier == null || provisionedIdentifier.getIdentifier() == null)) {
                // send outbound delete request. Skip the flow
                return;
            }
            if (provisionedIdentifier == null || provisionedIdentifier.getIdentifier() == null) {
                provisioningOp = ProvisioningOperation.POST;
            }
            String[] provisionByRoleList = new String[0];
            if (provisioningIdp.getProvisioningRole() != null) {
                provisionByRoleList = provisioningIdp.getProvisioningRole().trim().split("\\s*,[,\\s]*");
            }
            if (provisioningEntity.getEntityType() == ProvisioningEntityType.GROUP && Arrays.asList(provisionByRoleList).contains(provisioningEntity.getEntityName())) {
                Map<ClaimMapping, List<String>> attributes = provisioningEntity.getAttributes();
                List<String> newUsersList = attributes.get(ClaimMapping.build(IdentityProvisioningConstants.NEW_USER_CLAIM_URI, null, null, false));
                List<String> deletedUsersList = attributes.get(ClaimMapping.build(IdentityProvisioningConstants.DELETED_USER_CLAIM_URI, null, null, false));
                Map<ClaimMapping, List<String>> mappedUserClaims;
                ProvisionedIdentifier provisionedUserIdentifier;
                for (String user : newUsersList) {
                    ProvisioningEntity inboundProvisioningEntity = getInboundProvisioningEntity(provisioningEntity, provisioningEntityTenantDomainName, ProvisioningOperation.POST, user);
                    provisionedUserIdentifier = getProvisionedEntityIdentifier(idPName, connectorType, inboundProvisioningEntity, spTenantDomainName);
                    if (provisionedUserIdentifier != null && provisionedUserIdentifier.getIdentifier() != null) {
                        continue;
                    }
                    mappedUserClaims = getMappedClaims(inboundClaimDialect, outboundClaimDialect, inboundProvisioningEntity, spClaimMappings, idpClaimMappings, spTenantDomainName);
                    outboundProEntity = new ProvisioningEntity(ProvisioningEntityType.USER, user, ProvisioningOperation.POST, mappedUserClaims);
                    Callable<Boolean> proThread = new ProvisioningThread(outboundProEntity, spTenantDomainName, provisioningEntityTenantDomainName, connector, connectorType, idPName, dao);
                    outboundProEntity.setIdentifier(provisionedIdentifier);
                    outboundProEntity.setJitProvisioning(jitProvisioning);
                    boolean isBlocking = entry.getValue().isBlocking();
                    executeOutboundProvisioning(provisioningEntity, executors, connectorType, idPName, proThread, isBlocking);
                }
                for (String user : deletedUsersList) {
                    ProvisioningEntity inboundProvisioningEntity = getInboundProvisioningEntity(provisioningEntity, provisioningEntityTenantDomainName, ProvisioningOperation.DELETE, user);
                    provisionedUserIdentifier = getProvisionedEntityIdentifier(idPName, connectorType, inboundProvisioningEntity, spTenantDomainName);
                    if (provisionedUserIdentifier != null && provisionedUserIdentifier.getIdentifier() != null) {
                        mappedUserClaims = getMappedClaims(inboundClaimDialect, outboundClaimDialect, inboundProvisioningEntity, spClaimMappings, idpClaimMappings, spTenantDomainName);
                        outboundProEntity = new ProvisioningEntity(ProvisioningEntityType.USER, user, ProvisioningOperation.DELETE, mappedUserClaims);
                        Callable<Boolean> proThread = new ProvisioningThread(outboundProEntity, spTenantDomainName, provisioningEntityTenantDomainName, connector, connectorType, idPName, dao);
                        outboundProEntity.setIdentifier(provisionedUserIdentifier);
                        outboundProEntity.setJitProvisioning(jitProvisioning);
                        boolean isBlocking = entry.getValue().isBlocking();
                        executeOutboundProvisioning(provisioningEntity, executors, connectorType, idPName, proThread, isBlocking);
                    }
                }
            } else {
                if (!canUserBeProvisioned(provisioningEntity, provisionByRoleList, provisioningEntityTenantDomainName)) {
                    if (!canUserBeDeProvisioned(provisionedIdentifier)) {
                        continue;
                    } else {
                        // This is used when user removed from the provisioning role
                        provisioningOp = ProvisioningOperation.DELETE;
                    }
                }
                if (!skipOutBoundProvisioning(provisioningOp, provisioningEntity, inboundClaimDialect)) {
                    outboundProEntity = new ProvisioningEntity(provisioningEntity.getEntityType(), provisioningEntity.getEntityName(), provisioningOp, mapppedClaims);
                    Callable<Boolean> proThread = new ProvisioningThread(outboundProEntity, spTenantDomainName, provisioningEntityTenantDomainName, connector, connectorType, idPName, dao);
                    outboundProEntity.setIdentifier(provisionedIdentifier);
                    outboundProEntity.setJitProvisioning(jitProvisioning);
                    boolean isAllowed = true;
                    boolean isBlocking = entry.getValue().isBlocking();
                    boolean isPolicyEnabled = entry.getValue().isPolicyEnabled();
                    if (isPolicyEnabled) {
                        isAllowed = XACMLBasedRuleHandler.getInstance().isAllowedToProvision(spTenantDomainName, provisioningEntity, serviceProvider, idPName, connectorType);
                    }
                    if (isAllowed) {
                        executeOutboundProvisioning(provisioningEntity, executors, connectorType, idPName, proThread, isBlocking);
                    }
                }
            }
        }
        if (executors != null) {
            executors.shutdown();
        }
    } catch (CarbonException | IdentityApplicationManagementException | IdentityProviderManagementException | UserStoreException e) {
        throw new IdentityProvisioningException("Error occurred while checking for user " + "provisioning", e);
    }
}
Also used : CarbonException(org.wso2.carbon.CarbonException) Entry(java.util.Map.Entry) SimpleEntry(java.util.AbstractMap.SimpleEntry) ServiceProviderProvisioningConnectorCacheEntry(org.wso2.carbon.identity.provisioning.cache.ServiceProviderProvisioningConnectorCacheEntry) UserStoreException(org.wso2.carbon.user.api.UserStoreException) List(java.util.List) ArrayList(java.util.ArrayList) IdentityApplicationManagementException(org.wso2.carbon.identity.application.common.IdentityApplicationManagementException) IdentityProvider(org.wso2.carbon.identity.application.common.model.IdentityProvider) ClaimMapping(org.wso2.carbon.identity.application.common.model.ClaimMapping) ServiceProvider(org.wso2.carbon.identity.application.common.model.ServiceProvider) ExecutorService(java.util.concurrent.ExecutorService) IdentityProviderManagementException(org.wso2.carbon.idp.mgt.IdentityProviderManagementException)

Example 23 with ClaimMapping

use of org.wso2.carbon.identity.application.common.model.xsd.ClaimMapping in project carbon-identity-framework by wso2.

the class ProvisioningUtil method getMappedClaims.

public static Map<ClaimMapping, List<String>> getMappedClaims(ClaimMapping[] outboundClaimMappings, Map<String, String> inboundClaimValueMap, ClaimMapping[] inboundClaimMappings, Map<ClaimMapping, List<String>> outboundClaimValueMappings) throws IdentityApplicationManagementException {
    try {
        if (outboundClaimValueMappings == null) {
            outboundClaimValueMappings = new HashMap<ClaimMapping, List<String>>();
        }
        if (MapUtils.isEmpty(inboundClaimValueMap)) {
            // the out-bound claim mapping.
            if (outboundClaimMappings != null && outboundClaimMappings.length > 0) {
                for (ClaimMapping mapping : outboundClaimMappings) {
                    if (mapping.getDefaultValue() != null) {
                        outboundClaimValueMappings.put(mapping, Arrays.asList(new String[] { mapping.getDefaultValue() }));
                    }
                }
            }
            return outboundClaimValueMappings;
        }
        if (outboundClaimMappings == null || outboundClaimMappings.length == 0) {
            // we cannot find out-bound claim dialect - return what we have.
            return outboundClaimValueMappings;
        }
        Map<String, String> claimMap = null;
        // out-bound is not in wso2 carbon dialect. we need to find how it maps to wso2
        // carbon dialect.
        Map<String, String> inboundToCarbonClaimMaping = new HashMap<String, String>();
        Map<String, String> outBoundToCarbonClaimMappping = new HashMap<String, String>();
        Map<String, String> outboundClaimDefaultValues = new HashMap<String, String>();
        for (ClaimMapping inboundClaimMapping : inboundClaimMappings) {
            // populate map with in-bound claims.
            if (inboundClaimMapping.getLocalClaim() != null) {
                inboundToCarbonClaimMaping.put(inboundClaimMapping.getLocalClaim().getClaimUri(), inboundClaimMapping.getRemoteClaim().getClaimUri());
            } else {
            // ignore. if you do not have a local claim we cannot map it.
            }
        }
        for (ClaimMapping outboundClaimMapping : outboundClaimMappings) {
            // use remote claim uri as the key.
            if (outboundClaimMapping.getLocalClaim() != null) {
                outBoundToCarbonClaimMappping.put(outboundClaimMapping.getRemoteClaim().getClaimUri(), outboundClaimMapping.getLocalClaim().getClaimUri());
            } else {
                outBoundToCarbonClaimMappping.put(outboundClaimMapping.getRemoteClaim().getClaimUri(), null);
            }
            outboundClaimDefaultValues.put(outboundClaimMapping.getRemoteClaim().getClaimUri(), outboundClaimMapping.getDefaultValue());
        }
        claimMap = new HashMap<String, String>();
        // we need to have everything in the out-bound claim dialect in the claimMap.
        for (Iterator<Map.Entry<String, String>> iterator = outBoundToCarbonClaimMappping.entrySet().iterator(); iterator.hasNext(); ) {
            Map.Entry<String, String> entry = iterator.next();
            String localClaimUri = entry.getValue();
            String outboundClaimUri = entry.getKey();
            String inboundClaim = inboundToCarbonClaimMaping.get(localClaimUri);
            claimMap.put(outboundClaimUri, inboundClaim);
        }
        if (claimMap.isEmpty()) {
            return outboundClaimValueMappings;
        }
        for (Iterator<Map.Entry<String, String>> iterator = claimMap.entrySet().iterator(); iterator.hasNext(); ) {
            Map.Entry<String, String> entry = iterator.next();
            String outboundClaimUri = entry.getKey();
            String inboundClaimUri = entry.getValue();
            if (inboundClaimUri != null && inboundClaimValueMap.get(inboundClaimUri) != null) {
                outboundClaimValueMappings.put(ClaimMapping.build(inboundClaimUri, outboundClaimUri, outboundClaimDefaultValues.get(outboundClaimUri), false), Arrays.asList(new String[] { inboundClaimValueMap.get(inboundClaimUri) }));
            } else {
                outboundClaimValueMappings.put(ClaimMapping.build(inboundClaimUri, outboundClaimUri, outboundClaimDefaultValues.get(outboundClaimUri), false), Arrays.asList(new String[] { outboundClaimDefaultValues.get(outboundClaimUri) }));
            }
        }
    } catch (Exception e) {
        throw new IdentityApplicationManagementException("Error while loading claim mappings.", e);
    }
    return outboundClaimValueMappings;
}
Also used : HashMap(java.util.HashMap) IdentityApplicationManagementException(org.wso2.carbon.identity.application.common.IdentityApplicationManagementException) IdentityApplicationManagementException(org.wso2.carbon.identity.application.common.IdentityApplicationManagementException) ClaimMapping(org.wso2.carbon.identity.application.common.model.ClaimMapping) ArrayList(java.util.ArrayList) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map)

Example 24 with ClaimMapping

use of org.wso2.carbon.identity.application.common.model.xsd.ClaimMapping in project carbon-identity-framework by wso2.

the class ProvisioningUtil method getMappedClaims.

public static Map<ClaimMapping, List<String>> getMappedClaims(ClaimMapping[] outboundClaimMappings, Map<String, String> inboundClaimValueMap, String inboundClaimMappingDialect, Map<ClaimMapping, List<String>> outboundClaimValueMappings, String tenantDomain) throws IdentityApplicationManagementException {
    try {
        if (MapUtils.isEmpty(inboundClaimValueMap)) {
            // the out-bound claim mapping.
            if (outboundClaimMappings != null && outboundClaimMappings.length > 0) {
                for (ClaimMapping mapping : outboundClaimMappings) {
                    if (mapping.getDefaultValue() != null) {
                        outboundClaimValueMappings.put(mapping, Arrays.asList(new String[] { mapping.getDefaultValue() }));
                    }
                }
            }
            return outboundClaimValueMappings;
        }
        if (outboundClaimMappings == null || outboundClaimMappings.length == 0) {
            // we cannot find out-bound claim dialect - return what we have.
            return outboundClaimValueMappings;
        }
        Map<String, String> claimMap = null;
        // out-bound is not in wso2 carbon dialect. we need to find how it maps to wso2
        // carbon dialect.
        Map<String, String> carbonToInboundClaimMapping = null;
        // we only know the dialect - it is standard claim dialect.
        // returns the carbon claim mapping corresponding to claims in the the in-bound
        // provisioning request with carbon in-bound claim uris as the key.
        carbonToInboundClaimMapping = ClaimMetadataHandler.getInstance().getMappingsMapFromOtherDialectToCarbon(inboundClaimMappingDialect, inboundClaimValueMap.keySet(), tenantDomain, true);
        claimMap = new HashMap<String, String>();
        Map<String, String> outboundClaimDefaultValues = new HashMap<String, String>();
        for (ClaimMapping outboundClaimMapping : outboundClaimMappings) {
            String inboundClaim = null;
            if (outboundClaimMapping.getLocalClaim() != null) {
                inboundClaim = carbonToInboundClaimMapping.get(outboundClaimMapping.getLocalClaim().getClaimUri());
            }
            claimMap.put(outboundClaimMapping.getRemoteClaim().getClaimUri(), inboundClaim);
            outboundClaimDefaultValues.put(outboundClaimMapping.getRemoteClaim().getClaimUri(), outboundClaimMapping.getDefaultValue());
        }
        if (claimMap.isEmpty()) {
            return outboundClaimValueMappings;
        }
        for (Iterator<Map.Entry<String, String>> iterator = claimMap.entrySet().iterator(); iterator.hasNext(); ) {
            Map.Entry<String, String> entry = iterator.next();
            String outboundClaimUri = entry.getKey();
            String inboundClaimUri = entry.getValue();
            if (inboundClaimUri != null && inboundClaimValueMap.get(inboundClaimUri) != null) {
                outboundClaimValueMappings.put(ClaimMapping.build(inboundClaimUri, outboundClaimUri, outboundClaimDefaultValues.get(outboundClaimUri), false), Arrays.asList(new String[] { inboundClaimValueMap.get(inboundClaimUri) }));
            } else {
                outboundClaimValueMappings.put(ClaimMapping.build(inboundClaimUri, outboundClaimUri, outboundClaimDefaultValues.get(outboundClaimUri), false), Arrays.asList(new String[] { outboundClaimDefaultValues.get(outboundClaimUri) }));
            }
        }
    } catch (Exception e) {
        throw new IdentityApplicationManagementException("Error while loading claim mappings.", e);
    }
    return outboundClaimValueMappings;
}
Also used : ClaimMapping(org.wso2.carbon.identity.application.common.model.ClaimMapping) HashMap(java.util.HashMap) IdentityApplicationManagementException(org.wso2.carbon.identity.application.common.IdentityApplicationManagementException) HashMap(java.util.HashMap) Map(java.util.Map) IdentityApplicationManagementException(org.wso2.carbon.identity.application.common.IdentityApplicationManagementException)

Example 25 with ClaimMapping

use of org.wso2.carbon.identity.application.common.model.xsd.ClaimMapping in project carbon-identity-framework by wso2.

the class ProvisioningUtil method getMappedClaims.

public static Map<ClaimMapping, List<String>> getMappedClaims(String outboundClaimDialect, Map<String, String> inboundClaimValueMap, String inboundClaimMappingDialect, Map<ClaimMapping, List<String>> outboundClaimValueMappings, String tenantDomain) throws IdentityApplicationManagementException {
    try {
        if (MapUtils.isEmpty(inboundClaimValueMap)) {
            return outboundClaimValueMappings;
        }
        Map<String, String> claimMap = null;
        if (IdentityApplicationConstants.WSO2CARBON_CLAIM_DIALECT.equals(inboundClaimMappingDialect)) {
            // in-bound dialect is in default carbon dialect.
            // otherDialectURI, carbonClaimURIs, tenantDomain, carbonDialectAsKey
            // this map will have out-bound dialect as the key.
            claimMap = ClaimMetadataHandler.getInstance().getMappingsMapFromOtherDialectToCarbon(outboundClaimDialect, null, tenantDomain, true);
        } else {
            // out-bound is not in wso2 carbon dialect. we need to find how it maps to wso2
            // carbon dialect.
            Map<String, String> inboundToCarbonClaimMaping = null;
            Map<String, String> outBoundToCarbonClaimMappping = null;
            // this will return back the mapped carbon dialect for the in-bound claims in the
            // in-bound provisioning request.
            // the key of this map will be in in-bound claim dialect.
            inboundToCarbonClaimMaping = ClaimMetadataHandler.getInstance().getMappingsMapFromOtherDialectToCarbon(inboundClaimMappingDialect, inboundClaimValueMap.keySet(), tenantDomain, false);
            // we only know the dialect - it is standard claim dialect.
            // this will return back all the wso2 carbon claims mapped to the out-bound dialect.
            // we send null here because we do not know the required claims for out-bound
            // provisioning.
            // the key of this map will be in carbon dialect.
            outBoundToCarbonClaimMappping = ClaimMetadataHandler.getInstance().getMappingsMapFromOtherDialectToCarbon(outboundClaimDialect, null, tenantDomain, true);
            // in-bound dialect / out-bound dialect.
            claimMap = new HashMap<String, String>();
            for (Iterator<Map.Entry<String, String>> iterator = inboundToCarbonClaimMaping.entrySet().iterator(); iterator.hasNext(); ) {
                Map.Entry<String, String> entry = iterator.next();
                String outboundClaim = outBoundToCarbonClaimMappping.get(entry.getValue());
                if (outboundClaim != null) {
                    claimMap.put(entry.getKey(), outboundClaim);
                }
            }
        }
        if (claimMap.isEmpty()) {
            return outboundClaimValueMappings;
        }
        // through the in-bound provisioning claim map.
        for (Iterator<Map.Entry<String, String>> iterator = claimMap.entrySet().iterator(); iterator.hasNext(); ) {
            Map.Entry<String, String> entry = iterator.next();
            String outboundClaimUri = entry.getValue();
            String inboundClaimUri = entry.getKey();
            String claimValue = null;
            if (outboundClaimUri != null) {
                claimValue = inboundClaimValueMap.get(inboundClaimUri);
            }
            if (claimValue != null) {
                outboundClaimValueMappings.put(ClaimMapping.build(inboundClaimUri, outboundClaimUri, null, false), Arrays.asList(new String[] { claimValue }));
            }
        }
    } catch (Exception e) {
        throw new IdentityApplicationManagementException("Error while loading claim mappings.", e);
    }
    return outboundClaimValueMappings;
}
Also used : IdentityApplicationManagementException(org.wso2.carbon.identity.application.common.IdentityApplicationManagementException) HashMap(java.util.HashMap) Map(java.util.Map) IdentityApplicationManagementException(org.wso2.carbon.identity.application.common.IdentityApplicationManagementException)

Aggregations

ClaimMapping (org.wso2.carbon.identity.application.common.model.ClaimMapping)108 HashMap (java.util.HashMap)60 ArrayList (java.util.ArrayList)52 ClaimConfig (org.wso2.carbon.identity.application.common.model.ClaimConfig)27 Map (java.util.Map)26 ServiceProvider (org.wso2.carbon.identity.application.common.model.ServiceProvider)24 ClaimMapping (org.wso2.carbon.identity.application.common.model.xsd.ClaimMapping)24 ClaimMapping (org.wso2.carbon.user.api.ClaimMapping)24 Claim (org.wso2.carbon.identity.application.common.model.Claim)23 Test (org.testng.annotations.Test)22 Claim (org.wso2.carbon.identity.application.common.model.xsd.Claim)21 LocalClaim (org.wso2.carbon.identity.claim.metadata.mgt.model.LocalClaim)21 AuthenticatedUser (org.wso2.carbon.identity.application.authentication.framework.model.AuthenticatedUser)20 IdentityApplicationManagementException (org.wso2.carbon.identity.application.common.IdentityApplicationManagementException)20 List (java.util.List)17 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)17 UserStoreException (org.wso2.carbon.user.api.UserStoreException)17 Matchers.anyString (org.mockito.Matchers.anyString)16 IdentityProvider (org.wso2.carbon.identity.application.common.model.IdentityProvider)13 ClaimMetadataException (org.wso2.carbon.identity.claim.metadata.mgt.exception.ClaimMetadataException)13