Java Code Examples for org.wso2.carbon.identity.application.common.model.ClaimMapping#getLocalClaim()

The following examples show how to use org.wso2.carbon.identity.application.common.model.ClaimMapping#getLocalClaim() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ProvisioningUtil.java    From carbon-identity-framework with Apache License 2.0 6 votes vote down vote up
/**
 * @param claimUri
 * @param attributeList
 */
public static void setClaimValue(String claimUri, Map<ClaimMapping, List<String>> attributeMap,
                                 List<String> attributeList) {

    ClaimMapping clmMapping = null;

    for (Map.Entry<ClaimMapping, List<String>> entry : attributeMap.entrySet()) {
        ClaimMapping mapping = entry.getKey();
        if (mapping.getLocalClaim() != null
                && claimUri.equals(mapping.getLocalClaim().getClaimUri())) {
            clmMapping = mapping;
            break;
        }
    }

    if (clmMapping != null) {
        attributeMap.put(clmMapping, attributeList);
    }
}
 
Example 2
Source File: ProvisioningUtil.java    From carbon-identity with Apache License 2.0 6 votes vote down vote up
/**
 * @param claimUri
 * @param attributeList
 */
public static void setClaimValue(String claimUri, Map<ClaimMapping, List<String>> attributeMap,
                                 List<String> attributeList) {

    ClaimMapping clmMapping = null;

    for (Map.Entry<ClaimMapping, List<String>> entry : attributeMap.entrySet()) {
        ClaimMapping mapping = entry.getKey();
        if (mapping.getLocalClaim() != null
                && claimUri.equals(mapping.getLocalClaim().getClaimUri())) {
            clmMapping = mapping;
            break;
        }
    }

    if (clmMapping != null) {
        attributeMap.put(clmMapping, attributeList);
    }
}
 
Example 3
Source File: JWTAccessTokenBuilder.java    From msf4j with Apache License 2.0 5 votes vote down vote up
private void addUserClaims(JWTClaimsSet jwtClaimsSet, AuthenticatedUser user) {
    for (Map.Entry<ClaimMapping, String> entry : user.getUserAttributes().entrySet()) {
        ClaimMapping claimMapping = entry.getKey();
        Claim claim = claimMapping.getLocalClaim();
        if (claim != null && Constants.CUSTOMER_ID_CLAIM_URI.equalsIgnoreCase(claim.getClaimUri())) {
            jwtClaimsSet.setClaim(Constants.CUSTOMER_ID_CLAIM_URI, entry.getValue());
        }
    }
}
 
Example 4
Source File: IdPManagementDAO.java    From carbon-identity with Apache License 2.0 5 votes vote down vote up
/**
 * @param conn
 * @param idPId
 * @param tenantId
 * @param claimMappings
 * @throws SQLException
 * @throws IdentityProviderManagementException
 */
private void addDefaultClaimValuesForLocalIdP(Connection conn, int idPId, int tenantId,
                                              ClaimMapping[] claimMappings) throws SQLException,
        IdentityProviderManagementException {

    PreparedStatement prepStmt = null;
    ResultSet rs = null;
    String sqlStmt;

    try {

        if (claimMappings == null || claimMappings.length == 0) {
            return;
        }

        sqlStmt = IdPManagementConstants.SQLQueries.ADD_LOCAL_IDP_DEFAULT_CLAIM_VALUES_SQL;
        prepStmt = conn.prepareStatement(sqlStmt);
        for (ClaimMapping mapping : claimMappings) {
            if (mapping != null && mapping.getLocalClaim() != null
                    && mapping.getLocalClaim().getClaimUri() != null) {

                prepStmt.setInt(1, idPId);
                prepStmt.setString(2, mapping.getLocalClaim().getClaimUri());
                prepStmt.setString(3, mapping.getDefaultValue());
                prepStmt.setInt(4, tenantId);
                if (mapping.isRequested()) {
                    prepStmt.setString(5, IdPManagementConstants.IS_TRUE_VALUE);
                } else {
                    prepStmt.setString(5, IdPManagementConstants.IS_FALSE_VALUE);
                }
                prepStmt.addBatch();
            }
        }

        prepStmt.executeBatch();

    } finally {
        IdentityDatabaseUtil.closeAllConnections(null, rs, prepStmt);
    }
}
 
