Search in sources :

Example 1 with AccessPolicyType

use of io.gravitee.am.model.uma.policy.AccessPolicyType 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());
    }
}
Also used : AccessPolicyCondition(io.gravitee.am.model.uma.policy.AccessPolicyCondition) AccessPolicyType(io.gravitee.am.model.uma.policy.AccessPolicyType) JsonObject(io.vertx.core.json.JsonObject) InvalidRequestException(io.gravitee.am.common.exception.oauth2.InvalidRequestException) DecodeException(io.vertx.core.json.DecodeException) AccessPolicy(io.gravitee.am.model.uma.policy.AccessPolicy) DecodeException(io.vertx.core.json.DecodeException) InvalidRequestException(io.gravitee.am.common.exception.oauth2.InvalidRequestException) AccessPolicyNotFoundException(io.gravitee.am.service.exception.AccessPolicyNotFoundException)

Aggregations

InvalidRequestException (io.gravitee.am.common.exception.oauth2.InvalidRequestException)1 AccessPolicy (io.gravitee.am.model.uma.policy.AccessPolicy)1 AccessPolicyCondition (io.gravitee.am.model.uma.policy.AccessPolicyCondition)1 AccessPolicyType (io.gravitee.am.model.uma.policy.AccessPolicyType)1 AccessPolicyNotFoundException (io.gravitee.am.service.exception.AccessPolicyNotFoundException)1 DecodeException (io.vertx.core.json.DecodeException)1 JsonObject (io.vertx.core.json.JsonObject)1