Search in sources :

Example 1 with UserRoleDaoUserDetailsService

use of org.pentaho.platform.security.userroledao.service.UserRoleDaoUserDetailsService 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);
}
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)

Example 2 with UserRoleDaoUserDetailsService

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

the class UserRoleDaoUserDetailsServiceIT method testLoadUserByUsernameNoRoles.

@Test
public void testLoadUserByUsernameNoRoles() {
    loginAsSysTenantAdmin();
    ITenant mainTenant_1 = tenantManager.createTenant(systemTenant, MAIN_TENANT_1, tenantAdminRoleName, tenantAuthenticatedRoleName, ANONYMOUS_ROLE_NAME);
    userRoleDao.createUser(mainTenant_1, USERNAME_ADMIN, PASSWORD, "", new String[] { tenantAdminRoleName });
    login(USERNAME_ADMIN, mainTenant_1, new String[] { tenantAdminRoleName, tenantAuthenticatedRoleName });
    IPentahoUser pentahoUser = userRoleDao.createUser(mainTenant_1, USER_2, PASSWORD_2, USER_DESCRIPTION_2, null);
    UserRoleDaoUserDetailsService userDetailsService = new UserRoleDaoUserDetailsService();
    userDetailsService.setUserRoleDao(userRoleDao);
    try {
        userDetailsService.loadUserByUsername(USER_2);
    } catch (UsernameNotFoundException unnf) {
        assertNotNull(unnf);
    }
    cleanupUserAndRoles(mainTenant_1);
}
Also used : UsernameNotFoundException(org.springframework.security.core.userdetails.UsernameNotFoundException) ITenant(org.pentaho.platform.api.mt.ITenant) UserRoleDaoUserDetailsService(org.pentaho.platform.security.userroledao.service.UserRoleDaoUserDetailsService) IPentahoUser(org.pentaho.platform.api.engine.security.userroledao.IPentahoUser) Test(org.junit.Test)

Example 3 with UserRoleDaoUserDetailsService

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

Example 4 with UserRoleDaoUserDetailsService

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

the class UserRoleDaoUserDetailsServiceIT method testLoadUserByUsername.

@Test
public void testLoadUserByUsername() {
    loginAsSysTenantAdmin();
    ITenant mainTenant_1 = tenantManager.createTenant(systemTenant, MAIN_TENANT_1, tenantAdminRoleName, tenantAuthenticatedRoleName, ANONYMOUS_ROLE_NAME);
    userRoleDao.createUser(mainTenant_1, USERNAME_ADMIN, PASSWORD, "", new String[] { tenantAdminRoleName });
    login(USERNAME_ADMIN, mainTenant_1, new String[] { tenantAdminRoleName, tenantAuthenticatedRoleName });
    IPentahoUser pentahoUser = userRoleDao.createUser(mainTenant_1, USER_2, PASSWORD_2, USER_DESCRIPTION_2, null);
    IPentahoRole pentahoRole = userRoleDao.createRole(mainTenant_1, ROLE_1, ROLE_DESCRIPTION_1, null);
    pentahoRole = userRoleDao.createRole(mainTenant_1, ROLE_2, ROLE_DESCRIPTION_2, null);
    pentahoRole = userRoleDao.createRole(mainTenant_1, ROLE_3, ROLE_DESCRIPTION_3, null);
    userRoleDao.setUserRoles(mainTenant_1, USER_2, new String[] { ROLE_1, ROLE_2, ROLE_3 });
    UserRoleDaoUserDetailsService userDetailsService = new UserRoleDaoUserDetailsService();
    userDetailsService.setUserRoleDao(userRoleDao);
    userDetailsService.setDefaultRole(tenantAuthenticatedRoleName);
    UserDetails userFromService = userDetailsService.loadUserByUsername(USER_2);
    assertTrue(userFromService.getUsername().equals(USER_2));
    assertTrue(userFromService.getPassword() != null);
    assertTrue(userFromService.isEnabled() == true);
    assertTrue(userFromService.getAuthorities().size() == 4);
    GrantedAuthority[] auths = new GrantedAuthority[4];
    userFromService.getAuthorities().toArray(auths);
    assertTrue(auths[0].getAuthority().equals(ROLE_0) || auths[0].getAuthority().equals(ROLE_3) || auths[0].getAuthority().equals(ROLE_2) || auths[0].getAuthority().equals(ROLE_1));
    assertTrue(auths[1].getAuthority().equals(ROLE_0) || auths[1].getAuthority().equals(ROLE_3) || auths[1].getAuthority().equals(ROLE_2) || auths[1].getAuthority().equals(ROLE_1));
    assertTrue(auths[2].getAuthority().equals(ROLE_0) || auths[2].getAuthority().equals(ROLE_3) || auths[2].getAuthority().equals(ROLE_2) || auths[2].getAuthority().equals(ROLE_1));
    assertTrue(auths[3].getAuthority().equals(ROLE_0) || auths[3].getAuthority().equals(ROLE_3) || auths[3].getAuthority().equals(ROLE_2) || auths[3].getAuthority().equals(ROLE_1));
    cleanupUserAndRoles(mainTenant_1);
}
Also used : ITenant(org.pentaho.platform.api.mt.ITenant) UserRoleDaoUserDetailsService(org.pentaho.platform.security.userroledao.service.UserRoleDaoUserDetailsService) UserDetails(org.springframework.security.core.userdetails.UserDetails) GrantedAuthority(org.springframework.security.core.GrantedAuthority) IPentahoRole(org.pentaho.platform.api.engine.security.userroledao.IPentahoRole) IPentahoUser(org.pentaho.platform.api.engine.security.userroledao.IPentahoUser) Test(org.junit.Test)

Example 5 with UserRoleDaoUserDetailsService

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

the class UserRoleDaoUserDetailsServiceIT method testLoadUserByUsernameUsernameNotFound.

@Test(expected = UsernameNotFoundException.class)
public void testLoadUserByUsernameUsernameNotFound() {
    UserRoleDaoUserDetailsService userDetailsService = new UserRoleDaoUserDetailsService();
    userDetailsService.setUserRoleDao(userRoleDao);
    userDetailsService.loadUserByUsername(USERNAME);
}
Also used : UserRoleDaoUserDetailsService(org.pentaho.platform.security.userroledao.service.UserRoleDaoUserDetailsService) Test(org.junit.Test)

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