use of io.gravitee.am.model.uma.policy.AccessPolicyCondition in project gravitee-access-management by gravitee-io.
the class ResourceAccessPoliciesEndpoint method extractRequest.
private AccessPolicy extractRequest(RoutingContext context) {
try {
// get body request
JsonObject body = context.getBodyAsJson();
// check missing values
Arrays.asList("name", "type", "description", "condition").forEach(key -> {
if (!body.containsKey(key)) {
throw new InvalidRequestException("[" + key + ": must not be null]");
}
});
// check type value
AccessPolicyType accessPolicyType = AccessPolicyType.fromString(body.getString("type"));
// check condition value
AccessPolicyCondition condition = body.getJsonObject("condition").mapTo(accessPolicyType.getConditionClazz());
// create access policy object
AccessPolicy accessPolicy = new AccessPolicy();
accessPolicy.setType(accessPolicyType);
accessPolicy.setName(body.getString("name"));
accessPolicy.setDescription(body.getString("description"));
accessPolicy.setCondition(condition.toString());
accessPolicy.setEnabled(body.getBoolean("enabled", true));
return accessPolicy;
} catch (DecodeException ex) {
throw new InvalidRequestException("Bad request payload");
} catch (Exception ex) {
throw new InvalidRequestException(ex.getMessage());
}
}
Aggregations