Search in sources :

Example 1 with LocalClaimDTO

use of org.wso2.carbon.identity.claim.metadata.mgt.dto.LocalClaimDTO 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)

Example 2 with LocalClaimDTO

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

the class ClaimMetadataManagementAdminService method updateLocalClaim.

@SuppressWarnings("unused")
public void updateLocalClaim(LocalClaimDTO localClaim) throws ClaimMetadataException {
    try {
        LocalClaim claim = ClaimMetadataUtils.convertLocalClaimDTOToLocalClaim(localClaim);
        String tenantDomain = CarbonContext.getThreadLocalCarbonContext().getTenantDomain();
        IdentityClaimManagementServiceDataHolder.getInstance().getClaimManagementService().updateLocalClaim(claim, tenantDomain);
    } catch (Throwable e) {
        log.error(e.getMessage(), e);
        throw new ClaimMetadataException(e.getMessage(), e);
    }
}
Also used : ClaimMetadataException(org.wso2.carbon.identity.claim.metadata.mgt.exception.ClaimMetadataException) LocalClaim(org.wso2.carbon.identity.claim.metadata.mgt.model.LocalClaim)

Example 3 with LocalClaimDTO

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

the class ClaimMetadataManagementAdminService method getLocalClaims.

@SuppressWarnings("unused")
public LocalClaimDTO[] getLocalClaims() throws ClaimMetadataException {
    try {
        String tenantDomain = CarbonContext.getThreadLocalCarbonContext().getTenantDomain();
        List<LocalClaim> localClaimList = IdentityClaimManagementServiceDataHolder.getInstance().getClaimManagementService().getLocalClaims(tenantDomain);
        LocalClaim[] localClaims = localClaimList.toArray(new LocalClaim[0]);
        LocalClaimDTO[] localClaimDTOS = ClaimMetadataUtils.convertLocalClaimsToLocalClaimDTOs(localClaims);
        // Sort the local claims in the alphabetical order
        Arrays.sort(localClaimDTOS, new Comparator<LocalClaimDTO>() {

            @Override
            public int compare(LocalClaimDTO o1, LocalClaimDTO o2) {
                return o1.getLocalClaimURI().toLowerCase().compareTo(o2.getLocalClaimURI().toLowerCase());
            }
        });
        return localClaimDTOS;
    } catch (Throwable e) {
        log.error(e.getMessage(), e);
        throw new ClaimMetadataException(e.getMessage(), e);
    }
}
Also used : ClaimMetadataException(org.wso2.carbon.identity.claim.metadata.mgt.exception.ClaimMetadataException) LocalClaim(org.wso2.carbon.identity.claim.metadata.mgt.model.LocalClaim) LocalClaimDTO(org.wso2.carbon.identity.claim.metadata.mgt.dto.LocalClaimDTO)

Example 4 with LocalClaimDTO

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

the class ClaimMetadataUtils method convertLocalClaimToLocalClaimDTO.

public static LocalClaimDTO convertLocalClaimToLocalClaimDTO(LocalClaim localClaim) {
    LocalClaimDTO localClaimDTO = new LocalClaimDTO();
    localClaimDTO.setLocalClaimURI(localClaim.getClaimURI());
    // Convert List<AttributeMapping> to AttributeMappingDTO[]
    List<AttributeMapping> attributeMappings = localClaim.getMappedAttributes();
    AttributeMappingDTO[] attributeMappingDTOs = new AttributeMappingDTO[attributeMappings.size()];
    int i = 0;
    for (AttributeMapping attributeMapping : attributeMappings) {
        AttributeMappingDTO attributeMappingDTO = new AttributeMappingDTO();
        attributeMappingDTO.setUserStoreDomain(attributeMapping.getUserStoreDomain());
        attributeMappingDTO.setAttributeName(attributeMapping.getAttributeName());
        attributeMappingDTOs[i] = attributeMappingDTO;
        i++;
    }
    localClaimDTO.setAttributeMappings(attributeMappingDTOs);
    // Convert Map<String, String> to ClaimPropertyDTO[]
    Map<String, String> claimProperties = localClaim.getClaimProperties();
    ClaimPropertyDTO[] claimPropertyDTOs = new ClaimPropertyDTO[claimProperties.size()];
    int j = 0;
    for (Map.Entry<String, String> claimPropertyEntry : claimProperties.entrySet()) {
        ClaimPropertyDTO claimProperty = new ClaimPropertyDTO();
        claimProperty.setPropertyName(claimPropertyEntry.getKey());
        claimProperty.setPropertyValue(claimPropertyEntry.getValue());
        claimPropertyDTOs[j] = claimProperty;
        j++;
    }
    localClaimDTO.setClaimProperties(claimPropertyDTOs);
    return localClaimDTO;
}
Also used : ClaimPropertyDTO(org.wso2.carbon.identity.claim.metadata.mgt.dto.ClaimPropertyDTO) AttributeMappingDTO(org.wso2.carbon.identity.claim.metadata.mgt.dto.AttributeMappingDTO) AttributeMapping(org.wso2.carbon.identity.claim.metadata.mgt.model.AttributeMapping) HashMap(java.util.HashMap) Map(java.util.Map) LocalClaimDTO(org.wso2.carbon.identity.claim.metadata.mgt.dto.LocalClaimDTO)

