Search in sources :

Example 1 with ClaimMappingDTO

use of org.wso2.carbon.claim.mgt.dto.ClaimMappingDTO 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 ClaimMappingDTO

use of org.wso2.carbon.claim.mgt.dto.ClaimMappingDTO 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 ClaimMappingDTO

use of org.wso2.carbon.claim.mgt.dto.ClaimMappingDTO in project carbon-apimgt by wso2.

the class DefaultJWTTransformer method transform.

@Override
public JWTClaimsSet transform(JWTClaimsSet jwtClaimsSet) {
    JWTClaimsSet.Builder transformedJWT = new JWTClaimsSet.Builder();
    if (tokenIssuer != null) {
        Map<String, ClaimMappingDto> claimConfigurations = tokenIssuer.getClaimConfigurations();
        for (Map.Entry<String, Object> claimEntry : jwtClaimsSet.getClaims().entrySet()) {
            ClaimMappingDto claimMappingDto = claimConfigurations.get(claimEntry.getKey());
            String claimKey = claimEntry.getKey();
            if (claimMappingDto != null) {
                claimKey = claimMappingDto.getLocalClaim();
            }
            transformedJWT.claim(claimKey, claimEntry.getValue());
        }
        return transformedJWT.build();
    }
    return jwtClaimsSet;
}
Also used : ClaimMappingDto(org.wso2.carbon.apimgt.common.gateway.dto.ClaimMappingDto) JWTClaimsSet(com.nimbusds.jwt.JWTClaimsSet) Map(java.util.Map)

Example 4 with ClaimMappingDTO

use of org.wso2.carbon.claim.mgt.dto.ClaimMappingDTO in project carbon-identity-framework by wso2.

the class ClaimAdminService method addNewClaimMapping.

/**
 * @param
 * @throws ClaimManagementException
 */
public void addNewClaimMapping(ClaimMappingDTO claimMappingDTO) throws ClaimManagementException {
    /*Convert the simple structure of ClaimMapping received, to the complex structure
        of ClaimMapping which is used in the back end. */
    ClaimMapping claimMapping = convertClaimMappingDTOToClaimMapping(claimMappingDTO);
    ClaimManagerHandler handler = ClaimManagerHandler.getInstance();
    ClaimMapping currentMapping = handler.getClaimMapping(claimMapping.getClaim().getClaimUri());
    if (currentMapping != null) {
        throw new ClaimManagementException("Duplicate claim exist in the system. Please pick a different Claim Uri");
    }
    handler.addNewClaimMapping(claimMapping);
}
Also used : ClaimMapping(org.wso2.carbon.user.api.ClaimMapping)

Example 5 with ClaimMappingDTO

use of org.wso2.carbon.claim.mgt.dto.ClaimMappingDTO in project carbon-identity-framework by wso2.

the class ClaimAdminService method convertClaimMappingToClaimMappingDTO.

private ClaimMappingDTO convertClaimMappingToClaimMappingDTO(ClaimMapping claimMapping) {
    ClaimMappingDTO claimMappingDTO = new ClaimMappingDTO();
    claimMappingDTO.setClaim(convertClaimToClaimDTO(claimMapping.getClaim()));
    claimMappingDTO.setMappedAttribute(claimMapping.getMappedAttribute());
    Map<String, String> attributes = claimMapping.getMappedAttributes();
    if (attributes != null) {
        ClaimAttributeDTO[] attrDto = new ClaimAttributeDTO[attributes.size()];
        int i = 0;
        for (Map.Entry<String, String> entry : attributes.entrySet()) {
            ClaimAttributeDTO dto = new ClaimAttributeDTO();
            dto.setAttributeName(entry.getValue());
            dto.setDomainName(entry.getKey());
            attrDto[i++] = dto;
        }
        claimMappingDTO.setMappedAttributes(attrDto);
    }
    return claimMappingDTO;
}
Also used : ClaimMappingDTO(org.wso2.carbon.claim.mgt.dto.ClaimMappingDTO) ClaimAttributeDTO(org.wso2.carbon.claim.mgt.dto.ClaimAttributeDTO) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

ClaimMappingDTO (org.wso2.carbon.claim.mgt.stub.dto.ClaimMappingDTO)8 ClaimDTO (org.wso2.carbon.claim.mgt.stub.dto.ClaimDTO)7 ArrayList (java.util.ArrayList)6 ClaimDialectDTO (org.wso2.carbon.claim.mgt.stub.dto.ClaimDialectDTO)5 ClaimMapping (org.wso2.carbon.user.api.ClaimMapping)5 Test (org.testng.annotations.Test)4 ClaimMappingDto (org.wso2.carbon.apimgt.common.gateway.dto.ClaimMappingDto)4 ISIntegrationTest (org.wso2.identity.integration.common.utils.ISIntegrationTest)4 ClaimMappingDTO (org.wso2.carbon.claim.mgt.dto.ClaimMappingDTO)3 ClaimAttributeDTO (org.wso2.carbon.claim.mgt.stub.dto.ClaimAttributeDTO)3 Gson (com.google.gson.Gson)2 Map (java.util.Map)2 JWKSConfigurationDTO (org.wso2.carbon.apimgt.common.gateway.dto.JWKSConfigurationDTO)2 TokenIssuerDto (org.wso2.carbon.apimgt.common.gateway.dto.TokenIssuerDto)2 ClaimAttributeDTO (org.wso2.carbon.claim.mgt.dto.ClaimAttributeDTO)2 JsonElement (com.google.gson.JsonElement)1 JWTClaimsSet (com.nimbusds.jwt.JWTClaimsSet)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 File (java.io.File)1 FileInputStream (java.io.FileInputStream)1