Search in sources :

Example 1 with UserListWrapper

use of org.pentaho.platform.web.http.api.resources.UserListWrapper in project pentaho-platform by pentaho.

the class UserRoleListService method getUsers.

public UserListWrapper getUsers() {
    IUserRoleListService service = getUserRoleListService();
    List<String> allUsers = service.getAllUsers();
    if (null != userComparator) {
        Collections.sort(allUsers, userComparator);
    }
    return new UserListWrapper(allUsers);
}
Also used : IUserRoleListService(org.pentaho.platform.api.engine.IUserRoleListService) UserListWrapper(org.pentaho.platform.web.http.api.resources.UserListWrapper)

Example 2 with UserListWrapper

use of org.pentaho.platform.web.http.api.resources.UserListWrapper 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 3 with UserListWrapper

use of org.pentaho.platform.web.http.api.resources.UserListWrapper 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 4 with UserListWrapper

use of org.pentaho.platform.web.http.api.resources.UserListWrapper 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 5 with UserListWrapper

use of org.pentaho.platform.web.http.api.resources.UserListWrapper in project pentaho-platform by pentaho.

the class UserRoleListServiceTest method testGetUsers.

@Test
public void testGetUsers() {
    IUserRoleListService service = mock(IUserRoleListService.class);
    doReturn(service).when(userRoleListService).getUserRoleListService();
    List<String> users = new ArrayList<String>();
    users.add("admin");
    users.add("joe");
    users.add("suzy");
    doReturn(users).when(service).getAllUsers();
    UserListWrapper usersWrapper = userRoleListService.getUsers();
    assertTrue(usersWrapper.getUsers().size() == 3);
}
Also used : ArrayList(java.util.ArrayList) IUserRoleListService(org.pentaho.platform.api.engine.IUserRoleListService) UserListWrapper(org.pentaho.platform.web.http.api.resources.UserListWrapper) Test(org.junit.Test)

Aggregations

UserListWrapper (org.pentaho.platform.web.http.api.resources.UserListWrapper)5 ArrayList (java.util.ArrayList)4 Test (org.junit.Test)4 IPentahoUser (org.pentaho.platform.api.engine.security.userroledao.IPentahoUser)3 IUserRoleDao (org.pentaho.platform.api.engine.security.userroledao.IUserRoleDao)3 Matchers.anyString (org.mockito.Matchers.anyString)2 IPentahoSession (org.pentaho.platform.api.engine.IPentahoSession)2 IUserRoleListService (org.pentaho.platform.api.engine.IUserRoleListService)2 ITenant (org.pentaho.platform.api.mt.ITenant)2