Example 5
Source File: FileBasedApplicationDAO.java    From carbon-identity with Apache License 2.0 5 votes vote down vote up
@Override
public List<String> getAllRequestedClaimsByServiceProvider(String serviceProviderName,
                                                           String tenantDomain) throws IdentityApplicationManagementException {
    ServiceProvider serviceProvider = ApplicationManagementServiceComponent.getFileBasedSPs()
            .get(serviceProviderName);

    List<String> requestedClaimList = new ArrayList<String>();

    if (serviceProvider == null || serviceProvider.getClaimConfig() == null) {
        return requestedClaimList;
    }

    ClaimMapping[] claimMappings = serviceProvider.getClaimConfig().getClaimMappings();

    if (claimMappings != null && claimMappings.length > 0) {

        for (ClaimMapping mapping : claimMappings) {
            if (mapping.isRequested()) {
                if (mapping.getRemoteClaim() != null
                        && mapping.getRemoteClaim().getClaimUri() != null) {
                    requestedClaimList.add(mapping.getRemoteClaim().getClaimUri());
                } else if (mapping.getLocalClaim() != null
                        && mapping.getLocalClaim().getClaimUri() != null) {
                    requestedClaimList.add(mapping.getLocalClaim().getClaimUri());
                }
            }
        }
    }

    return requestedClaimList;
}
 
Example 6
Source File: FileBasedApplicationDAO.java    From carbon-identity with Apache License 2.0 5 votes vote down vote up
@Override
public Map<String, String> getLocalIdPToServiceProviderClaimMapping(String serviceProviderName,
                                                                    String tenantDomain) throws IdentityApplicationManagementException {
    ServiceProvider serviceProvider = ApplicationManagementServiceComponent.getFileBasedSPs()
            .get(serviceProviderName);
    Map<String, String> claimMap = new HashMap<String, String>();

    if (serviceProvider == null || serviceProvider.getClaimConfig() == null) {
        return claimMap;
    }

    ClaimMapping[] claimMappings = serviceProvider.getClaimConfig().getClaimMappings();

    if (claimMappings != null && claimMappings.length > 0) {

        for (ClaimMapping mapping : claimMappings) {
            if (mapping.getLocalClaim() != null
                    && mapping.getLocalClaim().getClaimUri() != null
                    && mapping.getRemoteClaim() != null
                    && mapping.getRemoteClaim().getClaimUri() != null) {
                claimMap.put(mapping.getLocalClaim().getClaimUri(), mapping.getRemoteClaim()
                        .getClaimUri());
            }
        }
    }

    return claimMap;
}
 
Example 7
Source File: FileBasedApplicationDAO.java    From carbon-identity with Apache License 2.0 5 votes vote down vote up
@Override
public Map<String, String> getServiceProviderToLocalIdPClaimMapping(String serviceProviderName,
                                                                    String tenantDomain) throws IdentityApplicationManagementException {

    ServiceProvider serviceProvider = ApplicationManagementServiceComponent.getFileBasedSPs()
            .get(serviceProviderName);
    Map<String, String> claimMap = new HashMap<String, String>();

    if (serviceProvider == null || serviceProvider.getClaimConfig() == null) {
        return claimMap;
    }

    ClaimMapping[] claimMappings = serviceProvider.getClaimConfig().getClaimMappings();

    if (claimMappings != null && claimMappings.length > 0) {

        for (ClaimMapping mapping : claimMappings) {
            if (mapping.getLocalClaim() != null
                    && mapping.getLocalClaim().getClaimUri() != null
                    && mapping.getRemoteClaim() != null
                    && mapping.getRemoteClaim().getClaimUri() != null) {
                claimMap.put(mapping.getRemoteClaim().getClaimUri(), mapping.getLocalClaim()
                        .getClaimUri());
            }
        }
    }

    return claimMap;

}
 
