Search in sources :

Example 1 with RestException

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

the class PrivilegeResource method deletePrivilege.

@DELETE
@Produces("application/json")
@Path("/{name}")
public String deletePrivilege(@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);
        pm.remove(name);
        return createResponseJSONString(200, headers, "OK");
    } catch (JSONException e) {
        PrivilegeManager.debug.error("PrivilegeResource.deletePrivilege", e);
        throw getWebApplicationException(e, MimeType.JSON);
    } catch (RestException e) {
        PrivilegeManager.debug.error("PrivilegeResource.deletePrivilege", e);
        throw getWebApplicationException(headers, e, MimeType.JSON);
    } catch (EntitlementException e) {
        PrivilegeManager.debug.error("PrivilegeResource.deletePrivilege", e);
        throw getWebApplicationException(headers, e, MimeType.JSON);
    }
}
Also used : EntitlementException(com.sun.identity.entitlement.EntitlementException) PrivilegeManager(com.sun.identity.entitlement.PrivilegeManager) RestException(com.sun.identity.rest.RestException) JSONException(org.json.JSONException) Subject(javax.security.auth.Subject) Path(javax.ws.rs.Path) DELETE(javax.ws.rs.DELETE) Produces(javax.ws.rs.Produces)

Example 2 with RestException

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

the class PrivilegeResource method modifyPrivilege.

@PUT
@Produces("application/json")
@Path("/{name}")
public String modifyPrivilege(@Context HttpHeaders headers, @Context HttpServletRequest request, @FormParam("realm") @DefaultValue("/") String realm, @FormParam("privilege.json") String jsonString, @PathParam("name") String name) {
    try {
        Subject caller = getCaller(request);
        PrivilegeManager pm = PrivilegeManager.getInstance(realm, caller);
        Privilege privilege = Privilege.getNewInstance(jsonString);
        pm.modify(privilege);
        return createResponseJSONString(200, headers, "OK");
    } catch (JSONException e) {
        PrivilegeManager.debug.error("PrivilegeResource.modify", e);
        throw getWebApplicationException(e, MimeType.JSON);
    } catch (RestException e) {
        PrivilegeManager.debug.error("PrivilegeResource.modify", e);
        throw getWebApplicationException(headers, e, MimeType.JSON);
    } catch (EntitlementException e) {
        PrivilegeManager.debug.error("PrivilegeResource.modify", e);
        throw getWebApplicationException(headers, e, MimeType.JSON);
    }
}
Also used : EntitlementException(com.sun.identity.entitlement.EntitlementException) 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) PUT(javax.ws.rs.PUT)

Example 3 with RestException

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

the class PrivilegeResource method privileges.

@GET
@Produces("application/json")
public String privileges(@Context HttpHeaders headers, @Context HttpServletRequest request, @QueryParam("realm") @DefaultValue("/") String realm, @QueryParam("filter") List filters) {
    try {
        Subject caller = getCaller(request);
        PrivilegeManager pm = PrivilegeManager.getInstance(realm, caller);
        Set<String> privilegeNames = pm.searchNames(getFilters(filters));
        JSONObject jo = new JSONObject();
        jo.put(RESULT, privilegeNames);
        return createResponseJSONString(200, headers, jo);
    } catch (JSONException e) {
        PrivilegeManager.debug.error("PrivilegeResource.privileges", e);
        throw getWebApplicationException(e, MimeType.JSON);
    } catch (RestException e) {
        PrivilegeManager.debug.error("PrivilegeResource.privileges", e);
        throw getWebApplicationException(headers, e, MimeType.JSON);
    } catch (EntitlementException e) {
        PrivilegeManager.debug.error("PrivilegeResource.privileges", 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) Subject(javax.security.auth.Subject) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 4 with RestException

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

the class SSOTokenAuthZ method getAuthZSubject.

public Subject getAuthZSubject(HttpServletRequest req) throws RestException {
    try {
        String tokenId = req.getHeader(RestServiceManager.SUBJECT_HEADER_NAME);
        if ((tokenId == null) || (tokenId.trim().length() == 0)) {
            SSOTokenManager mgr = SSOTokenManager.getInstance();
            SSOToken token = mgr.createSSOToken(req);
            return SubjectUtils.createSubject(token);
        } else {
            int idx = tokenId.indexOf(':');
            if (idx != -1) {
                tokenId = tokenId.substring(idx + 1);
            }
            SSOTokenManager mgr = SSOTokenManager.getInstance();
            SSOToken token = mgr.createSSOToken(tokenId);
            return SubjectUtils.createSubject(token);
        }
    } catch (SSOException ex) {
        throw new RestException(1, ex);
    }
}
Also used : SSOTokenManager(com.iplanet.sso.SSOTokenManager) SSOToken(com.iplanet.sso.SSOToken) RestException(com.sun.identity.rest.RestException) SSOException(com.iplanet.sso.SSOException)

Example 5 with RestException

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

the class PrivilegeResource method createPrivilege.

@POST
@Produces("application/json")
public String createPrivilege(@Context HttpHeaders headers, @Context HttpServletRequest request, @FormParam("realm") @DefaultValue("/") String realm, @FormParam("privilege.json") String jsonString) {
    try {
        Subject caller = getCaller(request);
        PrivilegeManager pm = PrivilegeManager.getInstance(realm, caller);
        Privilege privilege = Privilege.getNewInstance(jsonString);
        pm.add(privilege);
        return createResponseJSONString(201, headers, "Created");
    } catch (JSONException e) {
        PrivilegeManager.debug.error("PrivilegeResource.createPrivilege", e);
        throw getWebApplicationException(e, MimeType.JSON);
    } catch (RestException e) {
        PrivilegeManager.debug.error("PrivilegeResource.createPrivilege", e);
        throw getWebApplicationException(headers, e, MimeType.JSON);
    } catch (EntitlementException e) {
        PrivilegeManager.debug.error("PrivilegeResource.createPrivilege", e);
        throw getWebApplicationException(headers, e, MimeType.JSON);
    }
}
Also used : EntitlementException(com.sun.identity.entitlement.EntitlementException) 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) POST(javax.ws.rs.POST) Produces(javax.ws.rs.Produces)

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