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