Search in sources :

Example 6 with IPentahoUser

use of org.pentaho.platform.api.engine.security.userroledao.IPentahoUser 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 7 with IPentahoUser

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

the class MockUserRoleDao method setUserDescription.

public void setUserDescription(ITenant tenant, String userName, String description) throws NotFoundException, UncategorizedUserRoleDaoException {
    IPentahoUser user = getUser(tenant, userName);
    if (user == null) {
        throw new NotFoundException(userName);
    }
    user.setDescription(description);
}
Also used : NotFoundException(org.pentaho.platform.api.engine.security.userroledao.NotFoundException) IPentahoUser(org.pentaho.platform.api.engine.security.userroledao.IPentahoUser)

Example 8 with IPentahoUser

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

the class MockUserRoleDao method createRole.

public IPentahoRole createRole(ITenant tenant, String roleName, String description, String[] memberUserNames) throws AlreadyExistsException, UncategorizedUserRoleDaoException {
    if (tenant == null) {
        tenant = getTenant(roleName, false);
        roleName = getPrincipalName(roleName, false);
    }
    if (tenant == null || tenant.getId() == null) {
        tenant = getCurrentTenant();
    }
    addTenant(tenant);
    MockPentahoRole role = null;
    HashSet<IPentahoRole> set = tenantRoles.get(tenant);
    if (set != null) {
        for (IPentahoRole iRole : set) {
            if (iRole.getName() == roleName) {
                role = (MockPentahoRole) iRole;
            }
        }
    }
    if (role == null) {
        role = new MockPentahoRole(tenant, roleName, description);
    }
    if (!tenantRoles.get(tenant).contains(role)) {
        tenantRoles.get(tenant).add(role);
        roleMembers.put(role, new HashSet<IPentahoUser>());
    } else {
        throw new AlreadyExistsException(roleName.toString());
    }
    setRoleMembers(tenant, roleName, memberUserNames);
    return role;
}
Also used : AlreadyExistsException(org.pentaho.platform.api.engine.security.userroledao.AlreadyExistsException) IPentahoRole(org.pentaho.platform.api.engine.security.userroledao.IPentahoRole) IPentahoUser(org.pentaho.platform.api.engine.security.userroledao.IPentahoUser)

Example 9 with IPentahoUser

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

the class MockUserRoleDao method setUserRoles.

public void setUserRoles(ITenant tenant, String userName, String[] roleNames) throws NotFoundException, UncategorizedUserRoleDaoException {
    if (tenant == null) {
        tenant = getTenant(userName, true);
        userName = getPrincipalName(userName, true);
    }
    if (tenant == null || tenant.getId() == null) {
        tenant = getCurrentTenant();
    }
    Set<String> roleSet = new HashSet<String>();
    if (roleNames != null) {
        roleSet.addAll(Arrays.asList(roleNames));
    }
    roleSet.add(authenticatedRoleName);
    IPentahoRole authRole = getRole(tenant, authenticatedRoleName);
    IPentahoUser user = getUser(tenant, userName);
    roleMembers.get(authRole).add(user);
    HashSet<IPentahoRole> roles = userRoles.get(user);
    roles.clear();
    for (String roleName : roleSet) {
        IPentahoRole role = getRole(tenant, roleName);
        if (role != null) {
            roles.add(role);
            roleMembers.get(role).add(user);
        }
    }
}
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 10 with IPentahoUser

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

the class MockUserRoleDao method getUserRoles.

public List<IPentahoRole> getUserRoles(ITenant tenant, String userName) throws UncategorizedUserRoleDaoException {
    if (tenant == null) {
        tenant = getTenant(userName, true);
        userName = getPrincipalName(userName, true);
    }
    if (tenant == null || tenant.getId() == null) {
        tenant = getCurrentTenant();
    }
    IPentahoUser user = getUser(tenant, userName);
    return Collections.list(Collections.enumeration(userRoles.get(user)));
}
Also used : IPentahoUser(org.pentaho.platform.api.engine.security.userroledao.IPentahoUser)

Aggregations

IPentahoUser (org.pentaho.platform.api.engine.security.userroledao.IPentahoUser)60 Test (org.junit.Test)23 ArrayList (java.util.ArrayList)16 ITenant (org.pentaho.platform.api.mt.ITenant)15 IUserRoleDao (org.pentaho.platform.api.engine.security.userroledao.IUserRoleDao)13 IPentahoRole (org.pentaho.platform.api.engine.security.userroledao.IPentahoRole)12 NotFoundException (org.pentaho.platform.api.engine.security.userroledao.NotFoundException)11 RepositoryException (javax.jcr.RepositoryException)8 PentahoUser (org.pentaho.platform.security.userroledao.PentahoUser)8 AlreadyExistsException (org.pentaho.platform.api.engine.security.userroledao.AlreadyExistsException)7 HashSet (java.util.HashSet)6 Matchers.anyString (org.mockito.Matchers.anyString)5 IPentahoSession (org.pentaho.platform.api.engine.IPentahoSession)5 IOException (java.io.IOException)4 AccessControlException (javax.jcr.security.AccessControlException)4 Group (org.apache.jackrabbit.api.security.user.Group)4 BeansException (org.springframework.beans.BeansException)4 User (org.apache.jackrabbit.api.security.user.User)3 UncategorizedUserRoleDaoException (org.pentaho.platform.api.engine.security.userroledao.UncategorizedUserRoleDaoException)3 UserListWrapper (org.pentaho.platform.web.http.api.resources.UserListWrapper)3