Search in sources :

Example 1 with HybridRoleManager

use of org.wso2.carbon.user.core.hybrid.HybridRoleManager in project carbon-identity-framework by wso2.

the class MockRealm method init.

@Override
public void init(RealmConfiguration realmConfiguration, Map<String, ClaimMapping> claimMappingMap, Map<String, ProfileConfiguration> map1, int tenantId) throws UserStoreException {
    this.realmConfiguration = realmConfiguration;
    this.tenantId = tenantId;
    DataSource dataSource = MockInitialContextFactory.initializeDatasource(UM_DB_JNDI_NAME, this.getClass(), new String[] { UM_DB_SQL_FILE });
    userStoreManager = new MockUserStoreManager(dataSource);
    ((MockUserStoreManager) this.userStoreManager).setRealmConfiguration(this.realmConfiguration);
    claimManager = new MockClaimManager(claimMappingMap);
    ((MockUserStoreManager) this.userStoreManager).setClaimManager(this.claimManager);
    HybridRoleManager hybridRoleManager = new MockHybridRoleManager(dataSource, tenantId, realmConfiguration, this);
    ((MockUserStoreManager) this.userStoreManager).setHybridRoleManager(hybridRoleManager);
}
Also used : HybridRoleManager(org.wso2.carbon.user.core.hybrid.HybridRoleManager) DataSource(javax.sql.DataSource)

Example 2 with HybridRoleManager

use of org.wso2.carbon.user.core.hybrid.HybridRoleManager in project carbon-identity-framework by wso2.

the class UserRealmProxyTest method testGetAllRolesNames.

@Test
public void testGetAllRolesNames() throws Exception {
    Mockito.when(realm.getUserStoreManager()).thenReturn(userStoreManagerWithAb);
    HybridRoleManager hybridRoleManager = mock(HybridRoleManager.class);
    Object cc = userStoreManagerWithAb;
    Field f1 = cc.getClass().getSuperclass().getDeclaredField("hybridRoleManager");
    f1.setAccessible(true);
    f1.set(cc, hybridRoleManager);
    String[] test = { "role3x", "role4x" };
    Mockito.when(hybridRoleManager.getHybridRoles("role")).thenReturn(test);
    Mockito.when(((AbstractUserStoreManager) userStoreManagerWithAb).getSharedRoleNames("role", 10)).thenReturn(new String[] { "role1", "role2" });
    Mockito.when(((AbstractUserStoreManager) userStoreManagerWithAb).getRoleNames("role", 10, true, true, true)).thenReturn(null);
    FlaggedName[] roleList = userRealmProxy.getAllRolesNames("role", 10);
    Assert.assertEquals(roleList.length, 3);
}
Also used : Field(java.lang.reflect.Field) HybridRoleManager(org.wso2.carbon.user.core.hybrid.HybridRoleManager) FlaggedName(org.wso2.carbon.user.mgt.common.FlaggedName) AbstractUserStoreManager(org.wso2.carbon.user.core.common.AbstractUserStoreManager) Mockito.anyString(org.mockito.Mockito.anyString) Test(org.testng.annotations.Test) BeforeTest(org.testng.annotations.BeforeTest) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 3 with HybridRoleManager

use of org.wso2.carbon.user.core.hybrid.HybridRoleManager in project carbon-identity-framework by wso2.

the class UserRealmProxyTest method testGetRolesOfUser.

@Test(dataProvider = "userListCount")
public void testGetRolesOfUser(int listCount, int assertCount) throws Exception {
    Mockito.when(realm.getUserStoreManager()).thenReturn(userStoreManagerWithAb);
    Mockito.when(((AbstractUserStoreManager) userStoreManagerWithAb).getRoleListOfUser("admin2")).thenReturn(new String[] { "PRIMARY/role1", "PRIMARY/role2" });
    Object cc = userStoreManagerWithAb;
    HybridRoleManager hybridRoleManager = mock(HybridRoleManager.class);
    Field f1 = cc.getClass().getSuperclass().getDeclaredField("hybridRoleManager");
    f1.setAccessible(true);
    f1.set(cc, hybridRoleManager);
    String[] test = { "PRIMARY/role3", "PRIMARY/role4" };
    String[] test2 = { "role3", "role4" };
    Mockito.when(((AbstractUserStoreManager) userStoreManagerWithAb).getRoleNames("role", listCount, true, true, true)).thenReturn(null);
    Mockito.when(hybridRoleManager.getHybridRoles("role")).thenReturn(test);
    FlaggedName[] flaggedNames = userRealmProxy.getRolesOfUser("admin2", "role", listCount);
    Assert.assertEquals(flaggedNames.length, assertCount);
}
Also used : Field(java.lang.reflect.Field) HybridRoleManager(org.wso2.carbon.user.core.hybrid.HybridRoleManager) FlaggedName(org.wso2.carbon.user.mgt.common.FlaggedName) AbstractUserStoreManager(org.wso2.carbon.user.core.common.AbstractUserStoreManager) Mockito.anyString(org.mockito.Mockito.anyString) Test(org.testng.annotations.Test) BeforeTest(org.testng.annotations.BeforeTest) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Aggregations

HybridRoleManager (org.wso2.carbon.user.core.hybrid.HybridRoleManager)3 Field (java.lang.reflect.Field)2 Mockito.anyString (org.mockito.Mockito.anyString)2 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)2 BeforeTest (org.testng.annotations.BeforeTest)2 Test (org.testng.annotations.Test)2 AbstractUserStoreManager (org.wso2.carbon.user.core.common.AbstractUserStoreManager)2 FlaggedName (org.wso2.carbon.user.mgt.common.FlaggedName)2 DataSource (javax.sql.DataSource)1