use of org.pentaho.platform.api.engine.security.userroledao.IPentahoUser in project pentaho-platform by pentaho.
the class UserRoleDaoUserDetailsServiceIT method testLoadUserByUsernameNoRoles.
@Test
public void testLoadUserByUsernameNoRoles() {
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);
UserRoleDaoUserDetailsService userDetailsService = new UserRoleDaoUserDetailsService();
userDetailsService.setUserRoleDao(userRoleDao);
try {
userDetailsService.loadUserByUsername(USER_2);
} catch (UsernameNotFoundException unnf) {
assertNotNull(unnf);
}
cleanupUserAndRoles(mainTenant_1);
}
use of org.pentaho.platform.api.engine.security.userroledao.IPentahoUser in project pentaho-platform by pentaho.
the class UserRoleDaoService method changeUserPassword.
public void changeUserPassword(final String userName, final String newPass, String oldPass) throws Exception {
if (inputValid(userName, newPass, oldPass)) {
final IPentahoSession pentahoSession = PentahoSessionHolder.getSession();
// You must be either an admin or trying to change your own password
if (canAdminister() || (null != pentahoSession && userName.equals(pentahoSession.getName()))) {
final IUserRoleDao roleDao = PentahoSystem.get(IUserRoleDao.class, "userRoleDaoProxy", pentahoSession);
IPentahoUser pentahoUser = roleDao.getUser(null, userName);
if (credentialValid(pentahoUser, oldPass)) {
SecurityHelper.getInstance().runAsSystem(new Callable<Void>() {
@Override
public Void call() throws Exception {
roleDao.setPassword(null, userName, newPass);
return null;
}
});
} else {
throw new SecurityException();
}
} else {
throw new SecurityException();
}
} else {
throw new ValidationFailedException();
}
}
use of org.pentaho.platform.api.engine.security.userroledao.IPentahoUser in project pentaho-platform by pentaho.
the class UserRoleDaoResource method assignAllUsersToRole.
/**
* Associates all user to a particular role
*
* @param tenantPath (tenant path where the user exist, null of empty string assumes default tenant)
* @param roleName (role name)
* @return
*/
@PUT
@Path("/assignAllUsersToRole")
@Consumes({ MediaType.WILDCARD })
@Facet(name = "Unsupported")
public Response assignAllUsersToRole(@QueryParam("tenant") String tenantPath, @QueryParam("roleName") String roleName) {
IUserRoleDao roleDao = getUserRoleDao();
Set<String> assignedUserNames = new HashSet<String>();
for (IPentahoUser pentahoUser : roleDao.getUsers(getTenant(tenantPath))) {
assignedUserNames.add(pentahoUser.getUsername());
}
roleDao.setRoleMembers(getTenant(tenantPath), roleName, assignedUserNames.toArray(new String[0]));
if (assignedUserNames.contains(getSession().getName())) {
updateRolesForCurrentSession();
}
return Response.ok().build();
}
use of org.pentaho.platform.api.engine.security.userroledao.IPentahoUser in project pentaho-platform by pentaho.
the class UserRoleDaoResourceTest method testGetRoleMembers.
@Test
public void testGetRoleMembers() throws Exception {
String role = "Report Author";
UserListWrapper userListWrapper = new UserListWrapper(new ArrayList<IPentahoUser>());
when(userRoleService.getRoleMembers(role)).thenReturn(userListWrapper);
assertEquals(userListWrapper, userRoleResource.getRoleMembers(role));
}
use of org.pentaho.platform.api.engine.security.userroledao.IPentahoUser in project pentaho-platform by pentaho.
the class UserRoleDaoServiceTest method testDeleteUsersUncategorizedUserRoleDaoException.
@Test(expected = UncategorizedUserRoleDaoException.class)
public void testDeleteUsersUncategorizedUserRoleDaoException() {
String users = "admin\tsuzy\t";
setupMockSessionUser(SESSION_USER_NAME, true);
IPentahoUser user = mock(IPentahoUser.class);
IUserRoleDao roleDao = mock(IUserRoleDao.class);
when(roleDao.getUser(any(ITenant.class), anyString())).thenThrow(new UncategorizedUserRoleDaoException("expectedTestException"));
PentahoSystem.registerObject(roleDao);
userRoleService.deleteUsers(users);
}
Aggregations