Search in sources :

Example 1 with AttributeMappingDTO

use of org.wso2.carbon.identity.claim.metadata.mgt.dto.AttributeMappingDTO 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 2 with AttributeMappingDTO

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

Example 3 with AttributeMappingDTO

use of org.wso2.carbon.identity.claim.metadata.mgt.dto.AttributeMappingDTO in project product-is by wso2.

the class ClaimMappingsOnSecondaryUserStoreTestCase method testUserstoreDeletion.

@Test(groups = "wso2.is", description = "Check userstore delete", dependsOnMethods = { "testAddJDBCUserStore" })
public void testUserstoreDeletion() throws Exception {
    addLocalClaims();
    userStoreConfigAdminServiceClient.deleteUserStore(DOMAIN_ID);
    for (LocalClaimDTO localClaimDTO : claimMetadataManagementServiceClient.getLocalClaims()) {
        for (AttributeMappingDTO attributeMappingDTO : localClaimDTO.getAttributeMappings()) {
            Assert.assertNotEquals(attributeMappingDTO.getUserStoreDomain(), DOMAIN_ID);
        }
    }
}
Also used : AttributeMappingDTO(org.wso2.carbon.identity.claim.metadata.mgt.stub.dto.AttributeMappingDTO) LocalClaimDTO(org.wso2.carbon.identity.claim.metadata.mgt.stub.dto.LocalClaimDTO) ISIntegrationTest(org.wso2.identity.integration.common.utils.ISIntegrationTest) Test(org.testng.annotations.Test)

Example 4 with AttributeMappingDTO

use of org.wso2.carbon.identity.claim.metadata.mgt.dto.AttributeMappingDTO in project identity-api-server by wso2.

the class ServerClaimManagementService method getLocalClaimResDTO.

private LocalClaimResDTO getLocalClaimResDTO(LocalClaim localClaim) {
    LocalClaimResDTO localClaimResDTO = new LocalClaimResDTO();
    localClaimResDTO.setId(base64EncodeId(localClaim.getClaimURI()));
    localClaimResDTO.setClaimURI(localClaim.getClaimURI());
    localClaimResDTO.setDialectURI(localClaim.getClaimDialectURI());
    Map<String, String> claimProperties = new HashMap<>(localClaim.getClaimProperties());
    String description = claimProperties.remove(PROP_DESCRIPTION);
    localClaimResDTO.setDescription(description);
    if (description == null) {
        localClaimResDTO.setDescription(StringUtils.EMPTY);
    }
    String propDisplayOrder = claimProperties.remove(PROP_DISPLAY_ORDER);
    if (StringUtils.isNumeric(propDisplayOrder)) {
        localClaimResDTO.setDisplayOrder(Integer.valueOf(propDisplayOrder));
    } else {
        localClaimResDTO.setDisplayOrder(0);
    }
    localClaimResDTO.setDisplayName(claimProperties.remove(PROP_DISPLAY_NAME));
    localClaimResDTO.setReadOnly(Boolean.valueOf(claimProperties.remove(PROP_READ_ONLY)));
    String regEx = claimProperties.remove(PROP_REG_EX);
    localClaimResDTO.setRegEx(regEx);
    if (regEx == null) {
        localClaimResDTO.setRegEx(StringUtils.EMPTY);
    }
    localClaimResDTO.setRequired(Boolean.valueOf(claimProperties.remove(PROP_REQUIRED)));
    localClaimResDTO.setSupportedByDefault(Boolean.valueOf(claimProperties.remove(PROP_SUPPORTED_BY_DEFAULT)));
    List<AttributeMappingDTO> attributeMappingDTOs = new ArrayList<>();
    for (AttributeMapping attributeMapping : localClaim.getMappedAttributes()) {
        AttributeMappingDTO attributeMappingDTO = new AttributeMappingDTO();
        attributeMappingDTO.setUserstore(attributeMapping.getUserStoreDomain());
        attributeMappingDTO.setMappedAttribute(attributeMapping.getAttributeName());
        attributeMappingDTOs.add(attributeMappingDTO);
    }
    localClaimResDTO.setAttributeMapping(attributeMappingDTOs);
    localClaimResDTO.setProperties(mapToProperties(claimProperties));
    return localClaimResDTO;
}
Also used : AttributeMappingDTO(org.wso2.carbon.identity.rest.api.server.claim.management.v1.dto.AttributeMappingDTO) HashMap(java.util.HashMap) LocalClaimResDTO(org.wso2.carbon.identity.rest.api.server.claim.management.v1.dto.LocalClaimResDTO) AttributeMapping(org.wso2.carbon.identity.claim.metadata.mgt.model.AttributeMapping) ArrayList(java.util.ArrayList)

