Java Code Examples for org.wso2.carbon.identity.application.common.model.ClaimMapping#getRemoteClaim()
The following examples show how to use
org.wso2.carbon.identity.application.common.model.ClaimMapping#getRemoteClaim() .
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: FrameworkUtils.java From carbon-identity-framework with Apache License 2.0 | 6 votes |
/** * To get the role claim uri of an IDP. * * @param externalIdPConfig Relevant external IDP Config. * @return idp role claim URI. */ public static String getIdpRoleClaimUri(ExternalIdPConfig externalIdPConfig) { // get external identity provider role claim uri. String idpRoleClaimUri = externalIdPConfig.getRoleClaimUri(); if (idpRoleClaimUri == null || idpRoleClaimUri.isEmpty()) { // no role claim uri defined // we can still try to find it out - lets have a look at the claim // mapping. ClaimMapping[] idpToLocalClaimMapping = externalIdPConfig.getClaimMappings(); if (idpToLocalClaimMapping != null && idpToLocalClaimMapping.length > 0) { for (ClaimMapping mapping : idpToLocalClaimMapping) { if (FrameworkConstants.LOCAL_ROLE_CLAIM_URI.equals(mapping.getLocalClaim().getClaimUri()) && mapping.getRemoteClaim() != null) { return mapping.getRemoteClaim().getClaimUri(); } } } } return idpRoleClaimUri; }
Example 2
Source File: FrameworkUtils.java From carbon-identity-framework with Apache License 2.0 | 6 votes |
/** * Returns the local claim uri that is mapped for the IdP role claim uri configured. * If no role claim uri is configured for the IdP returns the local role claim 'http://wso2.org/claims/role'. * * @param externalIdPConfig IdP configurations * @return local claim uri mapped for the IdP role claim uri. */ public static String getLocalClaimUriMappedForIdPRoleClaim(ExternalIdPConfig externalIdPConfig) { // get external identity provider role claim uri. String idpRoleClaimUri = externalIdPConfig.getRoleClaimUri(); if (StringUtils.isNotBlank(idpRoleClaimUri)) { // Iterate over IdP claim mappings and check for the local claim that is mapped for the remote IdP role // claim uri configured. ClaimMapping[] idpToLocalClaimMapping = externalIdPConfig.getClaimMappings(); if (!ArrayUtils.isEmpty(idpToLocalClaimMapping)) { for (ClaimMapping mapping : idpToLocalClaimMapping) { if (mapping.getRemoteClaim() != null && idpRoleClaimUri .equals(mapping.getRemoteClaim().getClaimUri())) { return mapping.getLocalClaim().getClaimUri(); } } } } return FrameworkConstants.LOCAL_ROLE_CLAIM_URI; }
Example 3
Source File: AbstractOutboundProvisioningConnector.java From carbon-identity-framework with Apache License 2.0 | 6 votes |
/** * @param attributeMap * @return claimValues */ protected Map<String, String> getSingleValuedClaims(Map<ClaimMapping, List<String>> attributeMap) { Map<String, String> claimValues = new HashMap<>(); for (Map.Entry<ClaimMapping, List<String>> entry : attributeMap.entrySet()) { ClaimMapping mapping = entry.getKey(); if (mapping.getRemoteClaim() != null && mapping.getRemoteClaim().getClaimUri() != null) { String claimUri = mapping.getRemoteClaim().getClaimUri(); if (!(IdentityProvisioningConstants.GROUP_CLAIM_URI.equals(claimUri) || IdentityProvisioningConstants.PASSWORD_CLAIM_URI.equals(claimUri) || IdentityProvisioningConstants.USERNAME_CLAIM_URI .equals(claimUri))) { if (CollectionUtils.isNotEmpty(entry.getValue()) && entry.getValue().get(0) != null) { claimValues.put(claimUri, entry.getValue().get(0)); } else { claimValues.put(claimUri, mapping.getDefaultValue()); } } } } return claimValues; }
Example 4
Source File: DefaultStepBasedSequenceHandler.java From carbon-identity with Apache License 2.0 | 6 votes |
/** * @param externalIdPConfig * @return */ protected String getIdpRoleClaimUri(ExternalIdPConfig externalIdPConfig) throws FrameworkException { // get external identity provider role claim uri. String idpRoleClaimUri = externalIdPConfig.getRoleClaimUri(); if (idpRoleClaimUri == null || idpRoleClaimUri.isEmpty()) { // no role claim uri defined // we can still try to find it out - lets have a look at the claim // mapping. ClaimMapping[] idpToLocalClaimMapping = externalIdPConfig.getClaimMappings(); if (idpToLocalClaimMapping != null && idpToLocalClaimMapping.length > 0) { for (ClaimMapping mapping : idpToLocalClaimMapping) { if (FrameworkConstants.LOCAL_ROLE_CLAIM_URI.equals( mapping.getLocalClaim().getClaimUri()) && mapping.getRemoteClaim() != null) { return mapping.getRemoteClaim().getClaimUri(); } } } } return idpRoleClaimUri; }
Example 5
Source File: AbstractOutboundProvisioningConnector.java From carbon-identity with Apache License 2.0 | 6 votes |
/** * @param attributeMap * @return claimValues */ protected Map<String, String> getSingleValuedClaims(Map<ClaimMapping, List<String>> attributeMap) { Map<String, String> claimValues = new HashMap<>(); for (Map.Entry<ClaimMapping, List<String>> entry : attributeMap.entrySet()) { ClaimMapping mapping = entry.getKey(); if (mapping.getRemoteClaim() != null && mapping.getRemoteClaim().getClaimUri() != null) { String claimUri = mapping.getRemoteClaim().getClaimUri(); if (!(IdentityProvisioningConstants.GROUP_CLAIM_URI.equals(claimUri) || IdentityProvisioningConstants.PASSWORD_CLAIM_URI.equals(claimUri) || IdentityProvisioningConstants.USERNAME_CLAIM_URI .equals(claimUri))) { if (entry.getValue() != null && entry.getValue().get(0) != null) { claimValues.put(claimUri, entry.getValue().get(0)); } else { claimValues.put(claimUri, mapping.getDefaultValue()); } } } } return claimValues; }
Example 6
Source File: FileBasedApplicationDAO.java From carbon-identity-framework with Apache License 2.0 | 5 votes |
@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 7
Source File: FileBasedApplicationDAO.java From carbon-identity-framework with Apache License 2.0 | 5 votes |
@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 8
Source File: FileBasedApplicationDAO.java From carbon-identity-framework with Apache License 2.0 | 5 votes |
@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 9
Source File: FileBasedApplicationDAO.java From carbon-identity with Apache License 2.0 | 5 votes |
@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 10
Source File: FileBasedApplicationDAO.java From carbon-identity with Apache License 2.0 | 5 votes |
@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 11
Source File: FileBasedApplicationDAO.java From carbon-identity with Apache License 2.0 | 5 votes |
@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 12
Source File: IdPManagementDAO.java From carbon-identity with Apache License 2.0 | 4 votes |
/** * @param conn * @param idPId * @param tenantId * @param claimMappings * @throws SQLException * @throws IdentityProviderManagementException */ private void addIdPClaimMappings(Connection conn, int idPId, int tenantId, ClaimMapping[] claimMappings) throws SQLException, IdentityProviderManagementException { Map<String, Integer> claimIdMap = new HashMap<String, Integer>(); PreparedStatement prepStmt = null; ResultSet rs = null; try { if (claimMappings == null || claimMappings.length == 0) { return; } String sqlStmt = IdPManagementConstants.SQLQueries.GET_IDP_CLAIMS_SQL; prepStmt = conn.prepareStatement(sqlStmt); prepStmt.setInt(1, idPId); rs = prepStmt.executeQuery(); while (rs.next()) { int id = rs.getInt("ID"); String claim = rs.getString("CLAIM"); claimIdMap.put(claim, id); } prepStmt.clearParameters(); if (claimIdMap.isEmpty()) { String message = "No Identity Provider claim URIs defined for tenant " + tenantId; throw new IdentityProviderManagementException(message); } sqlStmt = IdPManagementConstants.SQLQueries.ADD_IDP_CLAIM_MAPPINGS_SQL; prepStmt = conn.prepareStatement(sqlStmt); for (ClaimMapping mapping : claimMappings) { if (mapping != null && mapping.getRemoteClaim() != null && claimIdMap.containsKey(mapping.getRemoteClaim().getClaimUri())) { int idpClaimId = claimIdMap.get(mapping.getRemoteClaim().getClaimUri()); String localClaimURI = mapping.getLocalClaim().getClaimUri(); prepStmt.setInt(1, idpClaimId); prepStmt.setInt(2, tenantId); prepStmt.setString(3, localClaimURI); prepStmt.setString(4, mapping.getDefaultValue()); if (mapping.isRequested()) { prepStmt.setString(5, IdPManagementConstants.IS_TRUE_VALUE); } else { prepStmt.setString(5, IdPManagementConstants.IS_FALSE_VALUE); } prepStmt.addBatch(); } else { throw new IdentityProviderManagementException("Cannot find Identity Provider claim mapping for tenant " + tenantId); } } prepStmt.executeBatch(); } finally { IdentityDatabaseUtil.closeAllConnections(null, rs, prepStmt); } }
Example 13
Source File: ApplicationConfig.java From carbon-identity-framework with Apache License 2.0 | 4 votes |
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 14
Source File: ProvisioningUtil.java From carbon-identity with Apache License 2.0 | 4 votes |
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 15
Source File: ApplicationConfig.java From carbon-identity with Apache License 2.0 | 4 votes |
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: IdPManagementDAO.java From carbon-identity-framework with Apache License 2.0 | 4 votes |
/** * @param conn * @param idPId * @param tenantId * @param claimMappings * @throws SQLException * @throws IdentityProviderManagementException */ private void addIdPClaimMappings(Connection conn, int idPId, int tenantId, ClaimMapping[] claimMappings) throws SQLException, IdentityProviderManagementException { Map<String, Integer> claimIdMap = new HashMap<String, Integer>(); PreparedStatement prepStmt = null; ResultSet rs = null; try { if (claimMappings == null || claimMappings.length == 0) { return; } String sqlStmt = IdPManagementConstants.SQLQueries.GET_IDP_CLAIMS_SQL; prepStmt = conn.prepareStatement(sqlStmt); prepStmt.setInt(1, idPId); rs = prepStmt.executeQuery(); while (rs.next()) { int id = rs.getInt("ID"); String claim = rs.getString("CLAIM"); claimIdMap.put(claim, id); } prepStmt.clearParameters(); if (claimIdMap.isEmpty()) { String message = "No Identity Provider claim URIs defined for tenant " + tenantId; throw new IdentityProviderManagementException(message); } sqlStmt = IdPManagementConstants.SQLQueries.ADD_IDP_CLAIM_MAPPINGS_SQL; prepStmt = conn.prepareStatement(sqlStmt); for (ClaimMapping mapping : claimMappings) { if (mapping != null && mapping.getRemoteClaim() != null && claimIdMap.containsKey(mapping.getRemoteClaim().getClaimUri())) { int idpClaimId = claimIdMap.get(mapping.getRemoteClaim().getClaimUri()); String localClaimURI = mapping.getLocalClaim().getClaimUri(); prepStmt.setInt(1, idpClaimId); prepStmt.setInt(2, tenantId); prepStmt.setString(3, localClaimURI); prepStmt.setString(4, mapping.getDefaultValue()); if (mapping.isRequested()) { prepStmt.setString(5, IdPManagementConstants.IS_TRUE_VALUE); } else { prepStmt.setString(5, IdPManagementConstants.IS_FALSE_VALUE); } prepStmt.addBatch(); } else { throw new IdentityProviderManagementException("Cannot find Identity Provider claim mapping for " + "tenant " + tenantId); } } prepStmt.executeBatch(); } finally { IdentityDatabaseUtil.closeAllConnections(null, rs, prepStmt); } }
Example 17
Source File: ProvisioningUtil.java From carbon-identity-framework with Apache License 2.0 | 4 votes |
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; }