use of org.pentaho.platform.api.engine.security.userroledao.IUserRoleDao in project pentaho-platform by pentaho.
the class UserRoleDaoServiceTest method testUpdatePasswordWithWrongAdminCredentials.
@Test(expected = SecurityException.class)
public void testUpdatePasswordWithWrongAdminCredentials() throws Exception {
setupMockSessionUser(SESSION_USER_NAME, true);
AuthenticationProvider authenticationProvider = registerMockAuthenticationProvider();
addMockUserToAuthenticationProvider(authenticationProvider, SESSION_USER_NAME, SESSION_USER_PASSWORD);
IUserRoleDao roleDao = registerMockUserRoleDao();
addMockUserToUserRoleDao(roleDao, OTHER_USER_NAME, OTHER_USER_PASSWORD);
userRoleService.updatePassword(new User(OTHER_USER_NAME, A_NEW_PASSWORD), A_WRONG_PASSWORD);
}
use of org.pentaho.platform.api.engine.security.userroledao.IUserRoleDao in project pentaho-platform by pentaho.
the class UserRoleDaoServiceTest method registerMockUserRoleDao.
private IUserRoleDao registerMockUserRoleDao() {
IUserRoleDao roleDao = mock(IUserRoleDao.class);
PentahoSystem.registerObject(roleDao);
return roleDao;
}
use of org.pentaho.platform.api.engine.security.userroledao.IUserRoleDao in project pentaho-platform by pentaho.
the class UserRoleDaoServiceTest method testAssignRoleToUser.
@Test
public void testAssignRoleToUser() throws UserRoleListService.UnauthorizedException {
String userName = "testUser";
String roleNames = "Power User\tBusiness User\t";
setupMockSessionUser(SESSION_USER_NAME, true);
// Create session that will generate tenant
IPentahoSession session = mock(IPentahoSession.class);
when(session.getAttribute(IPentahoSession.TENANT_ID_KEY)).thenReturn("testTenantPath");
PentahoSessionHolder.setSession(session);
IPentahoRole ceoRole = mock(IPentahoRole.class);
when(ceoRole.getName()).thenReturn("ceo");
IPentahoRole ctoRole = mock(IPentahoRole.class);
when(ctoRole.getName()).thenReturn("cto");
List<IPentahoRole> roleList = new ArrayList<>();
roleList.add(ceoRole);
roleList.add(ctoRole);
IUserRoleDao roleDao = mock(IUserRoleDao.class);
when(roleDao.getUserRoles(any(ITenant.class), anyString())).thenReturn(roleList);
PentahoSystem.registerObject(roleDao);
userRoleService.assignRolesToUser(userName, roleNames);
verify(roleDao).setUserRoles(any(ITenant.class), anyString(), argThat(new UnorderedArrayMatcher(new String[] { "ceo", "cto", "Power User", "Business User" })));
}
use of org.pentaho.platform.api.engine.security.userroledao.IUserRoleDao in project pentaho-platform by pentaho.
the class UserRoleDaoServiceTest method testSelfUpdatePasswordWithAdminCredentials.
@Test
public void testSelfUpdatePasswordWithAdminCredentials() throws Exception {
setupMockSessionUser(SESSION_USER_NAME, true);
AuthenticationProvider authenticationProvider = registerMockAuthenticationProvider();
addMockUserToAuthenticationProvider(authenticationProvider, SESSION_USER_NAME, SESSION_USER_PASSWORD);
IUserRoleDao roleDao = registerMockUserRoleDao();
addMockUserToUserRoleDao(roleDao, SESSION_USER_NAME, SESSION_USER_PASSWORD);
userRoleService.updatePassword(new User(SESSION_USER_NAME, A_NEW_PASSWORD), SESSION_USER_PASSWORD);
verify(roleDao, times(1)).setPassword(any(ITenant.class), eq(SESSION_USER_NAME), eq(A_NEW_PASSWORD));
}
use of org.pentaho.platform.api.engine.security.userroledao.IUserRoleDao in project pentaho-platform by pentaho.
the class UserRoleDaoServiceTest method testUpdatePasswordWithNotAdminCredentials.
@Test(expected = SecurityException.class)
public void testUpdatePasswordWithNotAdminCredentials() throws Exception {
setupMockSessionUser(SESSION_USER_NAME, false);
AuthenticationProvider authenticationProvider = registerMockAuthenticationProvider();
addMockUserToAuthenticationProvider(authenticationProvider, SESSION_USER_NAME, SESSION_USER_PASSWORD);
IUserRoleDao roleDao = registerMockUserRoleDao();
addMockUserToUserRoleDao(roleDao, OTHER_USER_NAME, OTHER_USER_PASSWORD);
userRoleService.updatePassword(new User(OTHER_USER_NAME, A_NEW_PASSWORD), SESSION_USER_PASSWORD);
}
Aggregations