Search in sources :

Example 1 with LocalClaim

use of org.wso2.carbon.identity.claim.metadata.mgt.model.LocalClaim in project carbon-apimgt by wso2.

the class APIManagerConfiguration method setJWTTokenIssuers.

private void setJWTTokenIssuers(OMElement omElement) {
    Iterator tokenIssuersElement = omElement.getChildrenWithLocalName(APIConstants.TokenIssuer.TOKEN_ISSUER);
    while (tokenIssuersElement.hasNext()) {
        OMElement issuerElement = (OMElement) tokenIssuersElement.next();
        String issuer = issuerElement.getAttributeValue(new QName("issuer"));
        OMElement consumerKeyClaimElement = issuerElement.getFirstChildWithName(new QName(APIConstants.TokenIssuer.CONSUMER_KEY_CLAIM));
        OMElement scopesElement = issuerElement.getFirstChildWithName(new QName(APIConstants.TokenIssuer.SCOPES_CLAIM));
        TokenIssuerDto tokenIssuerDto = new TokenIssuerDto(issuer);
        if (consumerKeyClaimElement != null) {
            tokenIssuerDto.setConsumerKeyClaim(consumerKeyClaimElement.getText());
        }
        if (scopesElement != null) {
            tokenIssuerDto.setScopesClaim(scopesElement.getText());
        }
        OMElement jwksConfiguration = issuerElement.getFirstChildWithName(new QName(APIConstants.TokenIssuer.JWKS_CONFIGURATION));
        if (jwksConfiguration != null) {
            JWKSConfigurationDTO jwksConfigurationDTO = tokenIssuerDto.getJwksConfigurationDTO();
            jwksConfigurationDTO.setEnabled(true);
            jwksConfigurationDTO.setUrl(jwksConfiguration.getFirstChildWithName(new QName(APIConstants.TokenIssuer.JWKSConfiguration.URL)).getText());
        }
        OMElement claimMappingsElement = issuerElement.getFirstChildWithName(new QName(APIConstants.TokenIssuer.CLAIM_MAPPINGS));
        if (claimMappingsElement != null) {
            OMAttribute disableDefaultClaimMappingAttribute = claimMappingsElement.getAttribute(new QName("disable-default-claim-mapping"));
            if (disableDefaultClaimMappingAttribute != null) {
                String disableDefaultClaimMapping = disableDefaultClaimMappingAttribute.getAttributeValue();
                tokenIssuerDto.setDisableDefaultClaimMapping(Boolean.parseBoolean(disableDefaultClaimMapping));
            }
            Iterator claimMapping = claimMappingsElement.getChildrenWithName(new QName(APIConstants.TokenIssuer.CLAIM_MAPPING));
            while (claimMapping.hasNext()) {
                OMElement claim = (OMElement) claimMapping.next();
                OMElement remoteClaimElement = claim.getFirstChildWithName(new QName(APIConstants.TokenIssuer.ClaimMapping.REMOTE_CLAIM));
                OMElement localClaimElement = claim.getFirstChildWithName(new QName(APIConstants.TokenIssuer.ClaimMapping.LOCAL_CLAIM));
                if (remoteClaimElement != null && localClaimElement != null) {
                    String remoteClaim = remoteClaimElement.getText();
                    String localClaim = localClaimElement.getText();
                    if (StringUtils.isNotEmpty(remoteClaim) && StringUtils.isNotEmpty(localClaim)) {
                        tokenIssuerDto.getClaimConfigurations().put(remoteClaim, new ClaimMappingDto(remoteClaim, localClaim));
                    }
                }
            }
        }
        jwtConfigurationDto.getTokenIssuerDtoMap().put(tokenIssuerDto.getIssuer(), tokenIssuerDto);
    }
}
Also used : ClaimMappingDto(org.wso2.carbon.apimgt.common.gateway.dto.ClaimMappingDto) JWKSConfigurationDTO(org.wso2.carbon.apimgt.common.gateway.dto.JWKSConfigurationDTO) QName(javax.xml.namespace.QName) Iterator(java.util.Iterator) OMElement(org.apache.axiom.om.OMElement) TokenIssuerDto(org.wso2.carbon.apimgt.common.gateway.dto.TokenIssuerDto) OMAttribute(org.apache.axiom.om.OMAttribute)

Example 2 with LocalClaim

use of org.wso2.carbon.identity.claim.metadata.mgt.model.LocalClaim in project carbon-apimgt by wso2.

the class APIUtil method getDefaultClaimMappings.

public static List<ClaimMappingDto> getDefaultClaimMappings() {
    List<ClaimMappingDto> claimMappingDtoList = new ArrayList<>();
    try (InputStream resourceAsStream = APIUtil.class.getClassLoader().getResourceAsStream("claimMappings/default-claim-mapping.json")) {
        String content = IOUtils.toString(resourceAsStream);
        Map<String, String> claimMapping = new Gson().fromJson(content, Map.class);
        claimMapping.forEach((remoteClaim, localClaim) -> {
            claimMappingDtoList.add(new ClaimMappingDto(remoteClaim, localClaim));
        });
    } catch (IOException e) {
        log.error("Error while reading default-claim-mapping.json", e);
    }
    return claimMappingDtoList;
}
Also used : ClaimMappingDto(org.wso2.carbon.apimgt.common.gateway.dto.ClaimMappingDto) ByteArrayInputStream(java.io.ByteArrayInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) ArrayList(java.util.ArrayList) Gson(com.google.gson.Gson) IOException(java.io.IOException)

Example 3 with LocalClaim

use of org.wso2.carbon.identity.claim.metadata.mgt.model.LocalClaim in project carbon-apimgt by wso2.

