Search in sources :

Example 41 with IUserRoleDao

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

the class DefaultDeleteHelper method getUserList.

protected List<String> getUserList() {
    IUserRoleDao userRoleDao = PentahoSystem.get(IUserRoleDao.class);
    List<IPentahoUser> iusers = userRoleDao.getUsers();
    return iusers.stream().map(user -> user.getUsername()).collect(Collectors.toList());
}
Also used : Tenant(org.pentaho.platform.core.mt.Tenant) RepositoryFileDaoFileExistsException(org.pentaho.platform.repository2.unified.exception.RepositoryFileDaoFileExistsException) VersionHistory(javax.jcr.version.VersionHistory) QueryObjectModelConstants(javax.jcr.query.qom.QueryObjectModelConstants) Version(javax.jcr.version.Version) Date(java.util.Date) VersionIterator(javax.jcr.version.VersionIterator) IPentahoUser(org.pentaho.platform.api.engine.security.userroledao.IPentahoUser) QueryResult(javax.jcr.query.QueryResult) Property(javax.jcr.Property) PentahoSystem(org.pentaho.platform.engine.core.system.PentahoSystem) ITenant(org.pentaho.platform.api.mt.ITenant) QueryObjectModelFactory(javax.jcr.query.qom.QueryObjectModelFactory) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) Calendar(java.util.Calendar) RepositoryFileDaoReferentialIntegrityException(org.pentaho.platform.repository2.unified.exception.RepositoryFileDaoReferentialIntegrityException) RepositoryException(javax.jcr.RepositoryException) IAuthorizationPolicy(org.pentaho.platform.api.engine.IAuthorizationPolicy) Node(javax.jcr.Node) PropertyIterator(javax.jcr.PropertyIterator) VersionManager(javax.jcr.version.VersionManager) Lock(javax.jcr.lock.Lock) Query(javax.jcr.query.Query) Session(javax.jcr.Session) Constraint(javax.jcr.query.qom.Constraint) Messages(org.pentaho.platform.repository2.messages.Messages) Set(java.util.Set) Collectors(java.util.stream.Collectors) PentahoSessionHolder(org.pentaho.platform.engine.core.system.PentahoSessionHolder) ServerRepositoryPaths(org.pentaho.platform.repository2.unified.ServerRepositoryPaths) Serializable(java.io.Serializable) IUserRoleDao(org.pentaho.platform.api.engine.security.userroledao.IUserRoleDao) AdministerSecurityAction(org.pentaho.platform.security.policy.rolebased.actions.AdministerSecurityAction) List(java.util.List) Selector(javax.jcr.query.qom.Selector) IPentahoSession(org.pentaho.platform.api.engine.IPentahoSession) RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile) Collections(java.util.Collections) NodeIterator(javax.jcr.NodeIterator) Assert(org.springframework.util.Assert) StringUtils(org.springframework.util.StringUtils) IUserRoleDao(org.pentaho.platform.api.engine.security.userroledao.IUserRoleDao) IPentahoUser(org.pentaho.platform.api.engine.security.userroledao.IPentahoUser)

Example 42 with IUserRoleDao

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

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

the class UserRoleDaoResource method removeAllUsersFromRole.

/**
 * Removes all users from a particular role
 *
 * @param tenantPath (tenant path where the user exist, null of empty string assumes default tenant)
 * @param roleName   (role name)
 * @return
 */
@PUT
@Path("/removeAllUsersFromRole")
@Consumes({ MediaType.WILDCARD })
@Facet(name = "Unsupported")
public Response removeAllUsersFromRole(@QueryParam("tenant") String tenantPath, @QueryParam("roleName") String roleName) {
    if (canAdminister()) {
        try {
            IUserRoleDao roleDao = getUserRoleDao();
            roleDao.setRoleMembers(getTenant(tenantPath), roleName, new String[0]);
            updateRolesForCurrentSession();
            return Response.ok().build();
        } catch (Throwable th) {
            return processErrorResponse(th.getLocalizedMessage());
        }
    } else {
        return Response.status(Response.Status.UNAUTHORIZED).build();
    }
}
Also used : IUserRoleDao(org.pentaho.platform.api.engine.security.userroledao.IUserRoleDao) Path(javax.ws.rs.Path) Consumes(javax.ws.rs.Consumes) PUT(javax.ws.rs.PUT) Facet(org.codehaus.enunciate.Facet)

Aggregations

IUserRoleDao (org.pentaho.platform.api.engine.security.userroledao.IUserRoleDao)43 Test (org.junit.Test)28 IPentahoUser (org.pentaho.platform.api.engine.security.userroledao.IPentahoUser)21 ITenant (org.pentaho.platform.api.mt.ITenant)20 Matchers.anyString (org.mockito.Matchers.anyString)13 IPentahoSession (org.pentaho.platform.api.engine.IPentahoSession)11 ArrayList (java.util.ArrayList)9 User (org.pentaho.platform.web.http.api.resources.User)9 IPentahoRole (org.pentaho.platform.api.engine.security.userroledao.IPentahoRole)8 HashSet (java.util.HashSet)6 Consumes (javax.ws.rs.Consumes)6 PUT (javax.ws.rs.PUT)6 Path (javax.ws.rs.Path)6 Facet (org.codehaus.enunciate.Facet)6 UncategorizedUserRoleDaoException (org.pentaho.platform.api.engine.security.userroledao.UncategorizedUserRoleDaoException)5 AuthenticationProvider (org.springframework.security.authentication.AuthenticationProvider)5 NotFoundException (org.pentaho.platform.api.engine.security.userroledao.NotFoundException)3 Tenant (org.pentaho.platform.core.mt.Tenant)3 UserListWrapper (org.pentaho.platform.web.http.api.resources.UserListWrapper)3 IOException (java.io.IOException)2