use of org.pentaho.platform.api.engine.security.userroledao.IPentahoUser in project pentaho-platform by pentaho.
the class DefaultDeleteHelper method getUserList.
protected List<String> getUserList() {
IUserRoleDao userRoleDao = PentahoSystem.get(IUserRoleDao.class);
List<IPentahoUser> iusers = userRoleDao.getUsers();
return iusers.stream().map(user -> user.getUsername()).collect(Collectors.toList());
}
use of org.pentaho.platform.api.engine.security.userroledao.IPentahoUser in project pentaho-platform by pentaho.
the class DefaultUserRepositoryLifecycleManager method configureUsers.
private void configureUsers() throws PasswordServiceException {
String singleTenantAdminPlainTextPassword = passwordService.decrypt(singleTenantAdminPassword);
String nonAdminPasswordPlainTextPassword = passwordService.decrypt(nonAdminPassword);
for (final String userName : userRoleMappings.keySet()) {
final IPentahoUser user = userRoleDao.getUser(DEFAULT_TENANT, userName);
if (user == null) {
StringBuffer buffer = new StringBuffer();
if (logger.isDebugEnabled()) {
logger.debug("Creating user: " + userName);
}
List<String> roleNames = new ArrayList<String>();
for (String roleName : userRoleMappings.get(userName)) {
if (roleMappings.containsKey(roleName) || systemRoles.contains(roleName)) {
roleNames.add(roleName);
buffer.append(roleName + " ");
} else {
logger.error("Unable to map undefined role to user. User[" + userName + "] Role[" + roleName + "]");
}
}
if (singleTenantAdminUserName.equals(userName)) {
userRoleDao.createUser(DEFAULT_TENANT, userName, singleTenantAdminPlainTextPassword, "user", roleNames.toArray(EMPTY_STRING_ARRAY));
} else {
userRoleDao.createUser(DEFAULT_TENANT, userName, nonAdminPasswordPlainTextPassword, "user", roleNames.toArray(EMPTY_STRING_ARRAY));
}
if (logger.isDebugEnabled()) {
logger.debug("Created user: " + userName + "with role mappings [" + buffer + "]");
}
}
}
}
use of org.pentaho.platform.api.engine.security.userroledao.IPentahoUser in project pentaho-platform by pentaho.
the class UserRoleWebService method updateRole.
@Override
public void updateRole(String roleName, String description, List<String> usernames) throws UserRoleException {
IPentahoRole role = getDao().getRole(null, roleName);
if (role == null) {
throw new UserRoleException(Messages.getInstance().getErrorString("UserRoleWebService.ERROR_0006_ROLE_UPDATE_FAILED", // $NON-NLS-1$
roleName));
}
Set<String> users = new HashSet<String>();
for (String username : usernames) {
IPentahoUser user = getDao().getUser(null, username);
if (user == null) {
throw new UserRoleException(Messages.getInstance().getErrorString("UserRoleWebService.ERROR_0006_ROLE_UPDATE_FAILED", // $NON-NLS-1$
roleName));
}
users.add(user.getUsername());
}
getDao().setRoleDescription(null, roleName, description);
getDao().setRoleMembers(null, roleName, users.toArray(new String[0]));
}
use of org.pentaho.platform.api.engine.security.userroledao.IPentahoUser in project pentaho-platform by pentaho.
the class UserRoleWebService method updateUser.
@Override
public boolean updateUser(ProxyPentahoUser proxyUser) throws UserRoleException {
IPentahoUser user = getDao().getUser(proxyUser.getTenant(), proxyUser.getName());
if (user == null) {
throw new UserRoleException(Messages.getInstance().getErrorString("UserRoleWebService.ERROR_0004_FAILED_TO_FIND_USER", // $NON-NLS-1$
proxyUser.getName()));
}
if (!StringUtils.isBlank(proxyUser.getPassword())) {
getDao().setPassword(proxyUser.getTenant(), proxyUser.getName(), proxyUser.getPassword());
}
getDao().setUserDescription(proxyUser.getTenant(), proxyUser.getName(), proxyUser.getDescription());
return true;
}
use of org.pentaho.platform.api.engine.security.userroledao.IPentahoUser in project pentaho-platform by pentaho.
the class UserRoleWebService method getUserRoleSecurityInfo.
@Override
public UserRoleSecurityInfo getUserRoleSecurityInfo() throws UserRoleException {
UserRoleSecurityInfo userRoleSecurityInfo = new UserRoleSecurityInfo();
IUserRoleDao dao = getDao();
List<IPentahoUser> users = dao.getUsers();
if (users != null) {
for (IPentahoUser user : users) {
userRoleSecurityInfo.getUsers().add(ProxyPentahoUserRoleHelper.toProxyUser(user));
List<IPentahoRole> roles = dao.getUserRoles(user.getTenant(), user.getUsername());
if (roles != null) {
for (IPentahoRole role : roles) {
userRoleSecurityInfo.getAssignments().add(new UserToRoleAssignment(user.getUsername(), role.getName()));
}
}
}
}
userRoleSecurityInfo.getRoles().addAll(Arrays.asList(getRoles()));
return userRoleSecurityInfo;
}
Aggregations