Search in sources :

Example 86 with ClaimMapping

use of org.wso2.carbon.identity.application.common.model.xsd.ClaimMapping in project product-is by wso2.

the class TestPassiveSTS method testAddClaimConfiguration.

@Test(alwaysRun = true, description = "4.1.5.3", dependsOnMethods = { "testUpdateSP" })
public void testAddClaimConfiguration() throws Exception {
    serviceProvider.getClaimConfig().setClaimMappings(getClaimMappings());
    appMgtclient.updateApplicationData(serviceProvider);
    ServiceProvider updatedServiceProvider = appMgtclient.getApplication(SERVICE_PROVIDER_NAME);
    ClaimConfig updatedClaimConfig = updatedServiceProvider.getClaimConfig();
    Assert.assertNotNull(updatedClaimConfig.getClaimMappings(), "Claim mapping is null. Claim mapping creation failed.");
    for (ClaimMapping claimMapping : getClaimMappings()) {
        boolean success = false;
        for (ClaimMapping updatedClaimMapping : updatedClaimConfig.getClaimMappings()) {
            if (claimMapping.getLocalClaim().getClaimUri().equals(updatedClaimMapping.getLocalClaim().getClaimUri())) {
                success = true;
                break;
            }
        }
        Assert.assertTrue(success, "Failed to set claim uri: " + claimMapping.getLocalClaim().getClaimUri());
    }
}
Also used : ClaimMapping(org.wso2.carbon.identity.application.common.model.xsd.ClaimMapping) ClaimConfig(org.wso2.carbon.identity.application.common.model.xsd.ClaimConfig) ServiceProvider(org.wso2.carbon.identity.application.common.model.xsd.ServiceProvider) Test(org.testng.annotations.Test)

Example 87 with ClaimMapping

use of org.wso2.carbon.identity.application.common.model.xsd.ClaimMapping in project product-is by wso2.

the class SSOUtil method addClaimMapping.

private static void addClaimMapping(List<ClaimMapping> claimMappingList, String emailClaimUri) {
    Claim emailClaim = new Claim();
    emailClaim.setClaimUri(emailClaimUri);
    ClaimMapping emailClaimMapping = new ClaimMapping();
    emailClaimMapping.setRequested(true);
    emailClaimMapping.setLocalClaim(emailClaim);
    emailClaimMapping.setRemoteClaim(emailClaim);
    claimMappingList.add(emailClaimMapping);
}
Also used : ClaimMapping(org.wso2.carbon.identity.application.common.model.xsd.ClaimMapping) Claim(org.wso2.carbon.identity.application.common.model.xsd.Claim)

Example 88 with ClaimMapping

use of org.wso2.carbon.identity.application.common.model.xsd.ClaimMapping in project identity-inbound-provisioning-scim2 by wso2-extensions.

the class SCIMUserManagerTest method data.

@DataProvider(name = "ClaimData")
public Object[][] data() {
    String coreClaimUri1;
    String testMappedAttributesCore1;
    String coreClaimUri2;
    String testMappedAttributesCore2;
    String userClaimUri1;
    String testMappedAttributesUser1;
    String userClaimUri2;
    String testMappedAttributesUser2;
    Claim claim1 = new Claim();
    Claim claim2 = new Claim();
    Claim claim3 = new Claim();
    Claim claim4 = new Claim();
    coreClaimUri1 = "testCoreClaimURI1";
    claim1.setClaimUri(coreClaimUri1);
    testMappedAttributesCore1 = "MappedAttributesCore1";
    coreClaimUri2 = "testCoreClaimURI2";
    claim2.setClaimUri(coreClaimUri2);
    testMappedAttributesCore2 = "MappedAttributesCore2";
    userClaimUri1 = "testUserClaimURI1";
    claim3.setClaimUri(userClaimUri1);
    testMappedAttributesUser1 = "MappedAttributesUser1";
    userClaimUri2 = "testUserClaimURI2";
    claim4.setClaimUri(userClaimUri2);
    testMappedAttributesUser2 = "MappedAttributesUser2";
    ClaimMapping cMap1 = new ClaimMapping(claim1, testMappedAttributesCore1);
    ClaimMapping cMap2 = new ClaimMapping(claim2, testMappedAttributesCore2);
    ClaimMapping cMap3 = new ClaimMapping(claim3, testMappedAttributesUser1);
    ClaimMapping cMap4 = new ClaimMapping(claim4, testMappedAttributesUser2);
    ClaimMapping[] coreClaims = new ClaimMapping[] { cMap1, cMap2, cMap3, cMap4 };
    HashMap<String, Boolean> requiredAttributes = new HashMap<String, Boolean>() {

        {
            put("test1.test", true);
        }
    };
    String[] roles = new String[] { "role1", "role2", "role3" };
    return new Object[][] { { coreClaims, requiredAttributes, roles } };
}
Also used : ClaimMapping(org.wso2.carbon.user.api.ClaimMapping) HashMap(java.util.HashMap) Matchers.anyString(org.mockito.Matchers.anyString) Matchers.anyBoolean(org.mockito.Matchers.anyBoolean) ExternalClaim(org.wso2.carbon.identity.claim.metadata.mgt.model.ExternalClaim) LocalClaim(org.wso2.carbon.identity.claim.metadata.mgt.model.LocalClaim) Claim(org.wso2.carbon.user.api.Claim) DataProvider(org.testng.annotations.DataProvider)

