Search in sources :

Example 36 with IPentahoUser

use of org.pentaho.platform.api.engine.security.userroledao.IPentahoUser in project pentaho-platform by pentaho.

the class UserRoleDaoServiceTest method addMockUserToUserRoleDao.

private void addMockUserToUserRoleDao(IUserRoleDao roleDao, String username, String password) {
    IPentahoUser pentahoUser = createMockPentahoUser(username, password);
    doReturn(pentahoUser).when(roleDao).getUser(any(ITenant.class), eq(username));
}
Also used : ITenant(org.pentaho.platform.api.mt.ITenant) IPentahoUser(org.pentaho.platform.api.engine.security.userroledao.IPentahoUser)

Example 37 with IPentahoUser

use of org.pentaho.platform.api.engine.security.userroledao.IPentahoUser in project pentaho-platform by pentaho.

the class UserRoleDaoServiceTest method testGetRoleMembersSecurityException.

@Test(expected = SecurityException.class)
public void testGetRoleMembersSecurityException() {
    setupMockSessionUser(SESSION_USER_NAME, false);
    List<IPentahoUser> userList = new ArrayList<>();
    IUserRoleDao roleDao = mock(IUserRoleDao.class);
    when(roleDao.getRoleMembers(any(ITenant.class), anyString())).thenReturn(userList);
    PentahoSystem.registerObject(roleDao);
    IPentahoUser user = mock(IPentahoUser.class);
    when(user.getUsername()).thenReturn("admin");
    userList.add(user);
    UserListWrapper wrapUserList = new UserListWrapper(userList);
    IPentahoSession session = mock(IPentahoSession.class);
    String tenantPath = "testPath";
    when(session.getAttribute(IPentahoSession.TENANT_ID_KEY)).thenReturn(tenantPath);
    PentahoSessionHolder.setSession(session);
    userRoleService.getRoleMembers("Report Author");
}
Also used : ITenant(org.pentaho.platform.api.mt.ITenant) IPentahoSession(org.pentaho.platform.api.engine.IPentahoSession) ArrayList(java.util.ArrayList) Matchers.anyString(org.mockito.Matchers.anyString) IUserRoleDao(org.pentaho.platform.api.engine.security.userroledao.IUserRoleDao) IPentahoUser(org.pentaho.platform.api.engine.security.userroledao.IPentahoUser) UserListWrapper(org.pentaho.platform.web.http.api.resources.UserListWrapper) Test(org.junit.Test)

Example 38 with IPentahoUser

use of org.pentaho.platform.api.engine.security.userroledao.IPentahoUser in project pentaho-platform by pentaho.

the class UserRoleDaoServiceTest method testGetUsers.

@Test
public void testGetUsers() throws Exception {
    List<IPentahoUser> userList = new ArrayList<>();
    IUserRoleDao roleDao = mock(IUserRoleDao.class);
    when(roleDao.getUsers()).thenReturn(userList);
    PentahoSystem.registerObject(roleDao);
    UserListWrapper wrapUserList = new UserListWrapper(userList);
    assertEquals(wrapUserList.getUsers(), userRoleService.getUsers().getUsers());
}
Also used : ArrayList(java.util.ArrayList) IUserRoleDao(org.pentaho.platform.api.engine.security.userroledao.IUserRoleDao) IPentahoUser(org.pentaho.platform.api.engine.security.userroledao.IPentahoUser) UserListWrapper(org.pentaho.platform.web.http.api.resources.UserListWrapper) Test(org.junit.Test)

Example 39 with IPentahoUser

use of org.pentaho.platform.api.engine.security.userroledao.IPentahoUser in project pentaho-platform by pentaho.

the class UserRoleDaoServiceTest method testGetRoleMembers.

@Test
public void testGetRoleMembers() {
    setupMockSessionUser(SESSION_USER_NAME, true);
    List<IPentahoUser> userList = new ArrayList<>();
    IUserRoleDao roleDao = mock(IUserRoleDao.class);
    when(roleDao.getRoleMembers(any(ITenant.class), anyString())).thenReturn(userList);
    PentahoSystem.registerObject(roleDao);
    IPentahoUser user = mock(IPentahoUser.class);
    when(user.getUsername()).thenReturn("admin");
    userList.add(user);
    UserListWrapper wrapUserList = new UserListWrapper(userList);
    IPentahoSession session = mock(IPentahoSession.class);
    String tenantPath = "testPath";
    when(session.getAttribute(IPentahoSession.TENANT_ID_KEY)).thenReturn(tenantPath);
    PentahoSessionHolder.setSession(session);
    assertEquals(wrapUserList.getUsers(), userRoleService.getRoleMembers("Report Author").getUsers());
}
Also used : ITenant(org.pentaho.platform.api.mt.ITenant) IPentahoSession(org.pentaho.platform.api.engine.IPentahoSession) ArrayList(java.util.ArrayList) Matchers.anyString(org.mockito.Matchers.anyString) IUserRoleDao(org.pentaho.platform.api.engine.security.userroledao.IUserRoleDao) IPentahoUser(org.pentaho.platform.api.engine.security.userroledao.IPentahoUser) UserListWrapper(org.pentaho.platform.web.http.api.resources.UserListWrapper) Test(org.junit.Test)

Example 40 with IPentahoUser

use of org.pentaho.platform.api.engine.security.userroledao.IPentahoUser 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)

Aggregations

IPentahoUser (org.pentaho.platform.api.engine.security.userroledao.IPentahoUser)60 Test (org.junit.Test)23 ArrayList (java.util.ArrayList)16 ITenant (org.pentaho.platform.api.mt.ITenant)15 IUserRoleDao (org.pentaho.platform.api.engine.security.userroledao.IUserRoleDao)13 IPentahoRole (org.pentaho.platform.api.engine.security.userroledao.IPentahoRole)12 NotFoundException (org.pentaho.platform.api.engine.security.userroledao.NotFoundException)11 RepositoryException (javax.jcr.RepositoryException)8 PentahoUser (org.pentaho.platform.security.userroledao.PentahoUser)8 AlreadyExistsException (org.pentaho.platform.api.engine.security.userroledao.AlreadyExistsException)7 HashSet (java.util.HashSet)6 Matchers.anyString (org.mockito.Matchers.anyString)5 IPentahoSession (org.pentaho.platform.api.engine.IPentahoSession)5 IOException (java.io.IOException)4 AccessControlException (javax.jcr.security.AccessControlException)4 Group (org.apache.jackrabbit.api.security.user.Group)4 BeansException (org.springframework.beans.BeansException)4 User (org.apache.jackrabbit.api.security.user.User)3 UncategorizedUserRoleDaoException (org.pentaho.platform.api.engine.security.userroledao.UncategorizedUserRoleDaoException)3 UserListWrapper (org.pentaho.platform.web.http.api.resources.UserListWrapper)3