class PolicyEnforcementRest {

    @POST
    @Consumes(MediaType.APPLICATION_JSON)
    @Produces(MediaType.TEXT_PLAIN)
    @RolesAllowed("user")
    @ApiOperation("Converts user provided request into XACML and evaluates.")
    public Response evaluateRequest(@Context ContainerRequestContext context, String jsonRequest) {
        log.debug("Authorizing...");
        long start = System.currentTimeMillis();

        try {
            JSONObject json = JSONObject.fromObject(jsonRequest);
            IRI subjectId = (IRI) RestUtils.optActiveUser(context, engineManager).map(User::getResource)
                    .orElse(vf.createIRI(ANON_USER));

            String actionIdStr = json.optString("actionId");
            String resourceIdStr = json.optString("resourceId");
            if (StringUtils.isEmpty(actionIdStr) || StringUtils.isEmpty(resourceIdStr)) {
                throw ErrorUtils.sendError("ID is required.", Response.Status.BAD_REQUEST);
            }

            IRI actionId = vf.createIRI(actionIdStr);
            IRI resourceId = vf.createIRI(resourceIdStr);

            Map<String, String> attributes = json.getJSONObject("subjectAttrs");
            Map<String, Literal> subjectAttrs = attributes.entrySet().stream().collect(Collectors.toMap(
                    e -> e.getKey(), e -> vf.createLiteral(e.getValue())));
            attributes = json.getJSONObject("resourceAttrs");
            Map<String, Literal> resourceAttrs = attributes.entrySet().stream().collect(Collectors.toMap(
                    e -> e.getKey(), e -> vf.createLiteral(e.getValue())));
            attributes = json.getJSONObject("actionAttrs");
            Map<String, Literal> actionAttrs = attributes.entrySet().stream().collect(Collectors.toMap(
                    e -> e.getKey(), e -> vf.createLiteral(e.getValue())));

            Request request = pdp.createRequest(subjectId, subjectAttrs, resourceId, resourceAttrs,
                    actionId, actionAttrs);

            log.debug(request.toString());
            com.mobi.security.policy.api.Response response = pdp.evaluate(request,
                    vf.createIRI(POLICY_PERMIT_OVERRIDES));
            log.debug(response.toString());
            log.debug(String.format("Request Evaluated. %dms", System.currentTimeMillis() - start));

            return Response.ok(response.getDecision().toString()).build();
        } catch (IllegalArgumentException | MobiException ex) {
            throw ErrorUtils.sendError("Request could not be evaluated", Response.Status.INTERNAL_SERVER_ERROR);
        }
    }

}