Search in sources :

Example 1 with ClaimAttributeDTO

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

Example 2 with ClaimAttributeDTO

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

the class ClaimAdminService method convertClaimMappingDTOToClaimMapping.

private ClaimMapping convertClaimMappingDTOToClaimMapping(ClaimMappingDTO claimMappingDTO) {
    ClaimMapping claimMapping = new ClaimMapping(convertClaimDTOToClaim(claimMappingDTO.getClaim()), claimMappingDTO.getMappedAttribute());
    ClaimAttributeDTO[] attributes = claimMappingDTO.getMappedAttributes();
    if (attributes != null) {
        for (ClaimAttributeDTO attribute : attributes) {
            if (attribute.getDomainName() != null) {
                claimMapping.setMappedAttribute(attribute.getDomainName(), attribute.getAttributeName());
            }
        }
    }
    return claimMapping;
}
Also used : ClaimMapping(org.wso2.carbon.user.api.ClaimMapping) ClaimAttributeDTO(org.wso2.carbon.claim.mgt.dto.ClaimAttributeDTO)

Example 3 with ClaimAttributeDTO

use of org.wso2.carbon.claim.mgt.stub.dto.ClaimAttributeDTO in project product-is by wso2.

the class ClaimManagementServiceTestCase method testUpdateCliamMapping.

@Test(alwaysRun = true, description = "Update claim mapping", dependsOnMethods = "testAddNewCliamMapping")
public void testUpdateCliamMapping() {
    ClaimMappingDTO mapping = new ClaimMappingDTO();
    ClaimDTO claim = new ClaimDTO();
    claim.setClaimUri(CLAIM_URI_NEW);
    claim.setDisplayTag(DISPLAY_NAME_NEW);
    claim.setDescription(DESCRIPTION_NEW);
    claim.setDialectURI(DIALECT);
    claim.setRegEx(REGEX);
    claim.setDisplayOrder(DISPLAY_ORDER);
    claim.setRequired(REQUIRED);
    claim.setSupportedByDefault(SUPPORTED);
    claim.setReadOnly(READONLY);
    mapping.setClaim(claim);
    if (ATTRIBUTE != null) {
        String[] attributes = ATTRIBUTE.split(";");
        List<ClaimAttributeDTO> attrList = new ArrayList<ClaimAttributeDTO>();
        for (int i = 0; i < attributes.length; i++) {
            int index = 0;
            if ((index = attributes[i].indexOf("/")) > 1 && attributes[i].indexOf("/") == attributes[i].lastIndexOf("/")) {
                String domain = attributes[i].substring(0, index);
                String attrName = attributes[i].substring(index + 1);
                ClaimAttributeDTO attr = new ClaimAttributeDTO();
                attr.setAttributeName(attrName);
                attr.setDomainName(domain);
                attrList.add(attr);
            } else {
                mapping.setMappedAttribute(attributes[i]);
            }
        }
        if (attrList.size() > 0) {
            mapping.setMappedAttributes(attrList.toArray(new ClaimAttributeDTO[attrList.size()]));
        }
    }
    try {
        adminClient.updateClaimMapping(mapping);
        ClaimDialectDTO dialectDTO = adminClient.getClaimMappingByDialect(DIALECT);
        Assert.assertNotNull(dialectDTO, "Claim mapping adding failed.");
        for (ClaimMappingDTO mappingDTO : dialectDTO.getClaimMappings()) {
            if (CLAIM_URI_NEW.equals(mappingDTO.getClaim().getClaimUri())) {
                Assert.assertEquals(DESCRIPTION_NEW, mappingDTO.getClaim().getDescription(), "Claim mapping update failed.");
                Assert.assertEquals(DISPLAY_NAME_NEW, mappingDTO.getClaim().getDisplayTag(), "Claim mapping update failed.");
                break;
            }
        }
    } catch (Exception e) {
        Assert.fail("Error while trying to update claim mapping", e);
    }
}
Also used : ClaimMappingDTO(org.wso2.carbon.claim.mgt.stub.dto.ClaimMappingDTO) ClaimDTO(org.wso2.carbon.claim.mgt.stub.dto.ClaimDTO) ArrayList(java.util.ArrayList) ClaimAttributeDTO(org.wso2.carbon.claim.mgt.stub.dto.ClaimAttributeDTO) ClaimDialectDTO(org.wso2.carbon.claim.mgt.stub.dto.ClaimDialectDTO) ISIntegrationTest(org.wso2.identity.integration.common.utils.ISIntegrationTest) Test(org.testng.annotations.Test)