Example 8
Source File: ProvisioningUtil.java    From carbon-identity with Apache License 2.0 5 votes vote down vote up
/**
 * @return
 */
public static List<String> getClaimValues(Map<ClaimMapping, List<String>> attributeMap,
                                          String claimUri, String userStoreDomainName) {

    List<String> claimValues = new ArrayList<>();
    for (Map.Entry<ClaimMapping, List<String>> entry : attributeMap.entrySet()) {
        ClaimMapping mapping = entry.getKey();
        if (mapping.getLocalClaim() != null
                && claimUri.equals(mapping.getLocalClaim().getClaimUri())) {
            claimValues = entry.getValue();
            break;
        }
    }

    if (userStoreDomainName != null) {

        List<String> modifiedClaimValues = new ArrayList<>();

        for (Iterator<String> iterator = claimValues.iterator(); iterator.hasNext(); ) {
            String claimValue = iterator.next();
            if (StringUtils.contains(claimValue, "/")) {
                claimValue = claimValue.substring(claimValue.indexOf("/") + 1);
            }

            claimValue = userStoreDomainName + "/" + claimValue;
            modifiedClaimValues.add(claimValue);

        }

        claimValues = modifiedClaimValues;
    }

    return claimValues;
}
 
Example 9
Source File: IdPManagementDAO.java    From carbon-identity-framework with Apache License 2.0 5 votes vote down vote up
/**
 * @param conn
 * @param idPId
 * @param tenantId
 * @param claimMappings
 * @throws SQLException
 * @throws IdentityProviderManagementException
 */
private void addDefaultClaimValuesForLocalIdP(Connection conn, int idPId, int tenantId,
                                              ClaimMapping[] claimMappings) throws SQLException,
        IdentityProviderManagementException {

    PreparedStatement prepStmt = null;
    ResultSet rs = null;
    String sqlStmt;

    try {

        if (claimMappings == null || claimMappings.length == 0) {
            return;
        }

        sqlStmt = IdPManagementConstants.SQLQueries.ADD_LOCAL_IDP_DEFAULT_CLAIM_VALUES_SQL;
        prepStmt = conn.prepareStatement(sqlStmt);
        for (ClaimMapping mapping : claimMappings) {
            if (mapping != null && mapping.getLocalClaim() != null
                    && mapping.getLocalClaim().getClaimUri() != null) {

                prepStmt.setInt(1, idPId);
                prepStmt.setString(2, mapping.getLocalClaim().getClaimUri());
                prepStmt.setString(3, mapping.getDefaultValue());
                prepStmt.setInt(4, tenantId);
                if (mapping.isRequested()) {
                    prepStmt.setString(5, IdPManagementConstants.IS_TRUE_VALUE);
                } else {
                    prepStmt.setString(5, IdPManagementConstants.IS_FALSE_VALUE);
                }
                prepStmt.addBatch();
            }
        }

        prepStmt.executeBatch();

    } finally {
        IdentityDatabaseUtil.closeAllConnections(null, rs, prepStmt);
    }
}
 
Example 10
Source File: FileBasedApplicationDAO.java    From carbon-identity-framework with Apache License 2.0 5 votes vote down vote up
@Override
public List<String> getAllRequestedClaimsByServiceProvider(String serviceProviderName,
                                                           String tenantDomain)
        throws IdentityApplicationManagementException {

    ServiceProvider serviceProvider = ApplicationManagementServiceComponent.getFileBasedSPs()
            .get(serviceProviderName);

    List<String> requestedClaimList = new ArrayList<String>();

    if (serviceProvider == null || serviceProvider.getClaimConfig() == null) {
        return requestedClaimList;
    }

    ClaimMapping[] claimMappings = serviceProvider.getClaimConfig().getClaimMappings();

    if (claimMappings != null && claimMappings.length > 0) {

        for (ClaimMapping mapping : claimMappings) {
            if (mapping.isRequested()) {
                if (mapping.getRemoteClaim() != null
                        && mapping.getRemoteClaim().getClaimUri() != null) {
                    requestedClaimList.add(mapping.getRemoteClaim().getClaimUri());
                } else if (mapping.getLocalClaim() != null
                        && mapping.getLocalClaim().getClaimUri() != null) {
                    requestedClaimList.add(mapping.getLocalClaim().getClaimUri());
                }
            }
        }
    }

    return requestedClaimList;
}
 
