Search in sources :

Example 21 with IPentahoUser

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

the class UserRoleDaoResource method assignUserToRole.

/**
 * Associate list of users to the selected role
 *
 * @param tenantPath (tenant path where the user exist, null of empty string assumes default tenant)
 * @param userNames  (list of tab (\t) separated user names
 * @param roleName   (role name)
 * @return
 */
@PUT
@Path("/assignUserToRole")
@Consumes({ MediaType.WILDCARD })
@Facet(name = "Unsupported")
public Response assignUserToRole(@QueryParam("tenant") String tenantPath, @QueryParam("userNames") String userNames, @QueryParam("roleName") String roleName) {
    if (canAdminister()) {
        IUserRoleDao roleDao = getUserRoleDao();
        StringTokenizer tokenizer = new StringTokenizer(userNames, "\t");
        Set<String> assignedUserNames = new HashSet<String>();
        for (IPentahoUser pentahoUser : roleDao.getRoleMembers(getTenant(tenantPath), roleName)) {
            assignedUserNames.add(pentahoUser.getUsername());
        }
        while (tokenizer.hasMoreTokens()) {
            assignedUserNames.add(tokenizer.nextToken());
        }
        try {
            roleDao.setRoleMembers(getTenant(tenantPath), roleName, assignedUserNames.toArray(new String[0]));
            if (assignedUserNames.contains(getSession().getName())) {
                updateRolesForCurrentSession();
            }
            return Response.ok().build();
        } catch (Throwable th) {
            return processErrorResponse(th.getLocalizedMessage());
        }
    } else {
        return Response.status(Response.Status.UNAUTHORIZED).build();
    }
}
Also used : StringTokenizer(java.util.StringTokenizer) IUserRoleDao(org.pentaho.platform.api.engine.security.userroledao.IUserRoleDao) IPentahoUser(org.pentaho.platform.api.engine.security.userroledao.IPentahoUser) HashSet(java.util.HashSet) Path(javax.ws.rs.Path) Consumes(javax.ws.rs.Consumes) PUT(javax.ws.rs.PUT) Facet(org.codehaus.enunciate.Facet)

Example 22 with IPentahoUser

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

the class UserRoleDaoResource method removeUserFromRole.

/**
 * Remove user(s) from a particular role
 *
 * @param tenantPath (tenant path where the user exist, null of empty string assumes default tenant)
 * @param userNames  (list of tab (\t) separated user names
 * @param roleName   (role name)
 * @return
 */
@PUT
@Path("/removeUserFromRole")
@Consumes({ MediaType.WILDCARD })
@Facet(name = "Unsupported")
public Response removeUserFromRole(@QueryParam("tenant") String tenantPath, @QueryParam("userNames") String userNames, @QueryParam("roleName") String roleName) {
    if (canAdminister()) {
        try {
            IUserRoleDao roleDao = getUserRoleDao();
            StringTokenizer tokenizer = new StringTokenizer(userNames, "\t");
            Set<String> assignedUserNames = new HashSet<String>();
            for (IPentahoUser pentahoUser : roleDao.getRoleMembers(getTenant(tenantPath), roleName)) {
                assignedUserNames.add(pentahoUser.getUsername());
            }
            while (tokenizer.hasMoreTokens()) {
                assignedUserNames.remove(tokenizer.nextToken());
            }
            roleDao.setRoleMembers(getTenant(tenantPath), roleName, assignedUserNames.toArray(new String[0]));
            if (assignedUserNames.contains(getSession().getName())) {
                updateRolesForCurrentSession();
            }
            return Response.ok().build();
        } catch (Throwable th) {
            return processErrorResponse(th.getLocalizedMessage());
        }
    } else {
        return Response.status(Response.Status.UNAUTHORIZED).build();
    }
}
Also used : StringTokenizer(java.util.StringTokenizer) IUserRoleDao(org.pentaho.platform.api.engine.security.userroledao.IUserRoleDao) IPentahoUser(org.pentaho.platform.api.engine.security.userroledao.IPentahoUser) HashSet(java.util.HashSet) Path(javax.ws.rs.Path) Consumes(javax.ws.rs.Consumes) PUT(javax.ws.rs.PUT) Facet(org.codehaus.enunciate.Facet)

Example 23 with IPentahoUser

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

the class UserRoleDaoServiceTest method createMockPentahoUser.

private IPentahoUser createMockPentahoUser(String username, String password) {
    IPentahoUser pentahoUser = mock(IPentahoUser.class);
    doReturn(username).when(pentahoUser).getUsername();
    doReturn(password).when(pentahoUser).getPassword();
    return pentahoUser;
}
Also used : IPentahoUser(org.pentaho.platform.api.engine.security.userroledao.IPentahoUser)

Example 24 with IPentahoUser

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

the class UserRoleDaoServiceTest method testDeleteUsers.

@Test
public void testDeleteUsers() {
    String users = "admin\tsuzy\t";
    setupMockSessionUser(SESSION_USER_NAME, true);
    IPentahoUser user = mock(IPentahoUser.class);
    IUserRoleDao roleDao = mock(IUserRoleDao.class);
    when(roleDao.getUser(any(ITenant.class), anyString())).thenReturn(user);
    PentahoSystem.registerObject(roleDao);
    userRoleService.deleteUsers(users);
    verify(roleDao, times(2)).deleteUser(any(IPentahoUser.class));
}
Also used : ITenant(org.pentaho.platform.api.mt.ITenant) Matchers.anyString(org.mockito.Matchers.anyString) IUserRoleDao(org.pentaho.platform.api.engine.security.userroledao.IUserRoleDao) IPentahoUser(org.pentaho.platform.api.engine.security.userroledao.IPentahoUser) Test(org.junit.Test)

Example 25 with IPentahoUser

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

the class AbstractJcrBackedUserRoleDao method getRoleMembers.

public List<IPentahoUser> getRoleMembers(Session session, final ITenant theTenant, final String roleName) throws RepositoryException {
    List<IPentahoUser> users = new ArrayList<IPentahoUser>();
    Group jackrabbitGroup = getJackrabbitGroup(theTenant, roleName, session);
    if ((jackrabbitGroup != null) && TenantUtils.isAccessibleTenant(theTenant == null ? tenantedRoleNameUtils.getTenant(jackrabbitGroup.getID()) : theTenant)) {
        Iterator<Authorizable> authorizables = jackrabbitGroup.getMembers();
        while (authorizables.hasNext()) {
            Authorizable authorizable = authorizables.next();
            if (authorizable instanceof User) {
                users.add(convertToPentahoUser((User) authorizable));
            }
        }
    }
    return users;
}
Also used : Group(org.apache.jackrabbit.api.security.user.Group) IPentahoUser(org.pentaho.platform.api.engine.security.userroledao.IPentahoUser) User(org.apache.jackrabbit.api.security.user.User) PentahoUser(org.pentaho.platform.security.userroledao.PentahoUser) ArrayList(java.util.ArrayList) Authorizable(org.apache.jackrabbit.api.security.user.Authorizable) 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