the class APIAdminImpl method updateClaims.

private void updateClaims(IdentityProvider idp, Object claims) {
    if (claims != null) {
        ClaimConfig claimConfig = new ClaimConfig();
        List<ClaimMapping> claimMappings = new ArrayList<>();
        List<org.wso2.carbon.identity.application.common.model.Claim> idpClaims = new ArrayList<>();
        JsonArray claimArray = (JsonArray) claims;
        claimConfig.setLocalClaimDialect(false);
        for (JsonElement claimMappingEntry : claimArray) {
            if (claimMappingEntry instanceof JsonObject) {
                JsonElement idpClaimUri = ((JsonObject) claimMappingEntry).get("remoteClaim");
                JsonElement localClaimUri = ((JsonObject) claimMappingEntry).get("localClaim");
                ClaimMapping internalMapping = new ClaimMapping();
                org.wso2.carbon.identity.application.common.model.Claim remoteClaim = new org.wso2.carbon.identity.application.common.model.Claim();
                remoteClaim.setClaimUri(idpClaimUri.getAsString());
                org.wso2.carbon.identity.application.common.model.Claim localClaim = new org.wso2.carbon.identity.application.common.model.Claim();
                localClaim.setClaimUri(localClaimUri.getAsString());
                internalMapping.setRemoteClaim(remoteClaim);
                internalMapping.setLocalClaim(localClaim);
                claimMappings.add(internalMapping);
                idpClaims.add(remoteClaim);
            }
        }
        claimConfig.setClaimMappings(claimMappings.toArray(new ClaimMapping[0]));
        claimConfig.setIdpClaims(idpClaims.toArray(new org.wso2.carbon.identity.application.common.model.Claim[0]));
        idp.setClaimConfig(claimConfig);
    }
}
Also used : ArrayList(java.util.ArrayList) JsonObject(com.google.gson.JsonObject) JsonArray(com.google.gson.JsonArray) ClaimMapping(org.wso2.carbon.identity.application.common.model.ClaimMapping) ClaimConfig(org.wso2.carbon.identity.application.common.model.ClaimConfig) JsonElement(com.google.gson.JsonElement)

Example 4 with LocalClaim

use of org.wso2.carbon.identity.claim.metadata.mgt.model.LocalClaim in project carbon-identity-framework by wso2.

the class IdPManagementDAO method getLocalIdPDefaultClaimValues.

/**
 * @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);
    }
}
Also used : ClaimMapping(org.wso2.carbon.identity.application.common.model.ClaimMapping) ClaimConfig(org.wso2.carbon.identity.application.common.model.ClaimConfig) ResultSet(java.sql.ResultSet) ArrayList(java.util.ArrayList) PreparedStatement(java.sql.PreparedStatement) Claim(org.wso2.carbon.identity.application.common.model.Claim)

Example 5 with LocalClaim

use of org.wso2.carbon.identity.claim.metadata.mgt.model.LocalClaim in project carbon-identity-framework by wso2.

the class ClaimDataAdminClient method getRegex.

public String getRegex(LocalClaimDTO[] localClaimDTO, String claimURI) {
    String pattern = "";
    for (LocalClaimDTO localClaim : localClaimDTO) {
        if (claimURI.equals(localClaim.getLocalClaimURI())) {
            ClaimPropertyDTO[] claimPropertyDTOs = localClaim.getClaimProperties();
            if (claimPropertyDTOs != null) {
                for (ClaimPropertyDTO claimPropertyDTO : claimPropertyDTOs) {
                    if (ClaimConstants.REGULAR_EXPRESSION_PROPERTY.equals(claimPropertyDTO.getPropertyName())) {
                        pattern = claimPropertyDTO.getPropertyValue();
                        pattern = "/" + pattern + "/";
                        break;
                    }
                }
            }
        }
    }
    return pattern;
}
Also used : ClaimPropertyDTO(org.wso2.carbon.identity.claim.metadata.mgt.stub.dto.ClaimPropertyDTO) LocalClaimDTO(org.wso2.carbon.identity.claim.metadata.mgt.stub.dto.LocalClaimDTO)

Aggregations

LocalClaim (org.wso2.carbon.identity.claim.metadata.mgt.model.LocalClaim)52 ArrayList (java.util.ArrayList)38 HashMap (java.util.HashMap)26 ClaimMetadataException (org.wso2.carbon.identity.claim.metadata.mgt.exception.ClaimMetadataException)23 ExternalClaim (org.wso2.carbon.identity.claim.metadata.mgt.model.ExternalClaim)19 AttributeMapping (org.wso2.carbon.identity.claim.metadata.mgt.model.AttributeMapping)17 Test (org.testng.annotations.Test)15 Map (java.util.Map)11 ClaimMapping (org.wso2.carbon.identity.application.common.model.ClaimMapping)10 ClaimConfig (org.wso2.carbon.identity.application.common.model.ClaimConfig)8 ClaimDialect (org.wso2.carbon.identity.claim.metadata.mgt.model.ClaimDialect)8 UserStoreException (org.wso2.carbon.user.api.UserStoreException)8 ClaimMapping (org.wso2.carbon.user.api.ClaimMapping)7 Event (org.wso2.carbon.identity.event.event.Event)6 PreparedStatement (java.sql.PreparedStatement)5 HashSet (java.util.HashSet)5 Claim (org.wso2.carbon.identity.application.common.model.Claim)5 ClaimMapping (org.wso2.carbon.user.core.claim.ClaimMapping)5 Attribute (org.wso2.charon3.core.attributes.Attribute)5 MultiValuedAttribute (org.wso2.charon3.core.attributes.MultiValuedAttribute)5