Search in sources :

Example 31 with IUserRoleDao

use of org.pentaho.platform.api.engine.security.userroledao.IUserRoleDao 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 32 with IUserRoleDao

use of org.pentaho.platform.api.engine.security.userroledao.IUserRoleDao 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 33 with IUserRoleDao

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

the class UserRoleDaoServiceTest method testGetRolesForUser.

@Test
public void testGetRolesForUser() throws Exception {
    List<IPentahoRole> roleList = new ArrayList<>();
    IUserRoleDao roleDao = mock(IUserRoleDao.class);
    when(roleDao.getUserRoles(any(ITenant.class), anyString())).thenReturn(roleList);
    PentahoSystem.registerObject(roleDao);
    RoleListWrapper wrapRoleList = new RoleListWrapper(roleList);
    IPentahoSession session = mock(IPentahoSession.class);
    String tenantPath = "testPath";
    when(session.getAttribute(IPentahoSession.TENANT_ID_KEY)).thenReturn(tenantPath);
    PentahoSessionHolder.setSession(session);
    setupMockSessionUser(SESSION_USER_NAME, true);
    assertEquals(wrapRoleList.getRoles(), userRoleService.getRolesForUser("admin").getRoles());
}
Also used : ITenant(org.pentaho.platform.api.mt.ITenant) RoleListWrapper(org.pentaho.platform.web.http.api.resources.RoleListWrapper) IPentahoSession(org.pentaho.platform.api.engine.IPentahoSession) ArrayList(java.util.ArrayList) IPentahoRole(org.pentaho.platform.api.engine.security.userroledao.IPentahoRole) Matchers.anyString(org.mockito.Matchers.anyString) IUserRoleDao(org.pentaho.platform.api.engine.security.userroledao.IUserRoleDao) Test(org.junit.Test)

Example 34 with IUserRoleDao

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

the class UserRoleDaoServiceTest method testDeleteRoleUncategorizedUserRoleDaoException.

@Test(expected = UncategorizedUserRoleDaoException.class)
public void testDeleteRoleUncategorizedUserRoleDaoException() {
    String roles = "role1\trole2\t";
    setupMockSessionUser(SESSION_USER_NAME, true);
    IUserRoleDao roleDao = mock(IUserRoleDao.class);
    when(roleDao.getRole(any(ITenant.class), anyString())).thenThrow(new UncategorizedUserRoleDaoException("expectedTestException"));
    PentahoSystem.registerObject(roleDao);
    userRoleService.deleteRoles(roles);
}
Also used : ITenant(org.pentaho.platform.api.mt.ITenant) UncategorizedUserRoleDaoException(org.pentaho.platform.api.engine.security.userroledao.UncategorizedUserRoleDaoException) Matchers.anyString(org.mockito.Matchers.anyString) IUserRoleDao(org.pentaho.platform.api.engine.security.userroledao.IUserRoleDao) Test(org.junit.Test)

Example 35 with IUserRoleDao

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

the class UserRoleDaoServiceTest method testUpdatePasswordNotAdmin.

@Test(expected = SecurityException.class)
public void testUpdatePasswordNotAdmin() throws Exception {
    setupMockSessionUser(SESSION_USER_NAME, false);
    IUserRoleDao roleDao = registerMockUserRoleDao();
    addMockUserToUserRoleDao(roleDao, SESSION_USER_NAME, SESSION_USER_PASSWORD);
    addMockUserToUserRoleDao(roleDao, OTHER_USER_NAME, OTHER_USER_PASSWORD);
    userRoleService.updatePassword(new User(OTHER_USER_NAME, A_NEW_PASSWORD));
}
Also used : IPentahoUser(org.pentaho.platform.api.engine.security.userroledao.IPentahoUser) User(org.pentaho.platform.web.http.api.resources.User) IUserRoleDao(org.pentaho.platform.api.engine.security.userroledao.IUserRoleDao) Test(org.junit.Test)

Aggregations

IUserRoleDao (org.pentaho.platform.api.engine.security.userroledao.IUserRoleDao)43 Test (org.junit.Test)28 IPentahoUser (org.pentaho.platform.api.engine.security.userroledao.IPentahoUser)21 ITenant (org.pentaho.platform.api.mt.ITenant)20 Matchers.anyString (org.mockito.Matchers.anyString)13 IPentahoSession (org.pentaho.platform.api.engine.IPentahoSession)11 ArrayList (java.util.ArrayList)9 User (org.pentaho.platform.web.http.api.resources.User)9 IPentahoRole (org.pentaho.platform.api.engine.security.userroledao.IPentahoRole)8 HashSet (java.util.HashSet)6 Consumes (javax.ws.rs.Consumes)6 PUT (javax.ws.rs.PUT)6 Path (javax.ws.rs.Path)6 Facet (org.codehaus.enunciate.Facet)6 UncategorizedUserRoleDaoException (org.pentaho.platform.api.engine.security.userroledao.UncategorizedUserRoleDaoException)5 AuthenticationProvider (org.springframework.security.authentication.AuthenticationProvider)5 NotFoundException (org.pentaho.platform.api.engine.security.userroledao.NotFoundException)3 Tenant (org.pentaho.platform.core.mt.Tenant)3 UserListWrapper (org.pentaho.platform.web.http.api.resources.UserListWrapper)3 IOException (java.io.IOException)2