Example 5 with LocalClaimDTO

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

the class ClaimMetadataUtils method convertLocalClaimDTOToLocalClaim.

public static LocalClaim convertLocalClaimDTOToLocalClaim(LocalClaimDTO localClaimDTO) {
    // TODO : Validate if localClaimDTO null???
    LocalClaim localClaim = new LocalClaim(localClaimDTO.getLocalClaimURI());
    // Convert AttributeMappingDTO[] to List<AttributeMapping>
    if (localClaimDTO.getAttributeMappings() != null) {
        List<AttributeMapping> attributeMappings = new ArrayList<>();
        for (AttributeMappingDTO attributeMappingDTO : localClaimDTO.getAttributeMappings()) {
            attributeMappings.add(new AttributeMapping(attributeMappingDTO.getUserStoreDomain(), attributeMappingDTO.getAttributeName()));
        }
        localClaim.setMappedAttributes(attributeMappings);
    }
    // Convert ClaimPropertyDTO[] to Map<String, String>
    if (localClaimDTO.getClaimProperties() != null) {
        Map<String, String> claimProperties = new HashMap<>();
        for (ClaimPropertyDTO claimPropertyDTO : localClaimDTO.getClaimProperties()) {
            claimProperties.put(claimPropertyDTO.getPropertyName(), claimPropertyDTO.getPropertyValue());
        }
        localClaim.setClaimProperties(claimProperties);
    }
    return localClaim;
}
Also used : ClaimPropertyDTO(org.wso2.carbon.identity.claim.metadata.mgt.dto.ClaimPropertyDTO) AttributeMappingDTO(org.wso2.carbon.identity.claim.metadata.mgt.dto.AttributeMappingDTO) HashMap(java.util.HashMap) AttributeMapping(org.wso2.carbon.identity.claim.metadata.mgt.model.AttributeMapping) ArrayList(java.util.ArrayList) LocalClaim(org.wso2.carbon.identity.claim.metadata.mgt.model.LocalClaim)

Aggregations

LocalClaimDTO (org.wso2.carbon.identity.claim.metadata.mgt.stub.dto.LocalClaimDTO)7 LocalClaim (org.wso2.carbon.identity.claim.metadata.mgt.model.LocalClaim)6 ClaimPropertyDTO (org.wso2.carbon.identity.claim.metadata.mgt.dto.ClaimPropertyDTO)5 LocalClaimDTO (org.wso2.carbon.identity.claim.metadata.mgt.dto.LocalClaimDTO)5 AttributeMappingDTO (org.wso2.carbon.identity.claim.metadata.mgt.stub.dto.AttributeMappingDTO)5 ClaimPropertyDTO (org.wso2.carbon.identity.claim.metadata.mgt.stub.dto.ClaimPropertyDTO)4 HashMap (java.util.HashMap)3 Test (org.testng.annotations.Test)3 AttributeMappingDTO (org.wso2.carbon.identity.claim.metadata.mgt.dto.AttributeMappingDTO)3 ClaimMetadataException (org.wso2.carbon.identity.claim.metadata.mgt.exception.ClaimMetadataException)3 AttributeMapping (org.wso2.carbon.identity.claim.metadata.mgt.model.AttributeMapping)3 ArrayList (java.util.ArrayList)2 Map (java.util.Map)2 ExternalClaimDTO (org.wso2.carbon.identity.claim.metadata.mgt.stub.dto.ExternalClaimDTO)2 List (java.util.List)1 ClaimMetadataClientException (org.wso2.carbon.identity.claim.metadata.mgt.exception.ClaimMetadataClientException)1 ISIntegrationTest (org.wso2.identity.integration.common.utils.ISIntegrationTest)1