Search in sources :

Example 11 with ClaimDTO

use of org.wso2.micro.gateway.jwt.generator.ClaimDTO 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 12 with ClaimDTO

use of org.wso2.micro.gateway.jwt.generator.ClaimDTO in project product-is by wso2.

the class OpenIDUserProfileTestCase method testUserProfile.

@Test(alwaysRun = true, description = "Test reading user profile and claims from the profile")
public void testUserProfile() {
    String openId = Util.getDefaultOpenIDIdentifier(userName);
    OpenIDParameterDTO[] openidRequestParams = Util.getDummyOpenIDParameterDTOArray();
    OpenIDUserProfileDTO[] userProfiles = null;
    // reading back user profiles
    try {
        userProfiles = openidServiceClient.getUserProfiles(openId, openidRequestParams);
    } catch (Exception e) {
        Assert.fail("Error while reading user profiles", e);
    }
    Assert.assertEquals(userProfiles[0].getProfileName(), profileName);
    Assert.assertNotNull(userProfiles[0].getClaimSet());
    // we expect 4 claims : email, firstname, lastname and country
    Assert.assertEquals(userProfiles[0].getClaimSet().length, 4);
    for (OpenIDClaimDTO claimDTO : userProfiles[0].getClaimSet()) {
        if (emailClaimURI.equals(claimDTO.getClaimUri())) {
            Assert.assertTrue(claimDTO.getClaimValue().contains(emailClaimValue));
        } else if (firstNameClaimURI.equals(claimDTO.getClaimUri())) {
            Assert.assertTrue(claimDTO.getClaimValue().contains(firstNameClaimValue));
        } else if (lastNameClaimURI.equals(claimDTO.getClaimUri())) {
            Assert.assertTrue(claimDTO.getClaimValue().contains(lastNameClaimValue));
        } else if (countryClaimURI.equals(claimDTO.getClaimUri())) {
            Assert.assertTrue(claimDTO.getClaimValue().contains(countryClaimValue));
        } else {
            Assert.fail("Invalid claim returned");
        }
    }
    // Login with created user
    try {
        openidServiceClient.authenticateWithOpenID(openId, password);
    } catch (Exception e) {
        Assert.fail("Error while authenticating", e);
    }
}
Also used : OpenIDParameterDTO(org.wso2.carbon.identity.provider.openid.stub.dto.OpenIDParameterDTO) OpenIDClaimDTO(org.wso2.carbon.identity.provider.openid.stub.dto.OpenIDClaimDTO) OpenIDUserProfileDTO(org.wso2.carbon.identity.provider.openid.stub.dto.OpenIDUserProfileDTO) ISIntegrationTest(org.wso2.identity.integration.common.utils.ISIntegrationTest)

Example 13 with ClaimDTO

use of org.wso2.micro.gateway.jwt.generator.ClaimDTO in project product-is by wso2.

the class ClaimManagementServiceClient method addNewClaimMapping.

public void addNewClaimMapping(String dialectURI, String claimUri, String description, String mappedAttribute) throws ClaimManagementServiceClaimManagementException, RemoteException {
    ClaimMappingDTO claimMappingDTO = new ClaimMappingDTO();
    ClaimDTO claimDTO = new ClaimDTO();
    claimDTO.setDialectURI(dialectURI);
    claimDTO.setClaimUri(claimUri);
    claimDTO.setDescription(description);
    claimMappingDTO.setClaim(claimDTO);
    claimMappingDTO.setMappedAttribute(mappedAttribute);
    claimManagementServiceStub.addNewClaimMapping(claimMappingDTO);
}
Also used : ClaimMappingDTO(org.wso2.carbon.claim.mgt.stub.dto.ClaimMappingDTO) ClaimDTO(org.wso2.carbon.claim.mgt.stub.dto.ClaimDTO)

Example 14 with ClaimDTO

use of org.wso2.micro.gateway.jwt.generator.ClaimDTO in project product-is by wso2.

the class RemoteUserStoreManagerServiceTestCase method testGetUserClaimValues.

