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));
}
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");
}
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());
}
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());
}
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);
}
Aggregations