Search in sources :

Example 31 with IPentahoRole

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]));
}
Also used : IPentahoRole(org.pentaho.platform.api.engine.security.userroledao.IPentahoRole) IPentahoUser(org.pentaho.platform.api.engine.security.userroledao.IPentahoUser) HashSet(java.util.HashSet)

Example 32 with IPentahoRole

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;
}
Also used : IPentahoRole(org.pentaho.platform.api.engine.security.userroledao.IPentahoRole)

Example 33 with IPentahoRole

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;
}
Also used : IPentahoRole(org.pentaho.platform.api.engine.security.userroledao.IPentahoRole) IUserRoleDao(org.pentaho.platform.api.engine.security.userroledao.IUserRoleDao) IPentahoUser(org.pentaho.platform.api.engine.security.userroledao.IPentahoUser)

Example 34 with IPentahoRole

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;
}
Also used : Group(org.apache.jackrabbit.api.security.user.Group) UserManager(org.apache.jackrabbit.api.security.user.UserManager) ArrayList(java.util.ArrayList) Authorizable(org.apache.jackrabbit.api.security.user.Authorizable) IPentahoRole(org.pentaho.platform.api.engine.security.userroledao.IPentahoRole)

Example 35 with IPentahoRole

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;
}
Also used : Value(javax.jcr.Value) IPentahoRole(org.pentaho.platform.api.engine.security.userroledao.IPentahoRole) PentahoRole(org.pentaho.platform.security.userroledao.PentahoRole) IPentahoRole(org.pentaho.platform.api.engine.security.userroledao.IPentahoRole) NotFoundException(org.pentaho.platform.api.engine.security.userroledao.NotFoundException) RepositoryException(javax.jcr.RepositoryException) NamespaceException(javax.jcr.NamespaceException) AuthorizableExistsException(org.apache.jackrabbit.api.security.user.AuthorizableExistsException)

Aggregations

IPentahoRole (org.pentaho.platform.api.engine.security.userroledao.IPentahoRole)48 Test (org.junit.Test)19 ArrayList (java.util.ArrayList)16 IPentahoUser (org.pentaho.platform.api.engine.security.userroledao.IPentahoUser)13 ITenant (org.pentaho.platform.api.mt.ITenant)12 IUserRoleDao (org.pentaho.platform.api.engine.security.userroledao.IUserRoleDao)10 AlreadyExistsException (org.pentaho.platform.api.engine.security.userroledao.AlreadyExistsException)8 HashSet (java.util.HashSet)7 Matchers.anyString (org.mockito.Matchers.anyString)6 NotFoundException (org.pentaho.platform.api.engine.security.userroledao.NotFoundException)6 DefaultTenantedPrincipleNameResolver (org.pentaho.platform.security.userroledao.DefaultTenantedPrincipleNameResolver)6 IOException (java.io.IOException)5 RepositoryException (javax.jcr.RepositoryException)5 AccessControlException (javax.jcr.security.AccessControlException)4 IPentahoSession (org.pentaho.platform.api.engine.IPentahoSession)4 PentahoRole (org.pentaho.platform.security.userroledao.PentahoRole)4 BeansException (org.springframework.beans.BeansException)4 StringTokenizer (java.util.StringTokenizer)2 Group (org.apache.jackrabbit.api.security.user.Group)2 UncategorizedUserRoleDaoException (org.pentaho.platform.api.engine.security.userroledao.UncategorizedUserRoleDaoException)2