Example 5 with AttributeMappingDTO

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

the class ClaimMetadataUtilsTest method setUpLocalClaims.

private void setUpLocalClaims() {
    String localClaimURI1 = "testLocalClaimURI1";
    String localClaimURI2 = "testLocalClaimURI2";
    {
        localClaim1 = new LocalClaim(localClaimURI1);
        AttributeMapping attributeMapping1 = new AttributeMapping(UserCoreConstants.PRIMARY_DEFAULT_DOMAIN_NAME, "uid");
        AttributeMapping attributeMapping2 = new AttributeMapping("AD", "sAMAccountName");
        List<AttributeMapping> attributeMappingList = new ArrayList<>();
        attributeMappingList.add(attributeMapping1);
        attributeMappingList.add(attributeMapping2);
        Map<String, String> claimPropertiesMap = new HashMap<>();
        claimPropertiesMap.put(ClaimConstants.DISPLAY_NAME_PROPERTY, "username");
        claimPropertiesMap.put(ClaimConstants.READ_ONLY_PROPERTY, "true");
        localClaim2 = new LocalClaim(localClaimURI2, attributeMappingList, claimPropertiesMap);
        localClaims = new LocalClaim[] { localClaim1, localClaim2 };
    }
    {
        localClaimDTO1 = new LocalClaimDTO();
        localClaimDTO1.setLocalClaimURI(localClaimURI1);
        AttributeMappingDTO attributeMappingDTO1 = new AttributeMappingDTO();
        attributeMappingDTO1.setUserStoreDomain(UserCoreConstants.PRIMARY_DEFAULT_DOMAIN_NAME);
        attributeMappingDTO1.setAttributeName("uid");
        AttributeMappingDTO attributeMappingDTO2 = new AttributeMappingDTO();
        attributeMappingDTO2.setUserStoreDomain("AD");
        attributeMappingDTO2.setAttributeName("sAMAccountName");
        AttributeMappingDTO[] attributeMappingDTOs = new AttributeMappingDTO[] { attributeMappingDTO1, attributeMappingDTO2 };
        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 };
        localClaimDTO2 = new LocalClaimDTO();
        localClaimDTO2.setLocalClaimURI(localClaimURI2);
        localClaimDTO2.setAttributeMappings(attributeMappingDTOs);
        localClaimDTO2.setClaimProperties(claimPropertyDTOs);
        localClaimDTOs = new LocalClaimDTO[] { localClaimDTO1, localClaimDTO2 };
    }
}
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) LocalClaim(org.wso2.carbon.identity.claim.metadata.mgt.model.LocalClaim) ArrayList(java.util.ArrayList) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map) LocalClaimDTO(org.wso2.carbon.identity.claim.metadata.mgt.dto.LocalClaimDTO)

Aggregations

HashMap (java.util.HashMap)5 AttributeMapping (org.wso2.carbon.identity.claim.metadata.mgt.model.AttributeMapping)5 AttributeMappingDTO (org.wso2.carbon.identity.claim.metadata.mgt.stub.dto.AttributeMappingDTO)5 LocalClaimDTO (org.wso2.carbon.identity.claim.metadata.mgt.stub.dto.LocalClaimDTO)5 ArrayList (java.util.ArrayList)4 AttributeMappingDTO (org.wso2.carbon.identity.claim.metadata.mgt.dto.AttributeMappingDTO)3 ClaimPropertyDTO (org.wso2.carbon.identity.claim.metadata.mgt.dto.ClaimPropertyDTO)3 LocalClaim (org.wso2.carbon.identity.claim.metadata.mgt.model.LocalClaim)3 ClaimPropertyDTO (org.wso2.carbon.identity.claim.metadata.mgt.stub.dto.ClaimPropertyDTO)3 Map (java.util.Map)2 LocalClaimDTO (org.wso2.carbon.identity.claim.metadata.mgt.dto.LocalClaimDTO)2 ExternalClaimDTO (org.wso2.carbon.identity.claim.metadata.mgt.stub.dto.ExternalClaimDTO)2 AttributeMappingDTO (org.wso2.carbon.identity.rest.api.server.claim.management.v1.dto.AttributeMappingDTO)2 List (java.util.List)1 Test (org.testng.annotations.Test)1 LocalClaimResDTO (org.wso2.carbon.identity.rest.api.server.claim.management.v1.dto.LocalClaimResDTO)1 ISIntegrationTest (org.wso2.identity.integration.common.utils.ISIntegrationTest)1