Example 11
Source File: FileBasedApplicationDAO.java    From carbon-identity-framework with Apache License 2.0 5 votes vote down vote up
@Override
public Map<String, String> getLocalIdPToServiceProviderClaimMapping(String serviceProviderName,
                                                                    String tenantDomain)
        throws IdentityApplicationManagementException {

    ServiceProvider serviceProvider = ApplicationManagementServiceComponent.getFileBasedSPs()
            .get(serviceProviderName);
    Map<String, String> claimMap = new HashMap<String, String>();

    if (serviceProvider == null || serviceProvider.getClaimConfig() == null) {
        return claimMap;
    }

    ClaimMapping[] claimMappings = serviceProvider.getClaimConfig().getClaimMappings();

    if (claimMappings != null && claimMappings.length > 0) {

        for (ClaimMapping mapping : claimMappings) {
            if (mapping.getLocalClaim() != null
                    && mapping.getLocalClaim().getClaimUri() != null
                    && mapping.getRemoteClaim() != null
                    && mapping.getRemoteClaim().getClaimUri() != null) {
                claimMap.put(mapping.getLocalClaim().getClaimUri(), mapping.getRemoteClaim()
                        .getClaimUri());
            }
        }
    }

    return claimMap;
}
 
Example 12
Source File: FileBasedApplicationDAO.java    From carbon-identity-framework with Apache License 2.0 5 votes vote down vote up
@Override
public Map<String, String> getServiceProviderToLocalIdPClaimMapping(String serviceProviderName,
                                                                    String tenantDomain)
        throws IdentityApplicationManagementException {

    ServiceProvider serviceProvider = ApplicationManagementServiceComponent.getFileBasedSPs()
            .get(serviceProviderName);
    Map<String, String> claimMap = new HashMap<String, String>();

    if (serviceProvider == null || serviceProvider.getClaimConfig() == null) {
        return claimMap;
    }

    ClaimMapping[] claimMappings = serviceProvider.getClaimConfig().getClaimMappings();

    if (claimMappings != null && claimMappings.length > 0) {

        for (ClaimMapping mapping : claimMappings) {
            if (mapping.getLocalClaim() != null
                    && mapping.getLocalClaim().getClaimUri() != null
                    && mapping.getRemoteClaim() != null
                    && mapping.getRemoteClaim().getClaimUri() != null) {
                claimMap.put(mapping.getRemoteClaim().getClaimUri(), mapping.getLocalClaim()
                        .getClaimUri());
            }
        }
    }

    return claimMap;

}
 
Example 13
Source File: ProvisioningUtil.java    From carbon-identity-framework with Apache License 2.0 5 votes vote down vote up
/**
 * @return
 */
public static List<String> getClaimValues(Map<ClaimMapping, List<String>> attributeMap,
                                          String claimUri, String userStoreDomainName) {

    List<String> claimValues = new ArrayList<>();
    for (Map.Entry<ClaimMapping, List<String>> entry : attributeMap.entrySet()) {
        ClaimMapping mapping = entry.getKey();
        if (mapping.getLocalClaim() != null
                && claimUri.equals(mapping.getLocalClaim().getClaimUri())) {
            claimValues = entry.getValue();
            break;
        }
    }

    if (userStoreDomainName != null) {

        List<String> modifiedClaimValues = new ArrayList<>();

        for (Iterator<String> iterator = claimValues.iterator(); iterator.hasNext(); ) {
            String claimValue = iterator.next();
            if (StringUtils.contains(claimValue, "/")) {
                claimValue = claimValue.substring(claimValue.indexOf("/") + 1);
            }

            claimValue = userStoreDomainName + "/" + claimValue;
            modifiedClaimValues.add(claimValue);

        }

        claimValues = modifiedClaimValues;
    }

    return claimValues;
}
 
