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);
}
}
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);
}
}
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);
}
}
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);
}
}
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);
}
}
Aggregations