Search in sources :

Example 6 with UserRoleDaoUserDetailsService

use of org.pentaho.platform.security.userroledao.service.UserRoleDaoUserDetailsService 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);
}
Also used : UserRoleDaoUserDetailsService(org.pentaho.platform.security.userroledao.service.UserRoleDaoUserDetailsService) UserRoleDaoUserRoleListService(org.pentaho.platform.security.userroledao.service.UserRoleDaoUserRoleListService) Test(org.junit.Test)

Example 7 with UserRoleDaoUserDetailsService

use of org.pentaho.platform.security.userroledao.service.UserRoleDaoUserDetailsService 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);
}
Also used : UserRoleDaoUserDetailsService(org.pentaho.platform.security.userroledao.service.UserRoleDaoUserDetailsService) UserRoleDaoUserRoleListService(org.pentaho.platform.security.userroledao.service.UserRoleDaoUserRoleListService) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 8 with UserRoleDaoUserDetailsService

use of org.pentaho.platform.security.userroledao.service.UserRoleDaoUserDetailsService 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);
}
Also used : UserRoleDaoUserDetailsService(org.pentaho.platform.security.userroledao.service.UserRoleDaoUserDetailsService) UserRoleDaoUserRoleListService(org.pentaho.platform.security.userroledao.service.UserRoleDaoUserRoleListService) Test(org.junit.Test)

Example 9 with UserRoleDaoUserDetailsService

use of org.pentaho.platform.security.userroledao.service.UserRoleDaoUserDetailsService in project pentaho-platform by pentaho.

the class MetadataRepositoryLifecycleManagerIT method beforeTest.

@Before
public void beforeTest() throws PlatformInitializationException {
    System.setProperty(SYSTEM_PROPERTY, "MODE_INHERITABLETHREADLOCAL");
    mp = new MicroPlatform();
    mp.defineInstance("tenantedUserNameUtils", tenantedUserNameUtils);
    mp.define(IPluginManager.class, DefaultPluginManager.class, Scope.GLOBAL);
    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(IConfiguration.class, SystemConfig.class);
    mp.defineInstance("RepositoryFileProxyFactory", new RepositoryFileProxyFactory(this.jcrTemplate, this.repositoryFileDao));
    mp.defineInstance("useMultiByteEncoding", new Boolean(false));
    UserRoleDaoUserDetailsService userDetailsService = new UserRoleDaoUserDetailsService();
    userDetailsService.setUserRoleDao(userRoleDao);
    List<String> systemRoles = new ArrayList<String>();
    systemRoles.add("Administrator");
    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();
    loginAsRepositoryAdmin();
    setAclManagement();
    logout();
    startupCalled = true;
}
Also used : UserRoleDaoUserDetailsService(org.pentaho.platform.security.userroledao.service.UserRoleDaoUserDetailsService) UserRoleDaoUserRoleListService(org.pentaho.platform.security.userroledao.service.UserRoleDaoUserRoleListService) MicroPlatform(org.pentaho.test.platform.engine.core.MicroPlatform) ArrayList(java.util.ArrayList) RepositoryFileProxyFactory(org.pentaho.platform.repository2.unified.jcr.RepositoryFileProxyFactory) Before(org.junit.Before)

Example 10 with UserRoleDaoUserDetailsService

use of org.pentaho.platform.security.userroledao.service.UserRoleDaoUserDetailsService in project pentaho-platform by pentaho.

the class FileResourceIT 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);
}
Also used : NameBaseMimeResolver(org.pentaho.platform.plugin.services.importer.NameBaseMimeResolver) UserRoleDaoUserDetailsService(org.pentaho.platform.security.userroledao.service.UserRoleDaoUserDetailsService) UserRoleDaoUserRoleListService(org.pentaho.platform.security.userroledao.service.UserRoleDaoUserRoleListService) MicroPlatform(org.pentaho.test.platform.engine.core.MicroPlatform) ArrayList(java.util.ArrayList) DefaultRepositoryVersionManager(org.pentaho.platform.repository2.unified.DefaultRepositoryVersionManager) RepositoryFileProxyFactory(org.pentaho.platform.repository2.unified.jcr.RepositoryFileProxyFactory) Before(org.junit.Before)

Aggregations

UserRoleDaoUserDetailsService (org.pentaho.platform.security.userroledao.service.UserRoleDaoUserDetailsService)10 Test (org.junit.Test)7 UserRoleDaoUserRoleListService (org.pentaho.platform.security.userroledao.service.UserRoleDaoUserRoleListService)7 ArrayList (java.util.ArrayList)4 Before (org.junit.Before)3 RepositoryFileProxyFactory (org.pentaho.platform.repository2.unified.jcr.RepositoryFileProxyFactory)3 MicroPlatform (org.pentaho.test.platform.engine.core.MicroPlatform)3 IPentahoUser (org.pentaho.platform.api.engine.security.userroledao.IPentahoUser)2 ITenant (org.pentaho.platform.api.mt.ITenant)2 NameBaseMimeResolver (org.pentaho.platform.plugin.services.importer.NameBaseMimeResolver)2 DefaultRepositoryVersionManager (org.pentaho.platform.repository2.unified.DefaultRepositoryVersionManager)2 IPentahoRole (org.pentaho.platform.api.engine.security.userroledao.IPentahoRole)1 GrantedAuthority (org.springframework.security.core.GrantedAuthority)1 UserDetails (org.springframework.security.core.userdetails.UserDetails)1 UsernameNotFoundException (org.springframework.security.core.userdetails.UsernameNotFoundException)1