Search in sources :

Example 6 with RestException

use of com.sun.identity.rest.RestException in project OpenAM by OpenRock.

the class PrivilegeResource method privilege.

@GET
@Produces("application/json")
@Path("/{name}")
public String privilege(@Context HttpHeaders headers, @Context HttpServletRequest request, @QueryParam("realm") @DefaultValue("/") String realm, @PathParam("name") String name) {
    try {
        Subject caller = getCaller(request);
        PrivilegeManager pm = PrivilegeManager.getInstance(realm, caller);
        Privilege privilege = pm.findByName(name);
        JSONObject jo = new JSONObject();
        jo.put(RESULT, privilege.toMinimalJSONObject());
        return createResponseJSONString(200, headers, jo);
    } catch (JSONException e) {
        PrivilegeManager.debug.error("PrivilegeResource.privilege", e);
        throw getWebApplicationException(e, MimeType.JSON);
    } catch (RestException e) {
        PrivilegeManager.debug.error("PrivilegeResource.privilege", e);
        throw getWebApplicationException(headers, e, MimeType.JSON);
    } catch (EntitlementException e) {
        PrivilegeManager.debug.error("PrivilegeResource.privilege", e);
        throw getWebApplicationException(headers, e, MimeType.JSON);
    }
}
Also used : EntitlementException(com.sun.identity.entitlement.EntitlementException) JSONObject(org.json.JSONObject) PrivilegeManager(com.sun.identity.entitlement.PrivilegeManager) RestException(com.sun.identity.rest.RestException) JSONException(org.json.JSONException) Privilege(com.sun.identity.entitlement.Privilege) Subject(javax.security.auth.Subject) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Aggregations

RestException (com.sun.identity.rest.RestException)6 EntitlementException (com.sun.identity.entitlement.EntitlementException)5 PrivilegeManager (com.sun.identity.entitlement.PrivilegeManager)5 Subject (javax.security.auth.Subject)5 Produces (javax.ws.rs.Produces)5 JSONException (org.json.JSONException)5 Privilege (com.sun.identity.entitlement.Privilege)3 Path (javax.ws.rs.Path)3 GET (javax.ws.rs.GET)2 JSONObject (org.json.JSONObject)2 SSOException (com.iplanet.sso.SSOException)1 SSOToken (com.iplanet.sso.SSOToken)1 SSOTokenManager (com.iplanet.sso.SSOTokenManager)1 DELETE (javax.ws.rs.DELETE)1 POST (javax.ws.rs.POST)1 PUT (javax.ws.rs.PUT)1