Example 4 with ClaimAttributeDTO

use of org.wso2.carbon.claim.mgt.stub.dto.ClaimAttributeDTO in project product-is by wso2.

the class ClaimManagementServiceTestCase method testAddNewCliamMapping.

@Test(alwaysRun = true, description = "Add new claim mapping dialect", dependsOnMethods = "testAddNewCliamDialect")
public void testAddNewCliamMapping() {
    ClaimMappingDTO mapping = new ClaimMappingDTO();
    ClaimDTO claim = new ClaimDTO();
    claim.setClaimUri(CLAIM_URI_NEW);
    claim.setDisplayTag("Test1");
    claim.setDescription("Test1");
    claim.setDialectURI(DIALECT);
    claim.setRegEx(REGEX);
    claim.setDisplayOrder(DISPLAY_ORDER);
    claim.setRequired(REQUIRED);
    claim.setSupportedByDefault(SUPPORTED);
    claim.setReadOnly(READONLY);
    mapping.setClaim(claim);
    if (ATTRIBUTE != null) {
        String[] attributes = ATTRIBUTE.split(";");
        List<ClaimAttributeDTO> attrList = new ArrayList<ClaimAttributeDTO>();
        for (int i = 0; i < attributes.length; i++) {
            int index = 0;
            if ((index = attributes[i].indexOf("/")) > 1) {
                String domain = attributes[i].substring(0, index);
                String attrName = attributes[i].substring(index + 1);
                if (domain != null) {
                    ClaimAttributeDTO attr = new ClaimAttributeDTO();
                    attr.setAttributeName(attrName);
                    attr.setDomainName(domain);
                    attrList.add(attr);
                }
            } else {
                ClaimAttributeDTO attr = new ClaimAttributeDTO();
                attr.setAttributeName(attributes[i]);
                attr.setDomainName(null);
                attrList.add(attr);
            }
        }
        if (attrList.size() > 0) {
            mapping.setMappedAttributes(attrList.toArray(new ClaimAttributeDTO[attrList.size()]));
        }
    }
    try {
        adminClient.addNewClaimMapping(mapping);
        ClaimDialectDTO dialectDTO = adminClient.getClaimMappingByDialect(DIALECT);
        Assert.assertNotNull(dialectDTO, "Claim dialect adding failed.");
        String dialectURI = null;
        for (ClaimMappingDTO mappingDTO : dialectDTO.getClaimMappings()) {
            if (CLAIM_URI_NEW.equals(mappingDTO.getClaim().getClaimUri())) {
                dialectURI = mappingDTO.getClaim().getDialectURI();
            }
        }
        Assert.assertNotNull(dialectURI, "Error occured while adding claim mapping.");
    } catch (Exception e) {
        Assert.fail("Error while trying to add new claim dialect", e);
    }
}
Also used : ClaimMappingDTO(org.wso2.carbon.claim.mgt.stub.dto.ClaimMappingDTO) ClaimDTO(org.wso2.carbon.claim.mgt.stub.dto.ClaimDTO) ArrayList(java.util.ArrayList) ClaimAttributeDTO(org.wso2.carbon.claim.mgt.stub.dto.ClaimAttributeDTO) ClaimDialectDTO(org.wso2.carbon.claim.mgt.stub.dto.ClaimDialectDTO) ISIntegrationTest(org.wso2.identity.integration.common.utils.ISIntegrationTest) Test(org.testng.annotations.Test)

Example 5 with ClaimAttributeDTO

use of org.wso2.carbon.claim.mgt.stub.dto.ClaimAttributeDTO in project product-is by wso2.