Example 14
Source File: ApplicationConfig.java    From carbon-identity-framework with Apache License 2.0 4 votes vote down vote up
public ApplicationConfig(ServiceProvider application) {
    this.serviceProvider = application;
    applicationID = application.getApplicationID();
    applicationName = application.getApplicationName();
    isSaaSApp = application.isSaasApp();
    LocalAndOutboundAuthenticationConfig outboundAuthConfig = application.getLocalAndOutBoundAuthenticationConfig();

    if (outboundAuthConfig != null) {
        subjectClaimUri = outboundAuthConfig.getSubjectClaimUri();
        setUseTenantDomainInLocalSubjectIdentifier(outboundAuthConfig.isUseTenantDomainInLocalSubjectIdentifier());
        setUseUserstoreDomainInLocalSubjectIdentifier(outboundAuthConfig
                .isUseUserstoreDomainInLocalSubjectIdentifier());
        setEnableAuthorization(outboundAuthConfig.isEnableAuthorization());
        setUseUserstoreDomainInRole(outboundAuthConfig.isUseUserstoreDomainInRoles());
    }


    ClaimConfig claimConfig = application.getClaimConfig();
    if (claimConfig != null) {
        roleClaim = claimConfig.getRoleClaimURI();
        alwaysSendMappedLocalSubjectId = claimConfig.isAlwaysSendMappedLocalSubjectId();

        List<ClaimMapping> spClaimMappings = new ArrayList<>(Arrays.asList(claimConfig.getClaimMappings()));
        setSpDialectClaims(claimConfig, spClaimMappings);
        if (CollectionUtils.isNotEmpty(spClaimMappings)) {
            for (ClaimMapping claim : spClaimMappings) {
                if (claim.getRemoteClaim() != null
                    && claim.getRemoteClaim().getClaimUri() != null) {
                    if (claim.getLocalClaim() != null) {
                        claimMappings.put(claim.getRemoteClaim().getClaimUri(), claim
                                .getLocalClaim().getClaimUri());

                        if (claim.isRequested()) {
                            requestedClaims.put(claim.getRemoteClaim().getClaimUri(), claim
                                    .getLocalClaim().getClaimUri());
                        }

                        if (claim.isMandatory()) {
                            mandatoryClaims.put(claim.getRemoteClaim().getClaimUri(), claim
                                    .getLocalClaim().getClaimUri());
                        }

                    } else {
                        claimMappings.put(claim.getRemoteClaim().getClaimUri(), null);
                        if (claim.isRequested()) {
                            requestedClaims.put(claim.getRemoteClaim().getClaimUri(), null);
                        }

                        if (claim.isMandatory()) {
                            mandatoryClaims.put(claim.getRemoteClaim().getClaimUri(), null);
                        }
                    }
                }

            }
        }
    }

    PermissionsAndRoleConfig permissionRoleConfiguration;
    permissionRoleConfiguration = application.getPermissionAndRoleConfig();

    if (permissionRoleConfiguration != null) {
        ApplicationPermission[] permissionList = permissionRoleConfiguration.getPermissions();
        if (permissionList == null) {
            permissionList = new ApplicationPermission[0];
        }

        permissions = new String[permissionList.length];

        for (int i = 0; i < permissionList.length; i++) {
            ApplicationPermission permission = permissionList[i];
            permissions[i] = permission.getValue();
        }

        RoleMapping[] tempRoleMappings = permissionRoleConfiguration.getRoleMappings();

        if (tempRoleMappings != null && tempRoleMappings.length > 0) {
            for (RoleMapping roleMapping : tempRoleMappings) {
                this.roleMappings.put(roleMapping.getLocalRole().getLocalRoleName(),
                                      roleMapping.getRemoteRole());
            }
        }
    }
}
 
