use of org.pentaho.platform.api.engine.security.userroledao.IUserRoleDao in project pentaho-platform by pentaho.
the class UserRoleDaoResource method assignUserToRole.
/**
* Associate list of users to the selected role
*
* @param tenantPath (tenant path where the user exist, null of empty string assumes default tenant)
* @param userNames (list of tab (\t) separated user names
* @param roleName (role name)
* @return
*/
@PUT
@Path("/assignUserToRole")
@Consumes({ MediaType.WILDCARD })
@Facet(name = "Unsupported")
public Response assignUserToRole(@QueryParam("tenant") String tenantPath, @QueryParam("userNames") String userNames, @QueryParam("roleName") String roleName) {
if (canAdminister()) {
IUserRoleDao roleDao = getUserRoleDao();
StringTokenizer tokenizer = new StringTokenizer(userNames, "\t");
Set<String> assignedUserNames = new HashSet<String>();
for (IPentahoUser pentahoUser : roleDao.getRoleMembers(getTenant(tenantPath), roleName)) {
assignedUserNames.add(pentahoUser.getUsername());
}
while (tokenizer.hasMoreTokens()) {
assignedUserNames.add(tokenizer.nextToken());
}
try {
roleDao.setRoleMembers(getTenant(tenantPath), roleName, assignedUserNames.toArray(new String[0]));
if (assignedUserNames.contains(getSession().getName())) {
updateRolesForCurrentSession();
}
return Response.ok().build();
} catch (Throwable th) {
return processErrorResponse(th.getLocalizedMessage());
}
} else {
return Response.status(Response.Status.UNAUTHORIZED).build();
}
}
use of org.pentaho.platform.api.engine.security.userroledao.IUserRoleDao in project pentaho-platform by pentaho.
the class UserRoleDaoResource method removeUserFromRole.
/**
* Remove user(s) from a particular role
*
* @param tenantPath (tenant path where the user exist, null of empty string assumes default tenant)
* @param userNames (list of tab (\t) separated user names
* @param roleName (role name)
* @return
*/
@PUT
@Path("/removeUserFromRole")
@Consumes({ MediaType.WILDCARD })
@Facet(name = "Unsupported")
public Response removeUserFromRole(@QueryParam("tenant") String tenantPath, @QueryParam("userNames") String userNames, @QueryParam("roleName") String roleName) {
if (canAdminister()) {
try {
IUserRoleDao roleDao = getUserRoleDao();
StringTokenizer tokenizer = new StringTokenizer(userNames, "\t");
Set<String> assignedUserNames = new HashSet<String>();
for (IPentahoUser pentahoUser : roleDao.getRoleMembers(getTenant(tenantPath), roleName)) {
assignedUserNames.add(pentahoUser.getUsername());
}
while (tokenizer.hasMoreTokens()) {
assignedUserNames.remove(tokenizer.nextToken());
}
roleDao.setRoleMembers(getTenant(tenantPath), roleName, assignedUserNames.toArray(new String[0]));
if (assignedUserNames.contains(getSession().getName())) {
updateRolesForCurrentSession();
}
return Response.ok().build();
} catch (Throwable th) {
return processErrorResponse(th.getLocalizedMessage());
}
} else {
return Response.status(Response.Status.UNAUTHORIZED).build();
}
}
use of org.pentaho.platform.api.engine.security.userroledao.IUserRoleDao in project pentaho-platform by pentaho.
the class UserRoleDaoResource method assignAllRolesToUser.
/**
* Associate all roles to the selected user
*
* @param tenantPath (tenant path where the user exist, null of empty string assumes default tenant)
* @param userName (username)
* @return
*/
@PUT
@Path("/assignAllRolesToUser")
@Consumes({ MediaType.WILDCARD })
@Facet(name = "Unsupported")
public Response assignAllRolesToUser(@QueryParam("tenant") String tenantPath, @QueryParam("userName") String userName) {
IUserRoleDao roleDao = getUserRoleDao();
Set<String> assignedRoles = new HashSet<String>();
for (IPentahoRole pentahoRole : roleDao.getRoles(getTenant(tenantPath))) {
assignedRoles.add(pentahoRole.getName());
}
roleDao.setUserRoles(getTenant(tenantPath), userName, assignedRoles.toArray(new String[0]));
if (userName.equals(getSession().getName())) {
updateRolesForCurrentSession();
}
return Response.ok().build();
}
use of org.pentaho.platform.api.engine.security.userroledao.IUserRoleDao in project pentaho-platform by pentaho.
the class UserRoleDaoServiceTest method testSelfUpdatePasswordWithNotAdminCredentials.
@Test(expected = SecurityException.class)
public void testSelfUpdatePasswordWithNotAdminCredentials() throws Exception {
setupMockSessionUser(SESSION_USER_NAME, false);
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);
}
use of org.pentaho.platform.api.engine.security.userroledao.IUserRoleDao in project pentaho-platform by pentaho.
the class UserRoleDaoServiceTest method testChangePassByAdminSuccess.
@Test
public void testChangePassByAdminSuccess() throws Exception {
setupMockSessionUser(SESSION_USER_NAME, true);
IUserRoleDao roleDao = registerMockUserRoleDao();
addMockUserToUserRoleDao(roleDao, OTHER_USER_NAME, OTHER_USER_PASSWORD);
userRoleService.changeUserPassword(OTHER_USER_NAME, A_NEW_PASSWORD, OTHER_USER_PASSWORD);
}
Aggregations