Java Code Examples for org.wso2.carbon.identity.application.common.model.ClaimMapping#setRemoteClaim()
The following examples show how to use
org.wso2.carbon.identity.application.common.model.ClaimMapping#setRemoteClaim() .
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: OAuth2AuthzEndpoint.java From carbon-identity with Apache License 2.0 | 6 votes |
private void addUserAttributesToCache(SessionDataCacheEntry sessionDataCacheEntry, String code, String codeId) { AuthorizationGrantCacheKey authorizationGrantCacheKey = new AuthorizationGrantCacheKey(code); AuthorizationGrantCacheEntry authorizationGrantCacheEntry = new AuthorizationGrantCacheEntry( sessionDataCacheEntry.getLoggedInUser().getUserAttributes()); String sub = sessionDataCacheEntry.getLoggedInUser().getUserAttributes().get("sub"); if(StringUtils.isBlank(sub)){ sub = sessionDataCacheEntry.getLoggedInUser().getAuthenticatedSubjectIdentifier(); } if(StringUtils.isNotBlank(sub)){ ClaimMapping claimMapping = new ClaimMapping(); Claim claim = new Claim(); claim.setClaimUri("sub"); claimMapping.setRemoteClaim(claim); sessionDataCacheEntry.getLoggedInUser().getUserAttributes().put(claimMapping, sub); } authorizationGrantCacheEntry.setNonceValue(sessionDataCacheEntry.getoAuth2Parameters().getNonce()); authorizationGrantCacheEntry.setCodeId(codeId); AuthorizationGrantCache.getInstance().addToCacheByCode(authorizationGrantCacheKey, authorizationGrantCacheEntry); }
Example 2
Source File: FrameworkUtils.java From carbon-identity-framework with Apache License 2.0 | 5 votes |
public static String getFederatedSubjectFromClaims(IdentityProvider identityProvider, Map<ClaimMapping, String> claimMappings) { String userIdClaimURI = identityProvider.getClaimConfig().getUserClaimURI(); ClaimMapping claimMapping = new ClaimMapping(); Claim claim = new Claim(); claim.setClaimUri(userIdClaimURI); claimMapping.setRemoteClaim(claim); claimMapping.setLocalClaim(claim); return claimMappings.get(claimMapping); }
Example 3
Source File: FrameworkUtils.java From carbon-identity-framework with Apache License 2.0 | 5 votes |
public static String getFederatedSubjectFromClaims(AuthenticationContext context, String otherDialect) throws FrameworkException { String value; boolean useLocalClaimDialect = context.getExternalIdP().useDefaultLocalIdpDialect(); String userIdClaimURI = context.getExternalIdP().getUserIdClaimUri(); Map<ClaimMapping, String> claimMappings = context.getSubject().getUserAttributes(); if (useLocalClaimDialect) { Map<String, String> extAttributesValueMap = FrameworkUtils.getClaimMappings(claimMappings, false); Map<String, String> mappedAttrs = null; try { mappedAttrs = ClaimMetadataHandler.getInstance().getMappingsMapFromOtherDialectToCarbon(otherDialect, extAttributesValueMap.keySet(), context.getTenantDomain(), true); } catch (ClaimMetadataException e) { throw new FrameworkException("Error while loading claim mappings.", e); } String spUserIdClaimURI = mappedAttrs.get(userIdClaimURI); value = extAttributesValueMap.get(spUserIdClaimURI); } else { ClaimMapping claimMapping = new ClaimMapping(); Claim claim = new Claim(); claim.setClaimUri(userIdClaimURI); claimMapping.setRemoteClaim(claim); claimMapping.setLocalClaim(claim); value = claimMappings.get(claimMapping); } return value; }
Example 4
Source File: FrameworkUtils.java From carbon-identity with Apache License 2.0 | 5 votes |
public static String getFederatedSubjectFromClaims(IdentityProvider identityProvider, Map<ClaimMapping, String> claimMappings) { String userIdClaimURI = identityProvider.getClaimConfig().getUserClaimURI(); ClaimMapping claimMapping = new ClaimMapping(); Claim claim = new Claim(); claim.setClaimUri(userIdClaimURI); claimMapping.setRemoteClaim(claim); claimMapping.setLocalClaim(claim); return claimMappings.get(claimMapping); }
Example 5
Source File: FrameworkUtils.java From carbon-identity with Apache License 2.0 | 5 votes |
public static String getFederatedSubjectFromClaims(AuthenticationContext context, String otherDialect) throws FrameworkException { String value; boolean useLocalClaimDialect = context.getExternalIdP().useDefaultLocalIdpDialect(); String userIdClaimURI = context.getExternalIdP().getUserIdClaimUri(); Map<ClaimMapping, String> claimMappings = context.getSubject().getUserAttributes(); if (useLocalClaimDialect) { Map<String, String> extAttributesValueMap = FrameworkUtils.getClaimMappings(claimMappings, false); Map<String, String> mappedAttrs = null; try { mappedAttrs = ClaimManagerHandler.getInstance().getMappingsMapFromOtherDialectToCarbon(otherDialect, extAttributesValueMap.keySet(), context.getTenantDomain(), true); } catch (ClaimManagementException e) { throw new FrameworkException("Error while loading claim mappings.", e); } String spUserIdClaimURI = mappedAttrs.get(userIdClaimURI); value = extAttributesValueMap.get(spUserIdClaimURI); } else { ClaimMapping claimMapping = new ClaimMapping(); Claim claim = new Claim(); claim.setClaimUri(userIdClaimURI); claimMapping.setRemoteClaim(claim); value = claimMappings.get(claimMapping); } return value; }
Example 6
Source File: PassiveSTSManager.java From carbon-identity with Apache License 2.0 | 5 votes |
private Map<ClaimMapping, String> getClaimMappingsMap(Map<String, String> userAttributes) { Map<ClaimMapping, String> results = new HashMap<ClaimMapping, String>(); for (Map.Entry<String, String> entry : userAttributes.entrySet()) { ClaimMapping claimMapping = new ClaimMapping(); Claim claim = new Claim(); claim.setClaimUri(entry.getKey()); claimMapping.setRemoteClaim(claim); results.put(claimMapping, entry.getValue()); } return results; }
Example 7
Source File: AbstractOutboundProvisioningConnectorTest.java From carbon-identity-framework with Apache License 2.0 | 4 votes |
@BeforeMethod public void setUp() { initMocks(this); connector = new AbstractOutboundProvisioningConnector() { @Override public void init(Property[] provisioningProperties) throws IdentityProvisioningException { } @Override public ProvisionedIdentifier provision(ProvisioningEntity provisioningEntity) throws IdentityProvisioningException { return null; } }; attributeMap = new HashMap<>(); attributeMap.put(ClaimMapping.build("testLocalClaim", "testRemoteClaim", null, false), Arrays.asList("remoteClaimValue")); attributeMap.put(ClaimMapping.build("testLocalClaim1", null, null, false), new ArrayList<String>()); ClaimMapping mapping = new ClaimMapping(); mapping.setRemoteClaim(null); mapping.setLocalClaim(new Claim()); attributeMap.put(mapping, new ArrayList<String>()); attributeMap.put(ClaimMapping.build(IdentityProvisioningConstants.GROUP_CLAIM_URI, IdentityProvisioningConstants .GROUP_CLAIM_URI, null, false), Arrays.asList("testGroupName")); attributeMap.put(ClaimMapping.build(IdentityProvisioningConstants.USERNAME_CLAIM_URI, IdentityProvisioningConstants.USERNAME_CLAIM_URI, null, false), Arrays.asList("testUserName")); attributeMap.put(ClaimMapping.build(IdentityProvisioningConstants.PASSWORD_CLAIM_URI, IdentityProvisioningConstants.PASSWORD_CLAIM_URI, null, false), Arrays.asList("testPassword1", "testPassword2")); attributeMap.put(ClaimMapping.build("testLocalClaim", "testRemoteClaim1", null, false), Arrays.asList("testValue1", "testValue2")); attributeMap.put(ClaimMapping.build("testLocalClaim2", "testRemoteClaim1", null, false), Arrays.asList(null, "testValue2")); }
Example 8
Source File: IdPManagementDAO.java From carbon-identity-framework with Apache License 2.0 | 4 votes |
/** * @param dbConnection * @param idPName * @param userClaimUri * @param roleClaimUri * @param idpId * @param tenantId * @return * @throws SQLException */ private ClaimConfig getLocalIdPDefaultClaimValues(Connection dbConnection, String idPName, String userClaimUri, String roleClaimUri, int idpId, int tenantId) throws SQLException { PreparedStatement prepStmt = null; ResultSet rs = null; String sqlStmt; ClaimConfig claimConfig = new ClaimConfig(); try { claimConfig.setLocalClaimDialect(true); claimConfig.setRoleClaimURI(roleClaimUri); claimConfig.setUserClaimURI(userClaimUri); sqlStmt = IdPManagementConstants.SQLQueries.GET_LOCAL_IDP_DEFAULT_CLAIM_VALUES_SQL; prepStmt = dbConnection.prepareStatement(sqlStmt); prepStmt.setInt(1, idpId); prepStmt.setInt(2, tenantId); List<ClaimMapping> claimMappings = new ArrayList<ClaimMapping>(); rs = prepStmt.executeQuery(); while (rs.next()) { ClaimMapping claimMapping = new ClaimMapping(); // empty claim. Claim remoteClaim = new Claim(); Claim localClaim = new Claim(); localClaim.setClaimUri(rs.getString("CLAIM_URI")); claimMapping.setLocalClaim(localClaim); claimMapping.setRemoteClaim(remoteClaim); claimMapping.setDefaultValue(rs.getString("DEFAULT_VALUE")); if ((IdPManagementConstants.IS_TRUE_VALUE).equals(rs.getString("IS_REQUESTED"))) { claimMapping.setRequested(true); } else if (rs.getString("IS_REQUESTED").equals(IdPManagementConstants.IS_TRUE_VALUE)) { claimMapping.setRequested(false); } claimMappings.add(claimMapping); } claimConfig.setClaimMappings(claimMappings.toArray(new ClaimMapping[claimMappings .size()])); return claimConfig; } finally { IdentityDatabaseUtil.closeAllConnections(null, rs, prepStmt); } }
Example 9
Source File: IdPManagementDAO.java From carbon-identity-framework with Apache License 2.0 | 4 votes |
/** * @param dbConnection * @param idPName * @param tenantId * @return * @throws IdentityProviderManagementException * @throws SQLException */ private ClaimConfig getIdPClaimConfiguration(Connection dbConnection, String idPName, String userClaimUri, String roleClaimUri, int idPId, int tenantId) throws SQLException { PreparedStatement prepStmt1 = null; PreparedStatement prepStmt2 = null; ResultSet rs1 = null; ResultSet rs2 = null; try { List<Claim> claimList = new ArrayList<Claim>(); // SP_IDP_CLAIM_ID, SP_IDP_CLAIM String sqlStmt = IdPManagementConstants.SQLQueries.GET_IDP_CLAIMS_SQL; prepStmt1 = dbConnection.prepareStatement(sqlStmt); prepStmt1.setInt(1, idPId); rs1 = prepStmt1.executeQuery(); ClaimConfig claimConfig = new ClaimConfig(); while (rs1.next()) { Claim identityProviderClaim = new Claim(); identityProviderClaim.setClaimId(rs1.getInt(1)); identityProviderClaim.setClaimUri(rs1.getString(2)); claimList.add(identityProviderClaim); } // populate claim configuration with identity provider claims. claimConfig.setIdpClaims(claimList.toArray(new Claim[claimList.size()])); claimConfig.setUserClaimURI(userClaimUri); claimConfig.setRoleClaimURI(roleClaimUri); List<ClaimMapping> claimMappings = new ArrayList<ClaimMapping>(); // SP_IDP_CLAIMS.SP_IDP_CLAIM SP_IDP_CLAIM_MAPPINGS.SP_LOCAL_CLAIM sqlStmt = IdPManagementConstants.SQLQueries.GET_IDP_CLAIM_MAPPINGS_SQL; prepStmt2 = dbConnection.prepareStatement(sqlStmt); prepStmt2.setInt(1, idPId); rs2 = prepStmt2.executeQuery(); while (rs2.next()) { ClaimMapping claimMapping = new ClaimMapping(); Claim idpClaim = new Claim(); idpClaim.setClaimUri(rs2.getString("CLAIM")); Claim localClaim = new Claim(); localClaim.setClaimUri(rs2.getString("LOCAL_CLAIM")); claimMapping.setLocalClaim(localClaim); claimMapping.setRemoteClaim(idpClaim); claimMapping.setDefaultValue(rs2.getString("DEFAULT_VALUE")); if ((IdPManagementConstants.IS_TRUE_VALUE).equals(rs2.getString("IS_REQUESTED"))) { claimMapping.setRequested(true); } else if ((IdPManagementConstants.IS_FALSE_VALUE).equals(rs2.getString("IS_REQUESTED"))) { claimMapping.setRequested(false); } claimMappings.add(claimMapping); } claimConfig.setClaimMappings(claimMappings.toArray(new ClaimMapping[claimMappings .size()])); return claimConfig; } finally { IdentityDatabaseUtil.closeAllConnections(null, rs2, prepStmt2); IdentityDatabaseUtil.closeAllConnections(null, rs1, prepStmt1); } }
Example 10
Source File: IdPManagementDAO.java From carbon-identity with Apache License 2.0 | 4 votes |
/** * @param dbConnection * @param idPName * @param userClaimUri * @param roleClaimUri * @param idpId * @param tenantId * @return * @throws SQLException */ private ClaimConfig getLocalIdPDefaultClaimValues(Connection dbConnection, String idPName, String userClaimUri, String roleClaimUri, int idpId, int tenantId) throws SQLException { PreparedStatement prepStmt = null; ResultSet rs = null; String sqlStmt; ClaimConfig claimConfig = new ClaimConfig(); try { claimConfig.setLocalClaimDialect(true); claimConfig.setRoleClaimURI(roleClaimUri); claimConfig.setUserClaimURI(userClaimUri); sqlStmt = IdPManagementConstants.SQLQueries.GET_LOCAL_IDP_DEFAULT_CLAIM_VALUES_SQL; prepStmt = dbConnection.prepareStatement(sqlStmt); prepStmt.setInt(1, idpId); prepStmt.setInt(2, tenantId); List<ClaimMapping> claimMappings = new ArrayList<ClaimMapping>(); rs = prepStmt.executeQuery(); while (rs.next()) { ClaimMapping claimMapping = new ClaimMapping(); // empty claim. Claim remoteClaim = new Claim(); Claim localClaim = new Claim(); localClaim.setClaimUri(rs.getString("CLAIM_URI")); claimMapping.setLocalClaim(localClaim); claimMapping.setRemoteClaim(remoteClaim); claimMapping.setDefaultValue(rs.getString("DEFAULT_VALUE")); if ((IdPManagementConstants.IS_TRUE_VALUE).equals(rs.getString("IS_REQUESTED"))) { claimMapping.setRequested(true); } else if (rs.getString("IS_REQUESTED").equals(IdPManagementConstants.IS_TRUE_VALUE)) { claimMapping.setRequested(false); } claimMappings.add(claimMapping); } claimConfig.setClaimMappings(claimMappings.toArray(new ClaimMapping[claimMappings .size()])); return claimConfig; } finally { IdentityDatabaseUtil.closeAllConnections(null, rs, prepStmt); } }
Example 11
Source File: IdPManagementDAO.java From carbon-identity with Apache License 2.0 | 4 votes |
/** * @param dbConnection * @param idPName * @param tenantId * @return * @throws IdentityProviderManagementException * @throws SQLException */ private ClaimConfig getIdPClaimConfiguration(Connection dbConnection, String idPName, String userClaimUri, String roleClaimUri, int idPId, int tenantId) throws IdentityProviderManagementException, SQLException { PreparedStatement prepStmt1 = null; PreparedStatement prepStmt2 = null; ResultSet rs1 = null; ResultSet rs2 = null; try { List<Claim> claimList = new ArrayList<Claim>(); // SP_IDP_CLAIM_ID, SP_IDP_CLAIM String sqlStmt = IdPManagementConstants.SQLQueries.GET_IDP_CLAIMS_SQL; prepStmt1 = dbConnection.prepareStatement(sqlStmt); prepStmt1.setInt(1, idPId); rs1 = prepStmt1.executeQuery(); ClaimConfig claimConfig = new ClaimConfig(); while (rs1.next()) { Claim identityProviderClaim = new Claim(); identityProviderClaim.setClaimId(rs1.getInt(1)); identityProviderClaim.setClaimUri(rs1.getString(2)); claimList.add(identityProviderClaim); } // populate claim configuration with identity provider claims. claimConfig.setIdpClaims(claimList.toArray(new Claim[claimList.size()])); claimConfig.setUserClaimURI(userClaimUri); claimConfig.setRoleClaimURI(roleClaimUri); List<ClaimMapping> claimMappings = new ArrayList<ClaimMapping>(); // SP_IDP_CLAIMS.SP_IDP_CLAIM SP_IDP_CLAIM_MAPPINGS.SP_LOCAL_CLAIM sqlStmt = IdPManagementConstants.SQLQueries.GET_IDP_CLAIM_MAPPINGS_SQL; prepStmt2 = dbConnection.prepareStatement(sqlStmt); prepStmt2.setInt(1, idPId); rs2 = prepStmt2.executeQuery(); while (rs2.next()) { ClaimMapping claimMapping = new ClaimMapping(); Claim idpClaim = new Claim(); idpClaim.setClaimUri(rs2.getString("CLAIM")); Claim localClaim = new Claim(); localClaim.setClaimUri(rs2.getString("LOCAL_CLAIM")); claimMapping.setLocalClaim(localClaim); claimMapping.setRemoteClaim(idpClaim); claimMapping.setDefaultValue(rs2.getString("DEFAULT_VALUE")); if ((IdPManagementConstants.IS_TRUE_VALUE).equals(rs2.getString("IS_REQUESTED"))) { claimMapping.setRequested(true); } else if ((IdPManagementConstants.IS_FALSE_VALUE).equals(rs2.getString("IS_REQUESTED"))) { claimMapping.setRequested(false); } claimMappings.add(claimMapping); } claimConfig.setClaimMappings(claimMappings.toArray(new ClaimMapping[claimMappings .size()])); return claimConfig; } finally { IdentityDatabaseUtil.closeAllConnections(null, rs2, prepStmt2); IdentityDatabaseUtil.closeAllConnections(null, rs1, prepStmt1); } }