Example 15
Source File: ApplicationConfig.java    From carbon-identity with Apache License 2.0 4 votes vote down vote up
public ApplicationConfig(ServiceProvider application) {
    this.serviceProvider = application;
    applicationID = application.getApplicationID();
    applicationName = application.getApplicationName();
    isSaaSApp = application.isSaasApp();
    LocalAndOutboundAuthenticationConfig outboundAuthConfig = application.getLocalAndOutBoundAuthenticationConfig();

    if (outboundAuthConfig != null) {
        subjectClaimUri = outboundAuthConfig.getSubjectClaimUri();
        setUseTenantDomainInLocalSubjectIdentifier(outboundAuthConfig.isUseTenantDomainInLocalSubjectIdentifier());
        setUseUserstoreDomainInLocalSubjectIdentifier(outboundAuthConfig
                .isUseUserstoreDomainInLocalSubjectIdentifier());
    }


    ClaimConfig claimConfig = application.getClaimConfig();
    if (claimConfig != null) {
        roleClaim = claimConfig.getRoleClaimURI();
        alwaysSendMappedLocalSubjectId = claimConfig.isAlwaysSendMappedLocalSubjectId();

        ClaimMapping[] claimMapping = claimConfig.getClaimMappings();

        requestedClaims = new HashMap<String, String>();

        if (claimMapping != null && claimMapping.length > 0) {
            claimMappings = new HashMap<String, String>();
            for (ClaimMapping claim : claimMapping) {
                if (claim.getRemoteClaim() != null
                    && claim.getRemoteClaim().getClaimUri() != null) {
                    if (claim.getLocalClaim() != null) {
                        claimMappings.put(claim.getRemoteClaim().getClaimUri(), claim
                                .getLocalClaim().getClaimUri());

                        if (claim.isRequested()) {
                            requestedClaims.put(claim.getRemoteClaim().getClaimUri(), claim
                                    .getLocalClaim().getClaimUri());
                        }

                    } else {
                        claimMappings.put(claim.getRemoteClaim().getClaimUri(), null);
                        if (claim.isRequested()) {
                            requestedClaims.put(claim.getRemoteClaim().getClaimUri(), null);
                        }
                    }
                }

            }
        }
    }

    PermissionsAndRoleConfig permissionRoleConfiguration;
    permissionRoleConfiguration = application.getPermissionAndRoleConfig();

    if (permissionRoleConfiguration != null) {
        ApplicationPermission[] permissionList = permissionRoleConfiguration.getPermissions();
        if (permissionList == null) {
            permissionList = new ApplicationPermission[0];
        }

        permissions = new String[permissionList.length];

        for (int i = 0; i < permissionList.length; i++) {
            ApplicationPermission permission = permissionList[i];
            permissions[i] = permission.getValue();
        }

        RoleMapping[] tempRoleMappings = permissionRoleConfiguration.getRoleMappings();

        if (tempRoleMappings != null && tempRoleMappings.length > 0) {
            this.roleMappings = new HashMap<String, String>();
            for (RoleMapping roleMapping : tempRoleMappings) {
                this.roleMappings.put(roleMapping.getLocalRole().getLocalRoleName(),
                                      roleMapping.getRemoteRole());
            }
        }
    }
}
 
