use of org.pentaho.platform.api.engine.security.userroledao.IPentahoRole 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.IPentahoRole in project pentaho-platform by pentaho.
the class UserRoleWebService method updateRoleObject.
@Override
public boolean updateRoleObject(ProxyPentahoRole proxyPentahoRole) throws UserRoleException {
IPentahoRole role = getDao().getRole(proxyPentahoRole.getTenant(), proxyPentahoRole.getName());
if (role == null) {
throw new UserRoleException(Messages.getInstance().getErrorString("UserRoleWebService.ERROR_0006_ROLE_UPDATE_FAILED", // $NON-NLS-1$
proxyPentahoRole.getName()));
}
getDao().setRoleDescription(proxyPentahoRole.getTenant(), proxyPentahoRole.getName(), proxyPentahoRole.getDescription());
return true;
}
use of org.pentaho.platform.api.engine.security.userroledao.IPentahoRole 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;
}
use of org.pentaho.platform.api.engine.security.userroledao.IPentahoRole in project pentaho-platform by pentaho.
the class AbstractJcrBackedUserRoleDao method getRoles.
public List<IPentahoRole> getRoles(Session session, ITenant theTenant, boolean includeSubtenants) throws RepositoryException {
ArrayList<IPentahoRole> roles = new ArrayList<>();
if (theTenant == null || theTenant.getId() == null) {
theTenant = JcrTenantUtils.getTenant();
}
if (TenantUtils.isAccessibleTenant(theTenant)) {
UserManager userMgr = getUserManager(theTenant, session);
pPrincipalName = getJcrName(session);
Iterator<Authorizable> it = userMgr.findAuthorizables(pPrincipalName, null, UserManager.SEARCH_TYPE_GROUP);
while (it.hasNext()) {
Group group = (Group) it.next();
IPentahoRole pentahoRole = convertToPentahoRole(group);
// Exclude the system role from the list of roles to be returned back
if (!extraRoles.contains(pentahoRole.getName())) {
if (includeSubtenants) {
roles.add(pentahoRole);
} else {
if (pentahoRole.getTenant() != null && pentahoRole.getTenant().equals(theTenant)) {
roles.add(pentahoRole);
}
}
}
}
}
return roles;
}
use of org.pentaho.platform.api.engine.security.userroledao.IPentahoRole in project pentaho-platform by pentaho.
the class AbstractJcrBackedUserRoleDao method convertToPentahoRole.
private IPentahoRole convertToPentahoRole(Group jackrabbitGroup) throws RepositoryException {
IPentahoRole role = null;
Value[] propertyValues = null;
String description = null;
try {
// $NON-NLS-1$
propertyValues = jackrabbitGroup.getProperty("description");
description = propertyValues.length > 0 ? propertyValues[0].getString() : null;
} catch (Exception ex) {
// CHECKSTYLES IGNORE
}
role = new PentahoRole(tenantedRoleNameUtils.getTenant(jackrabbitGroup.getID()), tenantedRoleNameUtils.getPrincipleName(jackrabbitGroup.getID()), description);
return role;
}
Aggregations