use of org.pentaho.platform.security.userroledao.service.UserRoleDaoUserRoleListService in project pentaho-platform by pentaho.
the class DirectoryResourceIT method beforeTest.
@Before
public void beforeTest() throws PlatformInitializationException {
mp = new MicroPlatform();
// used by DefaultPentahoJackrabbitAccessControlHelper
mp.defineInstance(IAuthorizationPolicy.class, authorizationPolicy);
mp.defineInstance(ITenantManager.class, tenantManager);
mp.define(ITenant.class, Tenant.class);
mp.defineInstance("roleAuthorizationPolicyRoleBindingDaoTarget", roleBindingDaoTarget);
mp.defineInstance(IRoleAuthorizationPolicyRoleBindingDao.class, roleBindingDaoTarget);
mp.defineInstance("tenantedUserNameUtils", tenantedUserNameUtils);
mp.defineInstance("tenantedRoleNameUtils", tenantedRoleNameUtils);
mp.defineInstance("repositoryAdminUsername", repositoryAdminUsername);
mp.define(IRoleAuthorizationPolicyRoleBindingDao.class, RoleAuthorizationPolicy.class, Scope.GLOBAL);
mp.define(ITenantManager.class, RepositoryTenantManager.class, Scope.GLOBAL);
mp.defineInstance("singleTenantAdminAuthorityName", new String("Administrator"));
mp.defineInstance("RepositoryFileProxyFactory", new RepositoryFileProxyFactory(this.testJcrTemplate, this.repositoryFileDao));
DefaultRepositoryVersionManager defaultRepositoryVersionManager = new DefaultRepositoryVersionManager();
defaultRepositoryVersionManager.setPlatformMimeResolver(new NameBaseMimeResolver());
mp.defineInstance(IRepositoryVersionManager.class, defaultRepositoryVersionManager);
UserRoleDaoUserDetailsService userDetailsService = new UserRoleDaoUserDetailsService();
userDetailsService.setUserRoleDao(userRoleDao);
List<String> systemRoles = new ArrayList<String>();
systemRoles.add("Admin");
List<String> extraRoles = Arrays.asList(new String[] { "Authenticated", "Anonymous" });
String adminRole = "Admin";
userRoleListService = new UserRoleDaoUserRoleListService(userRoleDao, userDetailsService, tenantedUserNameUtils, systemRoles, extraRoles, adminRole);
((UserRoleDaoUserRoleListService) userRoleListService).setUserRoleDao(userRoleDao);
((UserRoleDaoUserRoleListService) userRoleListService).setUserDetailsService(userDetailsService);
mp.defineInstance(IUserRoleListService.class, userRoleListService);
mp.start();
logout();
startupCalled = true;
SecurityContextHolder.setStrategyName(SecurityContextHolder.MODE_GLOBAL);
}
use of org.pentaho.platform.security.userroledao.service.UserRoleDaoUserRoleListService in project pentaho-platform by pentaho.
the class UserRoleDaoUserRoleListServiceIT method testGetAllUsernames.
@Test
public void testGetAllUsernames() {
loginAsSysTenantAdmin();
mainTenant_1 = tenantManager.createTenant(systemTenant, MAIN_TENANT_1, tenantAdminRoleName, tenantAuthenticatedRoleName, ANONYMOUS_ROLE_NAME);
userRoleDao.createUser(mainTenant_1, USERNAME_ADMIN, PASSWORD, "", new String[] { tenantAdminRoleName });
mainTenant_2 = tenantManager.createTenant(systemTenant, MAIN_TENANT_2, tenantAdminRoleName, tenantAuthenticatedRoleName, ANONYMOUS_ROLE_NAME);
userRoleDao.createUser(mainTenant_2, USERNAME_ADMIN, PASSWORD, "", new String[] { tenantAdminRoleName });
login(USERNAME_ADMIN, mainTenant_1, new String[] { tenantAdminRoleName, tenantAuthenticatedRoleName });
userRoleDao.createUser(mainTenant_1, USER_2, PASSWORD_2, USER_DESCRIPTION_2, null);
userRoleDao.createUser(mainTenant_1, USER_3, PASSWORD_3, USER_DESCRIPTION_3, null);
userRoleDao.createUser(null, userNameUtils.getPrincipleId(mainTenant_1, USER_4), PASSWORD_4, USER_DESCRIPTION_4, null);
userRoleDao.createUser(null, USER_5, PASSWORD_5, USER_DESCRIPTION_5, null);
userRoleDao.createUser(null, userNameUtils.getPrincipleId(mainTenant_1, USER_6), PASSWORD_6, USER_DESCRIPTION_6, null);
logout();
login(USERNAME_ADMIN, mainTenant_2, new String[] { tenantAdminRoleName, tenantAuthenticatedRoleName });
userRoleDao.createUser(mainTenant_2, USER_7, PASSWORD_7, USER_DESCRIPTION_7, null);
userRoleDao.createUser(null, USER_8, PASSWORD_8, USER_DESCRIPTION_8, null);
UserRoleDaoUserDetailsService userDetailsService = new UserRoleDaoUserDetailsService();
userDetailsService.setUserRoleDao(userRoleDao);
List<String> systemRoles = Arrays.asList(USERNAME_ADMIN);
List<String> extraRoles = Arrays.asList(AUTHENTICATED_ROLE_NAME, ANONYMOUS_ROLE_NAME);
String adminRole = USERNAME_ADMIN;
UserRoleDaoUserRoleListService service = new UserRoleDaoUserRoleListService(userRoleDao, userDetailsService, userNameUtils, systemRoles, extraRoles, adminRole);
service.setUserRoleDao(userRoleDao);
service.setUserDetailsService(userDetailsService);
logout();
login(USERNAME_ADMIN, mainTenant_1, new String[] { tenantAdminRoleName, tenantAuthenticatedRoleName });
List<String> allUserForDefaultTenant = service.getAllUsers();
List<String> allUserForTenant = service.getAllUsers(mainTenant_2);
assertEquals(5 + DEFAULT_USER_COUNT, allUserForDefaultTenant.size());
assertEquals(2 + DEFAULT_USER_COUNT, allUserForTenant.size());
logout();
login(USERNAME_ADMIN, mainTenant_2, new String[] { tenantAdminRoleName, tenantAuthenticatedRoleName });
allUserForDefaultTenant = service.getAllUsers();
allUserForTenant = service.getAllUsers(mainTenant_1);
assertTrue(allUserForDefaultTenant.size() == 2 + DEFAULT_USER_COUNT);
assertEquals(5 + DEFAULT_USER_COUNT, allUserForTenant.size());
allUserForTenant = service.getAllUsers(mainTenant_1);
assertEquals(5 + DEFAULT_USER_COUNT, allUserForTenant.size());
allUserForTenant = service.getAllUsers(mainTenant_2);
assertEquals(2 + DEFAULT_USER_COUNT, allUserForTenant.size());
logout();
login(USERNAME_ADMIN, mainTenant_1, new String[] { tenantAdminRoleName, tenantAuthenticatedRoleName });
allUserForTenant = service.getAllUsers(mainTenant_1);
assertEquals(5 + DEFAULT_USER_COUNT, allUserForTenant.size());
allUserForTenant = service.getAllUsers(mainTenant_2);
assertEquals(2 + DEFAULT_USER_COUNT, allUserForTenant.size());
cleanupUserAndRoles(mainTenant_1);
cleanupUserAndRoles(mainTenant_2);
}
use of org.pentaho.platform.security.userroledao.service.UserRoleDaoUserRoleListService in project pentaho-platform by pentaho.
the class UserRoleDaoUserRoleListServiceIT method testGetAuthoritiesForUser.
@Test
public void testGetAuthoritiesForUser() {
loginAsSysTenantAdmin();
mainTenant_1 = tenantManager.createTenant(systemTenant, MAIN_TENANT_1, tenantAdminRoleName, tenantAuthenticatedRoleName, ANONYMOUS_ROLE_NAME);
userRoleDao.createUser(mainTenant_1, USERNAME_ADMIN, PASSWORD, "", new String[] { tenantAdminRoleName });
mainTenant_2 = tenantManager.createTenant(systemTenant, MAIN_TENANT_2, tenantAdminRoleName, tenantAuthenticatedRoleName, ANONYMOUS_ROLE_NAME);
userRoleDao.createUser(mainTenant_2, USERNAME_ADMIN, PASSWORD, "", new String[] { tenantAdminRoleName });
login(USERNAME_ADMIN, mainTenant_1, new String[] { tenantAdminRoleName, tenantAuthenticatedRoleName });
userRoleDao.createUser(mainTenant_1, USER_2, PASSWORD_2, USER_DESCRIPTION_2, null);
userRoleDao.createUser(null, userNameUtils.getPrincipleId(mainTenant_1, USER_3), PASSWORD_3, USER_DESCRIPTION_3, null);
userRoleDao.createUser(null, USER_4, PASSWORD_4, USER_DESCRIPTION_4, null);
logout();
login(USERNAME_ADMIN, mainTenant_2, new String[] { tenantAdminRoleName, tenantAuthenticatedRoleName });
userRoleDao.createUser(mainTenant_2, USER_5, PASSWORD_5, USER_DESCRIPTION_5, null);
userRoleDao.createUser(null, userNameUtils.getPrincipleId(mainTenant_2, USER_6), PASSWORD_6, USER_DESCRIPTION_6, null);
logout();
login(USERNAME_ADMIN, mainTenant_1, new String[] { tenantAdminRoleName, tenantAuthenticatedRoleName });
userRoleDao.createRole(mainTenant_1, ROLE_1, ROLE_DESCRIPTION_1, null);
userRoleDao.createRole(null, roleNameUtils.getPrincipleId(mainTenant_1, ROLE_2), ROLE_DESCRIPTION_2, null);
userRoleDao.createRole(null, ROLE_3, ROLE_DESCRIPTION_3, null);
logout();
login(USERNAME_ADMIN, mainTenant_2, new String[] { tenantAdminRoleName, tenantAuthenticatedRoleName });
userRoleDao.createRole(mainTenant_2, ROLE_4, ROLE_DESCRIPTION_4, null);
userRoleDao.setUserRoles(null, USER_5, new String[] { ROLE_4 });
userRoleDao.setUserRoles(null, userNameUtils.getPrincipleId(mainTenant_2, USER_6), new String[] { ROLE_4 });
logout();
login(USERNAME_ADMIN, mainTenant_1, new String[] { tenantAdminRoleName, tenantAuthenticatedRoleName });
userRoleDao.setUserRoles(mainTenant_1, USER_2, new String[] { ROLE_1, ROLE_2, ROLE_3 });
List<String> systemRoles = Arrays.asList(USERNAME_ADMIN);
try {
userRoleDao.setUserRoles(mainTenant_1, USER_3, new String[] { ROLE_2, ROLE_3, ROLE_4 });
} catch (Throwable th) {
assertNotNull(th);
}
try {
userRoleDao.setUserRoles(mainTenant_1, USER_4, new String[] { ROLE_2, ROLE_4 });
fail("Exception should be thrown");
} catch (Throwable th) {
assertNotNull(th);
}
UserRoleDaoUserDetailsService userDetailsService = new UserRoleDaoUserDetailsService();
userDetailsService.setUserRoleDao(userRoleDao);
userDetailsService.setDefaultRole(tenantAuthenticatedRoleName);
List<String> extraRoles = Arrays.asList(AUTHENTICATED_ROLE_NAME, ANONYMOUS_ROLE_NAME);
String adminRole = USERNAME_ADMIN;
UserRoleDaoUserRoleListService service = new UserRoleDaoUserRoleListService(userRoleDao, userDetailsService, userNameUtils, systemRoles, extraRoles, adminRole);
service.setUserDetailsService(userDetailsService);
logout();
login(USERNAME_ADMIN, mainTenant_1, new String[] { tenantAdminRoleName, tenantAuthenticatedRoleName });
List<String> rolesForUser_2 = service.getRolesForUser(mainTenant_1, USER_2);
List<String> rolesForUser_2_1 = service.getRolesForUser(null, USER_2);
List<String> rolesForUser_2_1_1 = service.getRolesForUser(null, userNameUtils.getPrincipleId(mainTenant_1, USER_2));
List<String> rolesForUser_3 = service.getRolesForUser(mainTenant_1, USER_3);
List<String> rolesForUser_4 = service.getRolesForUser(mainTenant_1, USER_4);
assertTrue(rolesForUser_2.size() == 4);
assertTrue(rolesForUser_2_1.size() == 4);
assertTrue(rolesForUser_2_1_1.size() == 4);
assertTrue(rolesForUser_3.size() == 3);
assertTrue(rolesForUser_4.size() == 2);
cleanupUserAndRoles(mainTenant_1);
cleanupUserAndRoles(mainTenant_2);
}
use of org.pentaho.platform.security.userroledao.service.UserRoleDaoUserRoleListService in project pentaho-platform by pentaho.
the class UserRoleDaoUserRoleListServiceIT method testGetUsernamesInRole.
@Test
public void testGetUsernamesInRole() {
loginAsSysTenantAdmin();
mainTenant_1 = tenantManager.createTenant(systemTenant, MAIN_TENANT_1, tenantAdminRoleName, tenantAuthenticatedRoleName, ANONYMOUS_ROLE_NAME);
userRoleDao.createUser(mainTenant_1, USERNAME_ADMIN, PASSWORD, "", new String[] { tenantAdminRoleName });
mainTenant_2 = tenantManager.createTenant(systemTenant, MAIN_TENANT_2, tenantAdminRoleName, tenantAuthenticatedRoleName, ANONYMOUS_ROLE_NAME);
userRoleDao.createUser(mainTenant_2, USERNAME_ADMIN, PASSWORD, "", new String[] { tenantAdminRoleName });
login(USERNAME_ADMIN, mainTenant_1, new String[] { tenantAdminRoleName, tenantAuthenticatedRoleName });
userRoleDao.createUser(mainTenant_1, USER_2, PASSWORD_2, USER_DESCRIPTION_2, null);
userRoleDao.createUser(null, USER_3, PASSWORD_3, USER_DESCRIPTION_3, null);
userRoleDao.createUser(null, userNameUtils.getPrincipleId(mainTenant_1, USER_4), PASSWORD_4, USER_DESCRIPTION_4, null);
userRoleDao.createUser(mainTenant_1, USER_5, PASSWORD_5, USER_DESCRIPTION_5, null);
userRoleDao.createUser(mainTenant_1, USER_6, PASSWORD_6, USER_DESCRIPTION_6, null);
logout();
login(USERNAME_ADMIN, mainTenant_2, new String[] { tenantAdminRoleName, tenantAuthenticatedRoleName });
userRoleDao.createUser(mainTenant_2, USER_7, PASSWORD_7, USER_DESCRIPTION_7, null);
userRoleDao.createUser(mainTenant_2, USER_8, PASSWORD_8, USER_DESCRIPTION_8, null);
logout();
login(USERNAME_ADMIN, mainTenant_1, new String[] { tenantAdminRoleName, tenantAuthenticatedRoleName });
userRoleDao.createRole(mainTenant_1, ROLE_1, ROLE_DESCRIPTION_1, null);
userRoleDao.createRole(null, ROLE_2, ROLE_DESCRIPTION_2, null);
userRoleDao.createRole(null, roleNameUtils.getPrincipleId(mainTenant_1, ROLE_3), ROLE_DESCRIPTION_3, null);
logout();
login(USERNAME_ADMIN, mainTenant_2, new String[] { tenantAdminRoleName, tenantAuthenticatedRoleName });
userRoleDao.createRole(mainTenant_2, ROLE_4, ROLE_DESCRIPTION_4, null);
logout();
login(USERNAME_ADMIN, mainTenant_1, new String[] { tenantAdminRoleName, tenantAuthenticatedRoleName });
userRoleDao.setRoleMembers(null, ROLE_1, new String[] { USER_2, USER_3, USER_4 });
userRoleDao.setRoleMembers(mainTenant_1, ROLE_2, new String[] { USER_5, USER_6, USER_7 });
userRoleDao.setRoleMembers(null, roleNameUtils.getPrincipleId(mainTenant_1, ROLE_3), new String[] { USER_2, USER_4, USER_6 });
logout();
login(USERNAME_ADMIN, mainTenant_2, new String[] { tenantAdminRoleName, tenantAuthenticatedRoleName });
userRoleDao.setRoleMembers(null, ROLE_4, new String[] { USER_3, USER_5, USER_7 });
logout();
login(USERNAME_ADMIN, mainTenant_1, new String[] { tenantAdminRoleName, tenantAuthenticatedRoleName });
UserRoleDaoUserDetailsService userDetailsService = new UserRoleDaoUserDetailsService();
userDetailsService.setUserRoleDao(userRoleDao);
userDetailsService.setDefaultRole(tenantAuthenticatedRoleName);
List<String> systemRoles = new ArrayList<String>();
systemRoles.add(USERNAME_ADMIN);
List<String> extraRoles = Arrays.asList(AUTHENTICATED_ROLE_NAME, ANONYMOUS_ROLE_NAME);
String adminRole = USERNAME_ADMIN;
UserRoleDaoUserRoleListService service = new UserRoleDaoUserRoleListService(userRoleDao, userDetailsService, userNameUtils, systemRoles, extraRoles, adminRole);
List<String> usersInRole_1 = service.getUsersInRole(mainTenant_1, ROLE_1);
List<String> usersInRole_2 = service.getUsersInRole(null, ROLE_2);
List<String> usersInRole_3 = service.getUsersInRole(null, roleNameUtils.getPrincipleId(mainTenant_1, ROLE_3));
logout();
login(USERNAME_ADMIN, mainTenant_2, new String[] { tenantAdminRoleName, tenantAuthenticatedRoleName });
List<String> usersInRole_4 = service.getUsersInRole(mainTenant_2, ROLE_4);
assertTrue(usersInRole_1.size() == 3);
assertTrue(usersInRole_2.size() == 2);
assertTrue(usersInRole_3.size() == 3);
assertTrue(usersInRole_4.size() == 1);
logout();
cleanupUserAndRoles(mainTenant_1);
cleanupUserAndRoles(mainTenant_2);
}
use of org.pentaho.platform.security.userroledao.service.UserRoleDaoUserRoleListService in project pentaho-platform by pentaho.
the class UserRoleDaoUserRoleListServiceIT method testGetAllAuthorities.
@Test
public void testGetAllAuthorities() {
loginAsSysTenantAdmin();
mainTenant_1 = tenantManager.createTenant(systemTenant, MAIN_TENANT_1, tenantAdminRoleName, tenantAuthenticatedRoleName, ANONYMOUS_ROLE_NAME);
userRoleDao.createUser(mainTenant_1, USERNAME_ADMIN, PASSWORD, "", new String[] { tenantAdminRoleName });
mainTenant_2 = tenantManager.createTenant(systemTenant, MAIN_TENANT_2, tenantAdminRoleName, tenantAuthenticatedRoleName, ANONYMOUS_ROLE_NAME);
userRoleDao.createUser(mainTenant_2, USERNAME_ADMIN, PASSWORD, "", new String[] { tenantAdminRoleName });
login(USERNAME_ADMIN, mainTenant_1, new String[] { tenantAdminRoleName, tenantAuthenticatedRoleName });
userRoleDao.createRole(mainTenant_1, ROLE_1, ROLE_DESCRIPTION_1, null);
userRoleDao.createRole(mainTenant_1, ROLE_2, ROLE_DESCRIPTION_2, null);
userRoleDao.createRole(mainTenant_1, ROLE_3, ROLE_DESCRIPTION_3, null);
logout();
login(USERNAME_ADMIN, mainTenant_2, new String[] { tenantAdminRoleName, tenantAuthenticatedRoleName });
userRoleDao.createRole(mainTenant_2, ROLE_4, ROLE_DESCRIPTION_4, null);
userRoleDao.createRole(mainTenant_2, ROLE_5, ROLE_DESCRIPTION_5, null);
userRoleDao.createRole(mainTenant_2, ROLE_6, ROLE_DESCRIPTION_6, null);
userRoleDao.createRole(mainTenant_2, ROLE_7, ROLE_DESCRIPTION_7, null);
List<String> systemRoles = Arrays.asList(USERNAME_ADMIN);
List<String> extraRoles = Arrays.asList(AUTHENTICATED_ROLE_NAME, ANONYMOUS_ROLE_NAME);
String adminRole = USERNAME_ADMIN;
UserRoleDaoUserDetailsService userDetailsService = new UserRoleDaoUserDetailsService();
UserRoleDaoUserRoleListService service = new UserRoleDaoUserRoleListService(userRoleDao, userDetailsService, userNameUtils, systemRoles, extraRoles, adminRole);
userDetailsService.setUserRoleDao(userRoleDao);
logout();
login(USERNAME_ADMIN, mainTenant_1, new String[] { tenantAdminRoleName, tenantAuthenticatedRoleName });
List<String> allRolesForDefaultTenant = service.getAllRoles();
List<String> allRolesForTenant = service.getAllRoles(mainTenant_2);
logger.info("allRolesForDefaultTenant.size() ==" + allRolesForDefaultTenant.size());
logger.info("allRolesForTenant.size() ==" + allRolesForTenant.size());
assertTrue(allRolesForDefaultTenant.size() == 2 + DEFAULT_ROLE_COUNT);
assertEquals(3 + DEFAULT_ROLE_COUNT, allRolesForTenant.size());
logout();
login(USERNAME_ADMIN, mainTenant_2, new String[] { tenantAdminRoleName, tenantAuthenticatedRoleName });
allRolesForDefaultTenant = service.getAllRoles();
allRolesForTenant = service.getAllRoles(mainTenant_1);
assertTrue(allRolesForDefaultTenant.size() == 3 + DEFAULT_ROLE_COUNT);
assertEquals(2 + DEFAULT_ROLE_COUNT, allRolesForTenant.size());
allRolesForTenant = service.getAllRoles(mainTenant_2);
assertEquals(3 + DEFAULT_ROLE_COUNT, allRolesForTenant.size());
allRolesForTenant = service.getAllRoles(mainTenant_1);
assertEquals(2 + DEFAULT_ROLE_COUNT, allRolesForTenant.size());
logout();
login(USERNAME_ADMIN, mainTenant_1, new String[] { tenantAdminRoleName, tenantAuthenticatedRoleName });
allRolesForTenant = service.getAllRoles(mainTenant_1);
assertEquals(2 + DEFAULT_ROLE_COUNT, allRolesForTenant.size());
allRolesForTenant = service.getAllRoles(mainTenant_2);
assertEquals(3 + DEFAULT_ROLE_COUNT, allRolesForTenant.size());
cleanupUserAndRoles(mainTenant_1);
cleanupUserAndRoles(mainTenant_2);
}
Aggregations