Example 16
Source File: ProvisioningUtil.java    From carbon-identity with Apache License 2.0 4 votes vote down vote up
public static Map<ClaimMapping, List<String>> getMappedClaims(String outboundClaimDialect,
                                                              Map<String, String> inboundClaimValueMap, ClaimMapping[] inboundClaimMappings,
                                                              Map<ClaimMapping, List<String>> outboundClaimValueMappings, String tenantDomain)
        throws IdentityApplicationManagementException {

    try {

        // we do have in-bound claim mapping - but no out-bound claim mapping - no out-bound
        // default values.since we do not know the out-bound claim mapping - whatever in the
        // in-bound claims will be mapped into the out-bound claim dialect.

        if (MapUtils.isEmpty(inboundClaimValueMap)) {
            // we do not have out-bound claim mapping - and a default values to worry about.
            // just return what we got.
            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> outBoundToCarbonClaimMapppings = null;

        // we only know the dialect - it is a standard claim dialect.
        // this returns back a map - having carbon claim dialect as the key.
        // null argument is passed - because we do not know the required attributes for
        // out-bound provisioning. This will find carbon claim mappings for the entire out-bound
        // claim dialect.
        outBoundToCarbonClaimMapppings = ClaimManagerHandler.getInstance()
                .getMappingsMapFromOtherDialectToCarbon(outboundClaimDialect, null,
                        tenantDomain, true);

        if (outBoundToCarbonClaimMapppings == null) {
            // we did not find any carbon claim mappings corresponding to the out-bound claim
            // dialect - we cannot map the in-bound claim dialect to out-bound claim dialect.
            // just return what we got.
            return outboundClaimValueMappings;
        }

        // {in-bound-claim-uri / out-bound-claim-uri
        claimMap = new HashMap<String, String>();

        for (ClaimMapping inboundClaimMapping : inboundClaimMappings) {
            // there can be a claim mapping without a mapped local claim.
            // if that is the case - we cannot map it to an out-bound claim.
            if (inboundClaimMapping.getLocalClaim() == null
                    || inboundClaimMapping.getLocalClaim().getClaimUri() == null) {
                if (log.isDebugEnabled()) {
                    log.debug("Inbound claim - local claim is null");
                }
                continue;
            }

            // get the out-bound claim corresponding to the carbon dialect - which is the key.
            String outboundClaim = outBoundToCarbonClaimMapppings.get(inboundClaimMapping
                    .getLocalClaim().getClaimUri());

            if (outboundClaim != null) {
                // in-bound claim uri / out-bound claim uri.
                if (inboundClaimMapping.getRemoteClaim() != null
                        && inboundClaimMapping.getRemoteClaim().getClaimUri() != null) {
                    claimMap.put(inboundClaimMapping.getRemoteClaim().getClaimUri(),
                            outboundClaim);
                }
            }
        }

        if (claimMap.isEmpty()) {
            // we do not have a claim map.
            // return what we got.
            return outboundClaimValueMappings;
        }

        for (Iterator<Map.Entry<String, String>> iterator = claimMap.entrySet().iterator(); iterator
                .hasNext(); ) {
            Map.Entry<String, String> entry = iterator.next();

            String inboundClaimUri = entry.getKey();
            String outboundClaimUri = entry.getValue();
            String claimValue = null;

            if (outboundClaimUri != null) {
                claimValue = inboundClaimValueMap.get(inboundClaimUri);
            }
            // null value goes there because we do not have an out-bound claim mapping - and
            // also default values.
            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;
}
 
Example 17
Source File: ProvisioningUtil.java    From carbon-identity with Apache License 2.0 4 votes vote down vote up
public static Map<ClaimMapping, List<String>> getMappedClaims(
        ClaimMapping[] outboundClaimMappings, Map<String, String> inboundClaimValueMap,
        String inboundClaimMappingDialect,
        Map<ClaimMapping, List<String>> outboundClaimValueMappings, String tenantDomain)
        throws IdentityApplicationManagementException {

    // we know the out-bound claim mapping - and the in-bound claim dialect.

    try {

        if (MapUtils.isEmpty(inboundClaimValueMap)) {
            // we do not have any values in the incoming provisioning request.
            // we need to populate outboundClaimValueMappings map with the default values from
            // 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 = ClaimManagerHandler.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;
}
 
Example 18
Source File: ProvisioningUtil.java    From carbon-identity-framework with Apache License 2.0 4 votes vote down vote up
public static Map<ClaimMapping, List<String>> getMappedClaims(
        ClaimMapping[] outboundClaimMappings, Map<String, String> inboundClaimValueMap,
        String inboundClaimMappingDialect,
        Map<ClaimMapping, List<String>> outboundClaimValueMappings, String tenantDomain)
        throws IdentityApplicationManagementException {

    // we know the out-bound claim mapping - and the in-bound claim dialect.

    try {

        if (MapUtils.isEmpty(inboundClaimValueMap)) {
            // we do not have any values in the incoming provisioning request.
            // we need to populate outboundClaimValueMappings map with the default values from
            // 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;
}
 
Example 19
Source File: ProvisioningUtil.java    From carbon-identity-framework with Apache License 2.0 4 votes vote down vote up
public static Map<ClaimMapping, List<String>> getMappedClaims(String outboundClaimDialect,
                                                              Map<String, String> inboundClaimValueMap, ClaimMapping[] inboundClaimMappings,
                                                              Map<ClaimMapping, List<String>> outboundClaimValueMappings, String tenantDomain)
        throws IdentityApplicationManagementException {

    try {

        // we do have in-bound claim mapping - but no out-bound claim mapping - no out-bound
        // default values.since we do not know the out-bound claim mapping - whatever in the
        // in-bound claims will be mapped into the out-bound claim dialect.

        if (MapUtils.isEmpty(inboundClaimValueMap)) {
            // we do not have out-bound claim mapping - and a default values to worry about.
            // just return what we got.
            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> outBoundToCarbonClaimMapppings = null;

        // we only know the dialect - it is a standard claim dialect.
        // this returns back a map - having carbon claim dialect as the key.
        // null argument is passed - because we do not know the required attributes for
        // out-bound provisioning. This will find carbon claim mappings for the entire out-bound
        // claim dialect.
        outBoundToCarbonClaimMapppings = ClaimMetadataHandler.getInstance()
                .getMappingsMapFromOtherDialectToCarbon(outboundClaimDialect, null,
                        tenantDomain, true);

        if (outBoundToCarbonClaimMapppings == null) {
            // we did not find any carbon claim mappings corresponding to the out-bound claim
            // dialect - we cannot map the in-bound claim dialect to out-bound claim dialect.
            // just return what we got.
            return outboundClaimValueMappings;
        }

        // {in-bound-claim-uri / out-bound-claim-uri
        claimMap = new HashMap<String, String>();

        for (ClaimMapping inboundClaimMapping : inboundClaimMappings) {
            // there can be a claim mapping without a mapped local claim.
            // if that is the case - we cannot map it to an out-bound claim.
            if (inboundClaimMapping.getLocalClaim() == null
                    || inboundClaimMapping.getLocalClaim().getClaimUri() == null) {
                if (log.isDebugEnabled()) {
                    log.debug("Inbound claim - local claim is null");
                }
                continue;
            }

            // get the out-bound claim corresponding to the carbon dialect - which is the key.
            String outboundClaim = outBoundToCarbonClaimMapppings.get(inboundClaimMapping
                    .getLocalClaim().getClaimUri());

            if (outboundClaim != null) {
                // in-bound claim uri / out-bound claim uri.
                if (inboundClaimMapping.getRemoteClaim() != null
                        && inboundClaimMapping.getRemoteClaim().getClaimUri() != null) {
                    claimMap.put(inboundClaimMapping.getRemoteClaim().getClaimUri(),
                            outboundClaim);
                }
            }
        }

        if (claimMap.isEmpty()) {
            // we do not have a claim map.
            // return what we got.
            return outboundClaimValueMappings;
        }

        for (Iterator<Map.Entry<String, String>> iterator = claimMap.entrySet().iterator(); iterator
                .hasNext(); ) {
            Map.Entry<String, String> entry = iterator.next();

            String inboundClaimUri = entry.getKey();
            String outboundClaimUri = entry.getValue();
            String claimValue = null;

            if (outboundClaimUri != null) {
                claimValue = inboundClaimValueMap.get(inboundClaimUri);
            }
            // null value goes there because we do not have an out-bound claim mapping - and
            // also default values.
            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;
}