Example 89 with ClaimMapping

use of org.wso2.carbon.identity.application.common.model.xsd.ClaimMapping in project identity-inbound-provisioning-scim2 by wso2-extensions.

the class SCIMUserManagerTest method getTestClaimMappings.

private ClaimMapping[] getTestClaimMappings() {
    ClaimMapping[] claimMappings = new ClaimMapping[3];
    Claim claim1 = new Claim();
    claim1.setClaimUri("urn:ietf:params:scim:schemas:core:2.0:User:userName");
    ClaimMapping claimMapping1 = new ClaimMapping();
    claimMapping1.setClaim(claim1);
    claimMapping1.setMappedAttribute("PRIMARY", "http://wso2.org/claims/username");
    claimMappings[0] = claimMapping1;
    Claim claim2 = new Claim();
    claim2.setClaimUri("urn:ietf:params:scim:schemas:core:2.0:User:emails");
    ClaimMapping claimMapping2 = new ClaimMapping();
    claimMapping2.setClaim(claim2);
    claimMapping2.setMappedAttribute("PRIMARY", "http://wso2.org/claims/emailaddress");
    claimMappings[1] = claimMapping2;
    Claim claim3 = new Claim();
    claim3.setClaimUri("urn:ietf:params:scim:schemas:core:2.0:User:name.givenName");
    ClaimMapping claimMapping3 = new ClaimMapping();
    claimMapping3.setClaim(claim3);
    claimMapping3.setMappedAttribute("PRIMARY", "http://wso2.org/claims/givenname");
    claimMappings[2] = claimMapping3;
    return claimMappings;
}
Also used : ClaimMapping(org.wso2.carbon.user.api.ClaimMapping) ExternalClaim(org.wso2.carbon.identity.claim.metadata.mgt.model.ExternalClaim) LocalClaim(org.wso2.carbon.identity.claim.metadata.mgt.model.LocalClaim) Claim(org.wso2.carbon.user.api.Claim)

Example 90 with ClaimMapping

use of org.wso2.carbon.identity.application.common.model.xsd.ClaimMapping in project identity-inbound-provisioning-scim2 by wso2-extensions.

the class SCIMUserManagerTest method testFilteringUsersWithGET.

