use of org.pentaho.platform.api.engine.security.userroledao.IUserRoleDao in project pentaho-platform by pentaho.
the class UserRoleDaoServiceTest method testChangeOwnPasswordSuccess.
@Test
public void testChangeOwnPasswordSuccess() throws Exception {
setupMockSessionUser(SESSION_USER_NAME, false);
IUserRoleDao roleDao = registerMockUserRoleDao();
addMockUserToUserRoleDao(roleDao, SESSION_USER_NAME, SESSION_USER_PASSWORD);
userRoleService.changeUserPassword(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 SolutionImportHandler method importRoles.
protected void importRoles(List<RoleExport> roles, Map<String, List<String>> roleToUserMap) {
IUserRoleDao roleDao = PentahoSystem.get(IUserRoleDao.class);
ITenant tenant = new Tenant("/pentaho/" + TenantUtils.getDefaultTenant(), true);
IRoleAuthorizationPolicyRoleBindingDao roleBindingDao = PentahoSystem.get(IRoleAuthorizationPolicyRoleBindingDao.class);
Set<String> existingRoles = new HashSet<>();
if (roles != null) {
for (RoleExport role : roles) {
log.debug("Importing role: " + role.getRolename());
try {
List<String> users = roleToUserMap.get(role.getRolename());
String[] userarray = users == null ? new String[] {} : users.toArray(new String[] {});
IPentahoRole role1 = roleDao.createRole(tenant, role.getRolename(), null, userarray);
} catch (AlreadyExistsException e) {
existingRoles.add(role.getRolename());
// it's ok if the role already exists, it is probably a default role
log.info(Messages.getInstance().getString("ROLE.Already.Exists", role.getRolename()));
}
try {
if (existingRoles.contains(role.getRolename())) {
// Only update an existing role if the overwrite flag is set
if (isOverwriteFile()) {
roleBindingDao.setRoleBindings(tenant, role.getRolename(), role.getPermissions());
}
} else {
// Always write a roles permissions that were not previously existing
roleBindingDao.setRoleBindings(tenant, role.getRolename(), role.getPermissions());
}
} catch (Exception e) {
log.info(Messages.getInstance().getString("ERROR.SettingRolePermissions", role.getRolename()), e);
}
}
}
}
use of org.pentaho.platform.api.engine.security.userroledao.IUserRoleDao 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.IUserRoleDao 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.IUserRoleDao in project pentaho-platform by pentaho.
the class UserRoleDaoServiceTest method testDeleteRole.
@Test
public void testDeleteRole() {
String roles = "role1\trole2\t";
setupMockSessionUser(SESSION_USER_NAME, true);
IPentahoRole role = mock(IPentahoRole.class);
IUserRoleDao roleDao = mock(IUserRoleDao.class);
when(roleDao.getRole(any(ITenant.class), anyString())).thenReturn(role);
PentahoSystem.registerObject(roleDao);
userRoleService.deleteRoles(roles);
verify(roleDao, times(2)).deleteRole(any(IPentahoRole.class));
}
Aggregations