Search in sources :

Example 1 with Facet

use of org.codehaus.enunciate.Facet in project pentaho-platform by pentaho.

the class UserRoleDaoResource method removeAllRolesFromUser.

/**
 * Remove all roles from the selected user
 *
 * @param tenantPath (tenant path where the user exist, null of empty string assumes default tenant)
 * @param userName   (username)
 * @return
 */
@PUT
@Path("/removeAllRolesFromUser")
@Consumes({ MediaType.WILDCARD })
@Facet(name = "Unsupported")
public Response removeAllRolesFromUser(@QueryParam("tenant") String tenantPath, @QueryParam("userName") String userName) {
    if (canAdminister()) {
        try {
            IUserRoleDao roleDao = getUserRoleDao();
            roleDao.setUserRoles(getTenant(tenantPath), userName, new String[0]);
            if (userName.equals(getSession().getName())) {
                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)

Example 2 with Facet

use of org.codehaus.enunciate.Facet 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 3 with Facet

use of org.codehaus.enunciate.Facet 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 4 with Facet

use of org.codehaus.enunciate.Facet in project pentaho-platform by pentaho.

the class UserRoleDaoResource method assignAllRolesToUser.

/**
 * Associate all roles to the selected user
 *
 * @param tenantPath (tenant path where the user exist, null of empty string assumes default tenant)
 * @param userName   (username)
 * @return
 */
@PUT
@Path("/assignAllRolesToUser")
@Consumes({ MediaType.WILDCARD })
@Facet(name = "Unsupported")
public Response assignAllRolesToUser(@QueryParam("tenant") String tenantPath, @QueryParam("userName") String userName) {
    IUserRoleDao roleDao = getUserRoleDao();
    Set<String> assignedRoles = new HashSet<String>();
    for (IPentahoRole pentahoRole : roleDao.getRoles(getTenant(tenantPath))) {
        assignedRoles.add(pentahoRole.getName());
    }
    roleDao.setUserRoles(getTenant(tenantPath), userName, assignedRoles.toArray(new String[0]));
    if (userName.equals(getSession().getName())) {
        updateRolesForCurrentSession();
    }
    return Response.ok().build();
}
Also used : IPentahoRole(org.pentaho.platform.api.engine.security.userroledao.IPentahoRole) IUserRoleDao(org.pentaho.platform.api.engine.security.userroledao.IUserRoleDao) 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 5 with Facet

use of org.codehaus.enunciate.Facet in project pentaho-platform by pentaho.

the class UserSettingsResource method getUserSetting.

/**
 * Retrieve a particular user setting for the current user
 *
 * @param setting (Name of the setting)
 *
 * @return value of the setting for the user
 */
@GET
@Path("{setting : .+}")
@Facet(name = "Unsupported")
public Response getUserSetting(@PathParam("setting") String setting) {
    IUserSettingService settingsService = getUserSettingService();
    IUserSetting userSetting = settingsService.getUserSetting(setting, null);
    return Response.ok(userSetting != null ? userSetting.getSettingValue() : null).build();
}
Also used : IUserSettingService(org.pentaho.platform.api.usersettings.IUserSettingService) IUserSetting(org.pentaho.platform.api.usersettings.pojo.IUserSetting) Path(javax.ws.rs.Path) GET(javax.ws.rs.GET) Facet(org.codehaus.enunciate.Facet)

Aggregations

Facet (org.codehaus.enunciate.Facet)48 Path (javax.ws.rs.Path)43 Produces (javax.ws.rs.Produces)33 GET (javax.ws.rs.GET)29 ArrayList (java.util.ArrayList)12 Consumes (javax.ws.rs.Consumes)12 POST (javax.ws.rs.POST)8 PentahoAccessControlException (org.pentaho.platform.api.engine.PentahoAccessControlException)8 PUT (javax.ws.rs.PUT)7 IPentahoSession (org.pentaho.platform.api.engine.IPentahoSession)6 IUserRoleDao (org.pentaho.platform.api.engine.security.userroledao.IUserRoleDao)6 Response (javax.ws.rs.core.Response)5 IDatabaseConnection (org.pentaho.database.model.IDatabaseConnection)5 HashSet (java.util.HashSet)4 StringTokenizer (java.util.StringTokenizer)4 StatusCodes (org.codehaus.enunciate.jaxrs.StatusCodes)4 IPluginManager (org.pentaho.platform.api.engine.IPluginManager)4 IMondrianCatalogService (org.pentaho.platform.plugin.action.mondrian.catalog.IMondrianCatalogService)4 ByteArrayOutputStream (java.io.ByteArrayOutputStream)3 IOException (java.io.IOException)3