@Test(priority = 5, groups = "wso2.is", description = "Test getUserClaimValues operation")
public void testGetUserClaimValues() throws RemoteUserStoreManagerServiceUserStoreExceptionException, RemoteException {
    ClaimDTO[] claims = remoteUserStoreManagerClient.getUserClaimValues(user2, null);
    Assert.assertNotNull(claims, "User claims retrieval failed");
    Map<String, ClaimDTO> claimMap = new HashMap<String, ClaimDTO>();
    for (ClaimDTO claim : claims) {
        claimMap.put(claim.getClaimUri(), claim);
    }
    // verify newly added claims are included in list
    Assert.assertTrue(claimMap.containsKey(claimURI1), "Claim not found :" + claimURI1);
    Assert.assertEquals(claimMap.get(claimURI1).getValue(), claimValue1, "Claim deviate from added value");
    Assert.assertTrue(claimMap.containsKey(claimURI2), "Claim not found :" + claimURI2);
    Assert.assertEquals(claimMap.get(claimURI2).getValue(), claimValue2, "Claim deviate from added value");
    Assert.assertTrue(claimMap.containsKey(claimURI3), "Claim not found :" + claimURI3);
    Assert.assertEquals(claimMap.get(claimURI3).getValue(), claimValue3, "Claim deviate from added value");
}
Also used : ClaimDTO(org.wso2.carbon.um.ws.api.stub.ClaimDTO) HashMap(java.util.HashMap) ISIntegrationTest(org.wso2.identity.integration.common.utils.ISIntegrationTest) Test(org.testng.annotations.Test)

Example 15 with ClaimDTO

use of org.wso2.micro.gateway.jwt.generator.ClaimDTO in project product-is by wso2.

the class UUIDUserStoreManagerService method convertClaimToClaimDTO.

private ClaimDTO[] convertClaimToClaimDTO(List<Claim> claims) {
    List<ClaimDTO> ClaimDTOs = new ArrayList<>();
    for (Claim claim : claims) {
        ClaimDTO claimDTO = new ClaimDTO();
        claimDTO.setClaimUri(claim.getClaimUri());
        claimDTO.setValue(claim.getValue());
        claimDTO.setDescription(claim.getDescription());
        claimDTO.setDialectURI(claim.getDialectURI());
        claimDTO.setDisplayOrder(claim.getDisplayOrder());
        claimDTO.setRegEx(claim.getRegEx());
        claimDTO.setSupportedByDefault(claim.isSupportedByDefault());
        claimDTO.setRequired(claim.isRequired());
        ClaimDTOs.add(claimDTO);
    }
    return ClaimDTOs.toArray(new ClaimDTO[0]);
}
Also used : ClaimDTO(org.wso2.carbon.identity.test.integration.service.dao.ClaimDTO) ArrayList(java.util.ArrayList) Claim(org.wso2.carbon.user.core.claim.Claim)

Aggregations

ArrayList (java.util.ArrayList)9 ClaimDTO (org.wso2.carbon.claim.mgt.stub.dto.ClaimDTO)7 ClaimMappingDTO (org.wso2.carbon.claim.mgt.stub.dto.ClaimMappingDTO)7 ISIntegrationTest (org.wso2.identity.integration.common.utils.ISIntegrationTest)5 Test (org.testng.annotations.Test)4 ClaimDialectDTO (org.wso2.carbon.claim.mgt.stub.dto.ClaimDialectDTO)4 Claim (org.wso2.carbon.user.api.Claim)4 HashMap (java.util.HashMap)3 ClaimAttributeDTO (org.wso2.carbon.claim.mgt.stub.dto.ClaimAttributeDTO)3 ClaimDTO (org.wso2.carbon.identity.test.integration.service.stub.ClaimDTO)3 ClaimDTO (org.wso2.carbon.identity.user.endpoint.dto.ClaimDTO)3 ClaimDTO (org.wso2.carbon.um.ws.api.stub.ClaimDTO)3 UserIdentityClaimDTO (org.wso2.carbon.identity.mgt.dto.UserIdentityClaimDTO)2 ClaimDTO (org.wso2.carbon.identity.recovery.endpoint.dto.ClaimDTO)2 ClaimValue (org.wso2.carbon.identity.test.integration.service.stub.ClaimValue)2 File (java.io.File)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 Map (java.util.Map)1 BPackage (org.ballerinalang.jvm.types.BPackage)1 BArray (org.ballerinalang.jvm.values.api.BArray)1