@Test(dataProvider = "userInfoForFiltering")
public void testFilteringUsersWithGET(List<org.wso2.carbon.user.core.common.User> users, String filter, int expectedResultCount, List<org.wso2.carbon.user.core.common.User> filteredUsers) throws Exception {
    Map<String, String> scimToLocalClaimMap = new HashMap<>();
    scimToLocalClaimMap.put("urn:ietf:params:scim:schemas:core:2.0:User:userName", "http://wso2.org/claims/username");
    scimToLocalClaimMap.put("urn:ietf:params:scim:schemas:core:2.0:id", "http://wso2.org/claims/userid");
    scimToLocalClaimMap.put("urn:ietf:params:scim:schemas:core:2.0:User:emails", "http://wso2.org/claims/emailaddress");
    scimToLocalClaimMap.put("urn:ietf:params:scim:schemas:core:2.0:User:name.givenName", "http://wso2.org/claims/givenname");
    mockStatic(SCIMCommonUtils.class);
    when(SCIMCommonUtils.getSCIMtoLocalMappings()).thenReturn(scimToLocalClaimMap);
    when(SCIMCommonUtils.convertLocalToSCIMDialect(anyMap(), anyMap())).thenReturn(new HashMap<String, String>() {

        {
            put(SCIMConstants.CommonSchemaConstants.ID_URI, "1f70378a-69bb-49cf-aa51-a0493c09110c");
        }
    });
    mockedUserStoreManager = PowerMockito.mock(AbstractUserStoreManager.class);
    when(mockedUserStoreManager.getUserListWithID("http://wso2.org/claims/userid", "*", null)).thenReturn(users);
    when(mockedUserStoreManager.getUserListWithID("http://wso2.org/claims/givenname", "testUser", "default")).thenReturn(filteredUsers);
    when(mockedUserStoreManager.getUserListWithID(any(Condition.class), anyString(), anyString(), anyInt(), anyInt(), anyString(), anyString())).thenReturn(filteredUsers);
    when(mockedUserStoreManager.getRoleListOfUserWithID(anyString())).thenReturn(new ArrayList<>());
    whenNew(GroupDAO.class).withAnyArguments().thenReturn(mockedGroupDAO);
    when(mockedGroupDAO.listSCIMGroups(anyInt())).thenReturn(anySet());
    when(mockedUserStoreManager.getSecondaryUserStoreManager("PRIMARY")).thenReturn(mockedUserStoreManager);
    when(mockedUserStoreManager.isSCIMEnabled()).thenReturn(true);
    when(mockedUserStoreManager.getSecondaryUserStoreManager("SECONDARY")).thenReturn(secondaryUserStoreManager);
    when(secondaryUserStoreManager.isSCIMEnabled()).thenReturn(true);
    when(mockedUserStoreManager.getRealmConfiguration()).thenReturn(mockedRealmConfig);
    when(mockedRealmConfig.getUserStoreProperty(UserCoreConstants.RealmConfig.PROPERTY_MAX_USER_LIST)).thenReturn("100");
    mockStatic(IdentityTenantUtil.class);
    when(IdentityTenantUtil.getRealmService()).thenReturn(mockRealmService);
    when(mockRealmService.getBootstrapRealmConfiguration()).thenReturn(mockedRealmConfig);
    mockStatic(IdentityUtil.class);
    when(IdentityUtil.isGroupsVsRolesSeparationImprovementsEnabled()).thenReturn(false);
    ClaimMapping[] claimMappings = getTestClaimMappings();
    when(mockedClaimManager.getAllClaimMappings(anyString())).thenReturn(claimMappings);
    HashMap<String, Boolean> requiredClaimsMap = new HashMap<>();
    requiredClaimsMap.put("urn:ietf:params:scim:schemas:core:2.0:User:userName", false);
    SCIMUserManager scimUserManager = new SCIMUserManager(mockedUserStoreManager, mockedClaimManager);
    Node node = null;
    if (StringUtils.isNotBlank(filter)) {
        SCIMResourceTypeSchema schema = SCIMResourceSchemaManager.getInstance().getUserResourceSchema();
        FilterTreeManager filterTreeManager = new FilterTreeManager(filter, schema);
        node = filterTreeManager.buildTree();
    }
    List<Object> result = scimUserManager.listUsersWithGET(node, 1, null, null, null, null, requiredClaimsMap);
    assertEquals(expectedResultCount, result.size());
}
Also used : Condition(org.wso2.carbon.user.core.model.Condition) HashMap(java.util.HashMap) ExpressionNode(org.wso2.charon3.core.utils.codeutils.ExpressionNode) Node(org.wso2.charon3.core.utils.codeutils.Node) Matchers.anyString(org.mockito.Matchers.anyString) FilterTreeManager(org.wso2.charon3.core.utils.codeutils.FilterTreeManager) ClaimMapping(org.wso2.carbon.user.api.ClaimMapping) AbstractUserStoreManager(org.wso2.carbon.user.core.common.AbstractUserStoreManager) SCIMResourceTypeSchema(org.wso2.charon3.core.schema.SCIMResourceTypeSchema) Matchers.anyBoolean(org.mockito.Matchers.anyBoolean) Test(org.testng.annotations.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Aggregations

ClaimMapping (org.wso2.carbon.identity.application.common.model.ClaimMapping)108 HashMap (java.util.HashMap)60 ArrayList (java.util.ArrayList)52 ClaimConfig (org.wso2.carbon.identity.application.common.model.ClaimConfig)27 Map (java.util.Map)26 ServiceProvider (org.wso2.carbon.identity.application.common.model.ServiceProvider)24 ClaimMapping (org.wso2.carbon.identity.application.common.model.xsd.ClaimMapping)24 ClaimMapping (org.wso2.carbon.user.api.ClaimMapping)24 Claim (org.wso2.carbon.identity.application.common.model.Claim)23 Test (org.testng.annotations.Test)22 Claim (org.wso2.carbon.identity.application.common.model.xsd.Claim)21 LocalClaim (org.wso2.carbon.identity.claim.metadata.mgt.model.LocalClaim)21 AuthenticatedUser (org.wso2.carbon.identity.application.authentication.framework.model.AuthenticatedUser)20 IdentityApplicationManagementException (org.wso2.carbon.identity.application.common.IdentityApplicationManagementException)20 List (java.util.List)17 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)17 UserStoreException (org.wso2.carbon.user.api.UserStoreException)17 Matchers.anyString (org.mockito.Matchers.anyString)16 IdentityProvider (org.wso2.carbon.identity.application.common.model.IdentityProvider)13 ClaimMetadataException (org.wso2.carbon.identity.claim.metadata.mgt.exception.ClaimMetadataException)13