Search in sources :

Example 1 with ExternalClaimDTO

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

the class ClaimMetadataManagementAdminService method getExternalClaims.

@SuppressWarnings("unused")
public ExternalClaimDTO[] getExternalClaims(String externalClaimDialectURI) throws ClaimMetadataException {
    try {
        String tenantDomain = CarbonContext.getThreadLocalCarbonContext().getTenantDomain();
        List<ExternalClaim> externalClaimList = IdentityClaimManagementServiceDataHolder.getInstance().getClaimManagementService().getExternalClaims(externalClaimDialectURI, tenantDomain);
        ExternalClaim[] externalClaims = externalClaimList.toArray(new ExternalClaim[0]);
        ExternalClaimDTO[] externalClaimDTOS = ClaimMetadataUtils.convertExternalClaimsToExternalClaimDTOs(externalClaims);
        // Sort the external claims in the alphabetical order
        Arrays.sort(externalClaimDTOS, new Comparator<ExternalClaimDTO>() {

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

Example 2 with ExternalClaimDTO

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

the class ClaimMetadataManagementAdminService method addExternalClaim.

@SuppressWarnings("unused")
public void addExternalClaim(ExternalClaimDTO externalClaim) throws ClaimMetadataException {
    try {
        ExternalClaim claim = ClaimMetadataUtils.convertExternalClaimDTOToExternalClaim(externalClaim);
        String tenantDomain = CarbonContext.getThreadLocalCarbonContext().getTenantDomain();
        IdentityClaimManagementServiceDataHolder.getInstance().getClaimManagementService().addExternalClaim(claim, tenantDomain);
    } catch (ClaimMetadataClientException e) {
        if (log.isDebugEnabled()) {
            log.debug(e.getMessage(), e);
        }
        throw new ClaimMetadataException(e.getMessage(), e);
    } catch (Throwable e) {
        log.error(e.getMessage(), e);
        throw new ClaimMetadataException(e.getMessage(), e);
    }
}
Also used : ClaimMetadataClientException(org.wso2.carbon.identity.claim.metadata.mgt.exception.ClaimMetadataClientException) ClaimMetadataException(org.wso2.carbon.identity.claim.metadata.mgt.exception.ClaimMetadataException) ExternalClaim(org.wso2.carbon.identity.claim.metadata.mgt.model.ExternalClaim)

Example 3 with ExternalClaimDTO

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

the class ClaimMetadataUtils method convertExternalClaimToExternalClaimDTO.

public static ExternalClaimDTO convertExternalClaimToExternalClaimDTO(ExternalClaim externalClaim) {
    ExternalClaimDTO externalClaimDTO = new ExternalClaimDTO();
    externalClaimDTO.setExternalClaimDialectURI(externalClaim.getClaimDialectURI());
    externalClaimDTO.setExternalClaimURI(externalClaim.getClaimURI());
    externalClaimDTO.setMappedLocalClaimURI(externalClaim.getMappedLocalClaim());
    // Convert Map<String, String> to ClaimPropertyDTO[]
    Map<String, String> claimProperties = externalClaim.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++;
    }
    externalClaimDTO.setClaimProperties(claimPropertyDTOs);
    return externalClaimDTO;
}
Also used : ExternalClaimDTO(org.wso2.carbon.identity.claim.metadata.mgt.dto.ExternalClaimDTO) ClaimPropertyDTO(org.wso2.carbon.identity.claim.metadata.mgt.dto.ClaimPropertyDTO) HashMap(java.util.HashMap) Map(java.util.Map)

Example 4 with ExternalClaimDTO

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

the class ClaimMetadataUtils method convertExternalClaimDTOToExternalClaim.

public static ExternalClaim convertExternalClaimDTOToExternalClaim(ExternalClaimDTO externalClaimDTO) {
    // TODO : Validate if externalClaimDTO null???
    ExternalClaim externalClaim = new ExternalClaim(externalClaimDTO.getExternalClaimDialectURI(), externalClaimDTO.getExternalClaimURI(), externalClaimDTO.getMappedLocalClaimURI());
    // Convert ClaimPropertyDTO[] to Map<String, String>
    if (externalClaimDTO.getClaimProperties() != null) {
        Map<String, String> claimProperties = new HashMap<>();
        for (ClaimPropertyDTO claimPropertyDTO : externalClaimDTO.getClaimProperties()) {
            claimProperties.put(claimPropertyDTO.getPropertyName(), claimPropertyDTO.getPropertyValue());
        }
        externalClaim.setClaimProperties(claimProperties);
    }
    return externalClaim;
}
Also used : ClaimPropertyDTO(org.wso2.carbon.identity.claim.metadata.mgt.dto.ClaimPropertyDTO) HashMap(java.util.HashMap) ExternalClaim(org.wso2.carbon.identity.claim.metadata.mgt.model.ExternalClaim)

Example 5 with ExternalClaimDTO

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

the class ClaimMetadataUtilsTest method setUpExternalClaims.

private void setUpExternalClaims() {
    String claimDialectURI = "testClaimDialectURI";
    String externalClaimURI = "testExternalClaimURI";
    String mappedLocalClaimURI = "testLocalClaimURI2";
    externalClaim = new ExternalClaim(claimDialectURI, externalClaimURI, mappedLocalClaimURI);
    int arraySize = 2;
    externalClaims = new ExternalClaim[arraySize];
    for (int i = 0; i < externalClaims.length; i++) {
        externalClaims[i] = new ExternalClaim(claimDialectURI + i, externalClaimURI + i, mappedLocalClaimURI + i);
    }
    ClaimPropertyDTO claimPropertyDTO1 = new ClaimPropertyDTO();
    claimPropertyDTO1.setPropertyName(ClaimConstants.DISPLAY_NAME_PROPERTY);
    claimPropertyDTO1.setPropertyValue("username");
    ClaimPropertyDTO claimPropertyDTO2 = new ClaimPropertyDTO();
    claimPropertyDTO2.setPropertyName(ClaimConstants.READ_ONLY_PROPERTY);
    claimPropertyDTO2.setPropertyValue("true");
    ClaimPropertyDTO[] claimPropertyDTOs = new ClaimPropertyDTO[] { claimPropertyDTO1, claimPropertyDTO2 };
    externalClaimDTO = new ExternalClaimDTO();
    externalClaimDTO.setExternalClaimDialectURI(claimDialectURI);
    externalClaimDTO.setExternalClaimURI(externalClaimURI);
    externalClaimDTO.setMappedLocalClaimURI(mappedLocalClaimURI);
    externalClaimDTO.setClaimProperties(claimPropertyDTOs);
}
Also used : ExternalClaimDTO(org.wso2.carbon.identity.claim.metadata.mgt.dto.ExternalClaimDTO) ClaimPropertyDTO(org.wso2.carbon.identity.claim.metadata.mgt.dto.ClaimPropertyDTO) ExternalClaim(org.wso2.carbon.identity.claim.metadata.mgt.model.ExternalClaim)

Aggregations

ExternalClaim (org.wso2.carbon.identity.claim.metadata.mgt.model.ExternalClaim)7 ClaimPropertyDTO (org.wso2.carbon.identity.claim.metadata.mgt.dto.ClaimPropertyDTO)6 ExternalClaimDTO (org.wso2.carbon.identity.claim.metadata.mgt.stub.dto.ExternalClaimDTO)6 ExternalClaimDTO (org.wso2.carbon.identity.claim.metadata.mgt.dto.ExternalClaimDTO)5 Test (org.testng.annotations.Test)3 ClaimMetadataException (org.wso2.carbon.identity.claim.metadata.mgt.exception.ClaimMetadataException)3 HashMap (java.util.HashMap)2 AttributeMappingDTO (org.wso2.carbon.identity.claim.metadata.mgt.stub.dto.AttributeMappingDTO)2 ClaimPropertyDTO (org.wso2.carbon.identity.claim.metadata.mgt.stub.dto.ClaimPropertyDTO)2 LocalClaimDTO (org.wso2.carbon.identity.claim.metadata.mgt.stub.dto.LocalClaimDTO)2 Map (java.util.Map)1 BeforeClass (org.testng.annotations.BeforeClass)1 ClaimMetadataClientException (org.wso2.carbon.identity.claim.metadata.mgt.exception.ClaimMetadataClientException)1 OAuthConsumerAppDTO (org.wso2.carbon.identity.oauth.stub.dto.OAuthConsumerAppDTO)1 UserManagementClient (org.wso2.carbon.integration.common.admin.client.UserManagementClient)1 IdentityProviderMgtServiceClient (org.wso2.identity.integration.common.clients.Idp.IdentityProviderMgtServiceClient)1 UserProfileMgtServiceClient (org.wso2.identity.integration.common.clients.UserProfileMgtServiceClient)1 ClaimMetadataManagementServiceClient (org.wso2.identity.integration.common.clients.claim.metadata.mgt.ClaimMetadataManagementServiceClient)1 OauthAdminClient (org.wso2.identity.integration.common.clients.oauth.OauthAdminClient)1