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);
}
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);
}
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);
}
Aggregations