the class ClaimManagementServiceTestCase method testAddNewCliamDialect.

@Test(alwaysRun = true, description = "Add new claim dialect")
public void testAddNewCliamDialect() {
    ClaimMappingDTO mapping = new ClaimMappingDTO();
    ClaimDTO claim = new ClaimDTO();
    claim.setClaimUri(CLAIM_URI);
    claim.setDisplayTag(DISPLAY_NAME);
    claim.setDescription(DESCRIPTION);
    claim.setDialectURI(DIALECT);
    claim.setRegEx(REGEX);
    claim.setDisplayOrder(DISPLAY_ORDER);
    claim.setRequired(REQUIRED);
    claim.setSupportedByDefault(SUPPORTED);
    claim.setReadOnly(READONLY);
    mapping.setClaim(claim);
    if (ATTRIBUTE != null) {
        String[] attributes = ATTRIBUTE.split(";");
        List<ClaimAttributeDTO> attrList = new ArrayList<ClaimAttributeDTO>();
        for (int i = 0; i < attributes.length; i++) {
            int index = 0;
            if ((index = attributes[i].indexOf("/")) > 1) {
                String domain = attributes[i].substring(0, index);
                String attrName = attributes[i].substring(index + 1);
                if (domain != null) {
                    ClaimAttributeDTO attr = new ClaimAttributeDTO();
                    attr.setAttributeName(attrName);
                    attr.setDomainName(domain);
                    attrList.add(attr);
                }
            } else {
                ClaimAttributeDTO attr = new ClaimAttributeDTO();
                attr.setAttributeName(attributes[i]);
                attr.setDomainName(null);
                attrList.add(attr);
            }
        }
        if (attrList.size() > 0) {
            mapping.setMappedAttributes(attrList.toArray(new ClaimAttributeDTO[attrList.size()]));
        }
    }
    try {
        ClaimDialectDTO dialectDTO = new ClaimDialectDTO();
        dialectDTO.addClaimMappings(mapping);
        dialectDTO.setDialectURI(DIALECT);
        dialectDTO.setUserStore(STORE);
        adminClient.addNewClaimDialect(dialectDTO);
        dialectDTO = adminClient.getClaimMappingByDialect(DIALECT);
        Assert.assertNotNull(dialectDTO, "Error occured while adding claim dialect.");
    } catch (Exception e) {
        Assert.fail("Error while trying to add new claim dialect", e);
    }
}
Also used : ClaimMappingDTO(org.wso2.carbon.claim.mgt.stub.dto.ClaimMappingDTO) ClaimDTO(org.wso2.carbon.claim.mgt.stub.dto.ClaimDTO) ArrayList(java.util.ArrayList) ClaimAttributeDTO(org.wso2.carbon.claim.mgt.stub.dto.ClaimAttributeDTO) ClaimDialectDTO(org.wso2.carbon.claim.mgt.stub.dto.ClaimDialectDTO) ISIntegrationTest(org.wso2.identity.integration.common.utils.ISIntegrationTest) Test(org.testng.annotations.Test)

Aggregations

ArrayList (java.util.ArrayList)3 Test (org.testng.annotations.Test)3 ClaimAttributeDTO (org.wso2.carbon.claim.mgt.stub.dto.ClaimAttributeDTO)3 ClaimDTO (org.wso2.carbon.claim.mgt.stub.dto.ClaimDTO)3 ClaimDialectDTO (org.wso2.carbon.claim.mgt.stub.dto.ClaimDialectDTO)3 ClaimMappingDTO (org.wso2.carbon.claim.mgt.stub.dto.ClaimMappingDTO)3 ISIntegrationTest (org.wso2.identity.integration.common.utils.ISIntegrationTest)3 ClaimAttributeDTO (org.wso2.carbon.claim.mgt.dto.ClaimAttributeDTO)2 HashMap (java.util.HashMap)1 Map (java.util.Map)1 ClaimMappingDTO (org.wso2.carbon.claim.mgt.dto.ClaimMappingDTO)1 ClaimMapping (org.wso2.carbon.user.api.ClaimMapping)1