Search in sources :

Example 1 with JsonPolicy

use of org.forgerock.openam.entitlement.rest.model.json.JsonPolicy in project OpenAM by OpenRock.

the class JsonPolicyParser method parsePrivilege.

private Privilege parsePrivilege(String providedName, JsonValue jsonValue) throws EntitlementException {
    try {
        // Note: this is a bit ugly as we re-serialise the JsonValue back into a JSON String to then parse it
        // again using Jackson. Unfortunately, that appears to be the easiest way as JsonValue does not support
        // data binding.
        JsonPolicy policy = MAPPER.readValue(jsonValue.toString(), JsonPolicy.class);
        Privilege privilege = policy.asPrivilege();
        if (isBlank(privilege.getName())) {
            privilege.setName(providedName);
        }
        if (isBlank(privilege.getName())) {
            throw new EntitlementException(EntitlementException.MISSING_PRIVILEGE_NAME);
        }
        // Validate the condition if present
        if (privilege.getCondition() != null) {
            privilege.getCondition().validate();
        }
        return privilege;
    } catch (UnrecognizedPropertyException ex) {
        throw new EntitlementException(EntitlementException.INVALID_VALUE, new Object[] { ex.getUnrecognizedPropertyName() });
    } catch (JsonMappingException ex) {
        throw new EntitlementException(EntitlementException.INVALID_JSON, ex, ex.getMessage());
    } catch (IOException e) {
        throw new EntitlementException(EntitlementException.UNABLE_TO_CREATE_POLICY, e);
    }
}
Also used : JsonPolicy(org.forgerock.openam.entitlement.rest.model.json.JsonPolicy) EntitlementException(com.sun.identity.entitlement.EntitlementException) JsonMappingException(com.fasterxml.jackson.databind.JsonMappingException) UnrecognizedPropertyException(com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException) IOException(java.io.IOException) Privilege(com.sun.identity.entitlement.Privilege)

Aggregations

JsonMappingException (com.fasterxml.jackson.databind.JsonMappingException)1 UnrecognizedPropertyException (com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException)1 EntitlementException (com.sun.identity.entitlement.EntitlementException)1 Privilege (com.sun.identity.entitlement.Privilege)1 IOException (java.io.IOException)1 JsonPolicy (org.forgerock.openam.entitlement.rest.model.json.JsonPolicy)1