Search in sources :

Example 1 with IPentahoRole

use of org.pentaho.platform.api.engine.security.userroledao.IPentahoRole in project pentaho-platform by pentaho.

the class UserRoleWebService method setUsers.

@Override
public void setUsers(ProxyPentahoRole proxyRole, ProxyPentahoUser[] assignedUsers) throws UserRoleException {
    IPentahoRole role = getDao().getRole(proxyRole.getTenant(), proxyRole.getName());
    if (role == null) {
        throw new UserRoleException(Messages.getInstance().getErrorString("UserRoleWebService.ERROR_0005_FAILED_TO_FIND_ROLE", // $NON-NLS-1$
        proxyRole.getName()));
    }
    ArrayList<String> userNames = new ArrayList<String>();
    for (ProxyPentahoUser proxyUser : assignedUsers) {
        userNames.add(proxyUser.getName());
    }
    getDao().setRoleMembers(proxyRole.getTenant(), proxyRole.getName(), userNames.toArray(new String[0]));
}
Also used : ArrayList(java.util.ArrayList) IPentahoRole(org.pentaho.platform.api.engine.security.userroledao.IPentahoRole)

Example 2 with IPentahoRole

use of org.pentaho.platform.api.engine.security.userroledao.IPentahoRole in project pentaho-platform by pentaho.

the class UserRoleWebService method getRoles.

@Override
public ProxyPentahoRole[] getRoles() throws UserRoleException {
    List<ProxyPentahoRole> proxyRoles = new ArrayList<ProxyPentahoRole>();
    List<IPentahoRole> roles = getDao().getRoles();
    if (roles != null) {
        for (IPentahoRole role : roles) {
            proxyRoles.add(ProxyPentahoUserRoleHelper.toProxyRole(role));
        }
    }
    return proxyRoles.toArray(new ProxyPentahoRole[0]);
}
Also used : ArrayList(java.util.ArrayList) IPentahoRole(org.pentaho.platform.api.engine.security.userroledao.IPentahoRole)

Example 3 with IPentahoRole

use of org.pentaho.platform.api.engine.security.userroledao.IPentahoRole in project pentaho-platform by pentaho.

the class UserRoleWebService method getRolesForUser.

@Override
public ProxyPentahoRole[] getRolesForUser(ProxyPentahoUser proxyUser) throws UserRoleException {
    List<ProxyPentahoRole> proxyRoles = new ArrayList<ProxyPentahoRole>();
    IPentahoUser user = getDao().getUser(proxyUser.getTenant(), proxyUser.getName());
    if (user != null) {
        for (IPentahoRole role : getDao().getUserRoles(proxyUser.getTenant(), proxyUser.getName())) {
            proxyRoles.add(ProxyPentahoUserRoleHelper.toProxyRole(role));
        }
    } else {
        throw new UserRoleException(Messages.getInstance().getErrorString("UserRoleWebService.ERROR_0004_FAILED_TO_FIND_USER", // $NON-NLS-1$
        proxyUser.getName()));
    }
    return proxyRoles.toArray(new ProxyPentahoRole[0]);
}
Also used : ArrayList(java.util.ArrayList) IPentahoRole(org.pentaho.platform.api.engine.security.userroledao.IPentahoRole) IPentahoUser(org.pentaho.platform.api.engine.security.userroledao.IPentahoUser)

Example 4 with IPentahoRole

use of org.pentaho.platform.api.engine.security.userroledao.IPentahoRole in project pentaho-platform by pentaho.

the class UserRoleWebService method getUsersForRole.

@Override
public ProxyPentahoUser[] getUsersForRole(ProxyPentahoRole proxyRole) throws UserRoleException {
    ArrayList<ProxyPentahoUser> users = new ArrayList<ProxyPentahoUser>();
    IPentahoRole role = getDao().getRole(proxyRole.getTenant(), proxyRole.getName());
    if (role != null) {
        for (IPentahoUser user : getDao().getRoleMembers(proxyRole.getTenant(), proxyRole.getName())) {
            users.add(ProxyPentahoUserRoleHelper.toProxyUser(user));
        }
    } else {
        throw new UserRoleException(Messages.getInstance().getErrorString("UserRoleWebService.ERROR_0005_FAILED_TO_FIND_ROLE", // $NON-NLS-1$
        proxyRole.getName()));
    }
    return users.toArray(new ProxyPentahoUser[0]);
}
Also used : ArrayList(java.util.ArrayList) IPentahoRole(org.pentaho.platform.api.engine.security.userroledao.IPentahoRole) IPentahoUser(org.pentaho.platform.api.engine.security.userroledao.IPentahoUser)

Example 5 with IPentahoRole

use of org.pentaho.platform.api.engine.security.userroledao.IPentahoRole in project pentaho-platform by pentaho.

the class MockUserRoleDao method getRole.

public IPentahoRole getRole(ITenant tenant, String roleName) throws UncategorizedUserRoleDaoException {
    if (tenant == null) {
        tenant = getTenant(roleName, false);
        roleName = getPrincipalName(roleName, false);
    }
    if (tenant == null || tenant.getId() == null) {
        tenant = getCurrentTenant();
    }
    HashSet<IPentahoRole> roles = tenantRoles.get(tenant);
    if (roles != null) {
        for (IPentahoRole role : roles) {
            if (role.getName().equals(roleName)) {
                return role;
            }
        }
    }
    return null;
}
Also used : IPentahoRole(org.pentaho.platform.api.engine.security.userroledao.IPentahoRole)

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