Search in sources :

Example 6 with IPentahoRole

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

the class MockUserRoleDao method setRoleDescription.

public void setRoleDescription(ITenant tenant, String roleName, String description) throws NotFoundException, UncategorizedUserRoleDaoException {
    IPentahoRole role = getRole(tenant, roleName);
    if (role == null) {
        throw new NotFoundException(roleName);
    }
    role.setDescription(description);
}
Also used : NotFoundException(org.pentaho.platform.api.engine.security.userroledao.NotFoundException) IPentahoRole(org.pentaho.platform.api.engine.security.userroledao.IPentahoRole)

Example 7 with IPentahoRole

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

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

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

the class MockUserRoleDao method getRoleMembers.

public List<IPentahoUser> getRoleMembers(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();
    }
    IPentahoRole role = getRole(tenant, roleName);
    return Collections.list(Collections.enumeration(roleMembers.get(role)));
}
Also used : IPentahoRole(org.pentaho.platform.api.engine.security.userroledao.IPentahoRole)

Example 10 with IPentahoRole

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

the class MockUserRoleDao method getRoles.

public List<IPentahoRole> getRoles(ITenant tenant, boolean includeSubTenants) throws UncategorizedUserRoleDaoException {
    ArrayList<IPentahoRole> roles = new ArrayList<IPentahoRole>();
    roles.addAll(getRoles(tenant));
    if (includeSubTenants) {
        for (ITenant tmpTenant : tenants) {
            if (tmpTenant.getRootFolderAbsolutePath().startsWith(tenant.getRootFolderAbsolutePath() + "/", 0)) {
                roles.addAll(getRoles(tmpTenant));
            }
        }
    }
    return roles;
}
Also used : ITenant(org.pentaho.platform.api.mt.ITenant) ArrayList(java.util.ArrayList) 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