Changesets · Branches · Tags · Compare
| Changeset | efabfe5eda7bef883eddde3b2dccfc48e766504e9e0b45c96f9f6a0e3604eff8 |
|---|---|
| Author | Enrico Risa <enrico.risa@gmail.com> · 2024-09-05 15:58 +02:00 |
| Committer | GitHub <noreply@github.com> · 2024-09-05 15:58 +02:00 |
| Parents | f90faa23e6dd |
36 files changed
modified core/common/lib/policy-engine-lib/src/main/java/org/eclipse/edc/policy/engine/PolicyEngineImpl.java +1 −2
| @@ -156,8 +156,7 @@ | ||
| 156 | 156 | |
| 157 | 157 | @Override |
| 158 | 158 | public PolicyEvaluationPlan createEvaluationPlan(String scope, Policy policy) { |
| 159 | - var delimitedScope = scope + DELIMITER; | |
| 160 | - var planner = PolicyEvaluationPlanner.Builder.newInstance(delimitedScope).ruleValidator(ruleValidator); | |
| 159 | + var planner = PolicyEvaluationPlanner.Builder.newInstance(scope).ruleValidator(ruleValidator); | |
| 161 | 160 | |
| 162 | 161 | preValidators.forEach(planner::preValidators); |
| 163 | 162 | postValidators.forEach(planner::postValidators); |
modified core/common/lib/policy-engine-lib/src/main/java/org/eclipse/edc/policy/engine/plan/PolicyEvaluationPlanner.java +27 −10
| @@ -55,6 +55,7 @@ | ||
| 55 | 55 | import java.util.stream.Collectors; |
| 56 | 56 | |
| 57 | 57 | import static org.eclipse.edc.policy.engine.PolicyEngineImpl.scopeFilter; |
| 58 | +import static org.eclipse.edc.policy.engine.spi.PolicyEngine.DELIMITER; | |
| 58 | 59 | |
| 59 | 60 | public class PolicyEvaluationPlanner implements Policy.Visitor<PolicyEvaluationPlan>, Rule.Visitor<RuleStep<? extends Rule>>, Constraint.Visitor<ConstraintStep> { |
| 60 | 61 | |
| @@ -65,11 +66,13 @@ | ||
| 65 | 66 | private final List<DynamicAtomicConstraintFunctionEntry<Rule>> dynamicConstraintFunctions = new ArrayList<>(); |
| 66 | 67 | private final List<RuleFunctionFunctionEntry<Rule>> ruleFunctions = new ArrayList<>(); |
| 67 | 68 | private final String delimitedScope; |
| 69 | + private final String scope; | |
| 68 | 70 | |
| 69 | 71 | private RuleValidator ruleValidator; |
| 70 | 72 | |
| 71 | - private PolicyEvaluationPlanner(String delimitedScope) { | |
| 72 | - this.delimitedScope = delimitedScope; | |
| 73 | + private PolicyEvaluationPlanner(String scope) { | |
| 74 | + this.scope = scope; | |
| 75 | + this.delimitedScope = scope + DELIMITER; | |
| 73 | 76 | } |
| 74 | 77 | |
| 75 | 78 | @Override |
| @@ -96,9 +99,18 @@ | ||
| 96 | 99 | var currentRule = currentRule(); |
| 97 | 100 | var leftValue = constraint.getLeftExpression().accept(s -> s.getValue().toString()); |
| 98 | 101 | var function = getFunctions(leftValue, currentRule.getClass()); |
| 99 | - var isFiltered = !ruleValidator.isInScope(leftValue, delimitedScope) || function == null; | |
| 100 | 102 | |
| 101 | - return new AtomicConstraintStep(constraint, isFiltered, currentRule, function); | |
| 103 | + var filteringReasons = new ArrayList<String>(); | |
| 104 | + | |
| 105 | + if (!ruleValidator.isInScope(leftValue, delimitedScope)) { | |
| 106 | + filteringReasons.add("leftOperand '%s' is not bound to scope '%s'".formatted(leftValue, scope)); | |
| 107 | + } | |
| 108 | + | |
| 109 | + if (function == null) { | |
| 110 | + filteringReasons.add("leftOperand '%s' is not bound to any function within scope '%s'".formatted(leftValue, scope)); | |
| 111 | + } | |
| 112 | + | |
| 113 | + return new AtomicConstraintStep(constraint, filteringReasons, currentRule, function); | |
| 102 | 114 | } |
| 103 | 115 | |
| 104 | 116 | @Override |
| @@ -115,7 +127,7 @@ | ||
| 115 | 127 | |
| 116 | 128 | policy.getObligations().stream().map(obligation -> obligation.accept(this)) |
| 117 | 129 | .map(DutyStep.class::cast) |
| 118 | - .forEach(builder::obligation); | |
| 130 | + .forEach(builder::duty); | |
| 119 | 131 | |
| 120 | 132 | policy.getProhibitions().stream().map(permission -> permission.accept(this)) |
| 121 | 133 | .map(ProhibitionStep.class::cast) |
| @@ -169,7 +181,11 @@ | ||
| 169 | 181 | |
| 170 | 182 | try { |
| 171 | 183 | ruleContext.push(rule); |
| 172 | - builder.filtered(shouldIgnoreRule(rule)); | |
| 184 | + | |
| 185 | + if (rule.getAction() != null && !ruleValidator.isBounded(rule.getAction().getType())) { | |
| 186 | + builder.filtered(true); | |
| 187 | + builder.filteringReason("action '%s' is not bound to scope '%s'".formatted(rule.getAction().getType(), scope)); | |
| 188 | + } | |
| 173 | 189 | builder.rule(rule); |
| 174 | 190 | |
| 175 | 191 | for (var functionEntry : ruleFunctions) { |
| @@ -192,10 +208,6 @@ | ||
| 192 | 208 | return ruleContext.peek(); |
| 193 | 209 | } |
| 194 | 210 | |
| 195 | - private boolean shouldIgnoreRule(Rule rule) { | |
| 196 | - return rule.getAction() != null && !ruleValidator.isBounded(rule.getAction().getType()); | |
| 197 | - } | |
| 198 | - | |
| 199 | 211 | private List<ConstraintStep> validateMultiplicityConstraint(MultiplicityConstraint multiplicityConstraint) { |
| 200 | 212 | return multiplicityConstraint.getConstraints() |
| 201 | 213 | .stream() |
| @@ -235,6 +247,11 @@ | ||
| 235 | 247 | public Result<Void> validate(Operator operator, Object rightValue, R rule) { |
| 236 | 248 | return inner.validate(leftOperand, operator, rightValue, rule); |
| 237 | 249 | } |
| 250 | + | |
| 251 | + @Override | |
| 252 | + public String name() { | |
| 253 | + return inner.name(); | |
| 254 | + } | |
| 238 | 255 | } |
| 239 | 256 | |
| 240 | 257 | public static class Builder { |
modified core/common/lib/policy-engine-lib/src/test/java/org/eclipse/edc/policy/engine/PolicyEngineImplPlannerTest.java +4 −3
| @@ -240,7 +240,7 @@ | ||
| 240 | 240 | var prohibition = Prohibition.Builder.newInstance().constraint(constraint).action(action).build(); |
| 241 | 241 | |
| 242 | 242 | Function<PolicyEvaluationPlan, List<? extends RuleStep<? extends Rule>>> permissionSteps = PolicyEvaluationPlan::getPermissionSteps; |
| 243 | - Function<PolicyEvaluationPlan, List<? extends RuleStep<? extends Rule>>> dutySteps = PolicyEvaluationPlan::getDutySteps; | |
| 243 | + Function<PolicyEvaluationPlan, List<? extends RuleStep<? extends Rule>>> dutySteps = PolicyEvaluationPlan::getObligationSteps; | |
| 244 | 244 | Function<PolicyEvaluationPlan, List<? extends RuleStep<? extends Rule>>> prohibitionSteps = PolicyEvaluationPlan::getProhibitionSteps; |
| 245 | 245 | |
| 246 | 246 | var permission = Permission.Builder.newInstance().constraint(constraint).action(action).build(); |
| @@ -275,6 +275,7 @@ | ||
| 275 | 275 | .first() |
| 276 | 276 | .satisfies(permissionStep -> { |
| 277 | 277 | assertThat(permissionStep.isFiltered()).isTrue(); |
| 278 | + assertThat(permissionStep.getFilteringReasons()).hasSize(1); | |
| 278 | 279 | assertThat(permissionStep.getConstraintSteps()).hasSize(1) |
| 279 | 280 | .first() |
| 280 | 281 | .isInstanceOfSatisfying(AtomicConstraintStep.class, constraintStep -> { |
| @@ -388,7 +389,7 @@ | ||
| 388 | 389 | assertThat(ruleStep.getConstraintSteps()).hasSize(1) |
| 389 | 390 | .first() |
| 390 | 391 | .isInstanceOfSatisfying(MultiplicityConstraintStep.class, constraintStep -> { |
| 391 | - assertThat(constraintStep.getSteps()).hasSize(2); | |
| 392 | + assertThat(constraintStep.getConstraintSteps()).hasSize(2); | |
| 392 | 393 | assertThat(constraintStep.getConstraint()).isNotNull(); |
| 393 | 394 | }); |
| 394 | 395 | })); |
| @@ -414,7 +415,7 @@ | ||
| 414 | 415 | var duty = Duty.Builder.newInstance().constraint(xoneConstraint).build(); |
| 415 | 416 | |
| 416 | 417 | Function<PolicyEvaluationPlan, List<? extends RuleStep<? extends Rule>>> permissionSteps = PolicyEvaluationPlan::getPermissionSteps; |
| 417 | - Function<PolicyEvaluationPlan, List<? extends RuleStep<? extends Rule>>> dutySteps = PolicyEvaluationPlan::getDutySteps; | |
| 418 | + Function<PolicyEvaluationPlan, List<? extends RuleStep<? extends Rule>>> dutySteps = PolicyEvaluationPlan::getObligationSteps; | |
| 418 | 419 | Function<PolicyEvaluationPlan, List<? extends RuleStep<? extends Rule>>> prohibitionSteps = PolicyEvaluationPlan::getProhibitionSteps; |
| 419 | 420 | |
| 420 | 421 | return Stream.of( |
modified core/control-plane/control-plane-aggregate-services/src/main/java/org/eclipse/edc/connector/controlplane/services/policydefinition/PolicyDefinitionServiceImpl.java +12 −3
| @@ -21,6 +21,7 @@ | ||
| 21 | 21 | import org.eclipse.edc.connector.controlplane.services.query.QueryValidator; |
| 22 | 22 | import org.eclipse.edc.connector.controlplane.services.spi.policydefinition.PolicyDefinitionService; |
| 23 | 23 | import org.eclipse.edc.policy.engine.spi.PolicyEngine; |
| 24 | +import org.eclipse.edc.policy.engine.spi.plan.PolicyEvaluationPlan; | |
| 24 | 25 | import org.eclipse.edc.policy.model.AndConstraint; |
| 25 | 26 | import org.eclipse.edc.policy.model.AtomicConstraint; |
| 26 | 27 | import org.eclipse.edc.policy.model.Constraint; |
| @@ -31,7 +32,6 @@ | ||
| 31 | 32 | import org.eclipse.edc.policy.model.Policy; |
| 32 | 33 | import org.eclipse.edc.policy.model.XoneConstraint; |
| 33 | 34 | import org.eclipse.edc.spi.query.QuerySpec; |
| 34 | -import org.eclipse.edc.spi.result.Result; | |
| 35 | 35 | import org.eclipse.edc.spi.result.ServiceResult; |
| 36 | 36 | import org.eclipse.edc.transaction.spi.TransactionContext; |
| 37 | 37 | import org.jetbrains.annotations.NotNull; |
| @@ -124,8 +124,17 @@ | ||
| 124 | 124 | } |
| 125 | 125 | |
| 126 | 126 | @Override |
| 127 | - public Result<Void> validate(Policy policy) { | |
| 128 | - return policyEngine.validate(policy); | |
| 127 | + public ServiceResult<Void> validate(Policy policy) { | |
| 128 | + var validationResult = policyEngine.validate(policy); | |
| 129 | + if (validationResult.failed()) { | |
| 130 | + return ServiceResult.badRequest(validationResult.getFailureMessages()); | |
| 131 | + } | |
| 132 | + return ServiceResult.success(); | |
| 133 | + } | |
| 134 | + | |
| 135 | + @Override | |
| 136 | + public ServiceResult<PolicyEvaluationPlan> createEvaluationPlan(String scope, Policy policy) { | |
| 137 | + return ServiceResult.success(policyEngine.createEvaluationPlan(scope, policy)); | |
| 129 | 138 | } |
| 130 | 139 | |
| 131 | 140 | private List<PolicyDefinition> queryPolicyDefinitions(QuerySpec query) { |
modified extensions/common/api/management-api-configuration/src/main/resources/management-api-version.json +1 −1
| @@ -8,7 +8,7 @@ | ||
| 8 | 8 | { |
| 9 | 9 | "version": "3.1.0-alpha", |
| 10 | 10 | "urlPath": "/v3.1alpha", |
| 11 | - "lastUpdated": "2024-08-30T10:17:00Z", | |
| 11 | + "lastUpdated": "2024-09-04T10:17:00Z", | |
| 12 | 12 | "maturity": "alpha" |
| 13 | 13 | } |
| 14 | 14 | ] |
modified extensions/control-plane/api/management-api/policy-definition-api/src/main/java/org/eclipse/edc/connector/controlplane/api/management/policy/BasePolicyDefinitionApiController.java +1 −1
| @@ -40,7 +40,7 @@ | ||
| 40 | 40 | protected final Monitor monitor; |
| 41 | 41 | protected final PolicyDefinitionService service; |
| 42 | 42 | protected final TypeTransformerRegistry transformerRegistry; |
| 43 | - private final JsonObjectValidatorRegistry validatorRegistry; | |
| 43 | + protected final JsonObjectValidatorRegistry validatorRegistry; | |
| 44 | 44 | |
| 45 | 45 | public BasePolicyDefinitionApiController(Monitor monitor, TypeTransformerRegistry transformerRegistry, |
| 46 | 46 | PolicyDefinitionService service, JsonObjectValidatorRegistry validatorRegistry) { |
modified extensions/control-plane/api/management-api/policy-definition-api/src/main/java/org/eclipse/edc/connector/controlplane/api/management/policy/PolicyDefinitionApiExtension.java +7 −0
| @@ -16,12 +16,15 @@ | ||
| 16 | 16 | |
| 17 | 17 | import jakarta.json.Json; |
| 18 | 18 | import org.eclipse.edc.connector.controlplane.api.management.policy.transform.JsonObjectFromPolicyDefinitionTransformer; |
| 19 | +import org.eclipse.edc.connector.controlplane.api.management.policy.transform.JsonObjectFromPolicyEvaluationPlanTransformer; | |
| 19 | 20 | import org.eclipse.edc.connector.controlplane.api.management.policy.transform.JsonObjectFromPolicyValidationResultTransformer; |
| 20 | 21 | import org.eclipse.edc.connector.controlplane.api.management.policy.transform.JsonObjectToPolicyDefinitionTransformer; |
| 22 | +import org.eclipse.edc.connector.controlplane.api.management.policy.transform.JsonObjectToPolicyEvaluationPlanRequestTransformer; | |
| 21 | 23 | import org.eclipse.edc.connector.controlplane.api.management.policy.v2.PolicyDefinitionApiV2Controller; |
| 22 | 24 | import org.eclipse.edc.connector.controlplane.api.management.policy.v3.PolicyDefinitionApiV3Controller; |
| 23 | 25 | import org.eclipse.edc.connector.controlplane.api.management.policy.v31alpha.PolicyDefinitionApiV31AlphaController; |
| 24 | 26 | import org.eclipse.edc.connector.controlplane.api.management.policy.validation.PolicyDefinitionValidator; |
| 27 | +import org.eclipse.edc.connector.controlplane.api.management.policy.validation.PolicyEvaluationPlanRequestValidator; | |
| 25 | 28 | import org.eclipse.edc.connector.controlplane.services.spi.policydefinition.PolicyDefinitionService; |
| 26 | 29 | import org.eclipse.edc.runtime.metamodel.annotation.Extension; |
| 27 | 30 | import org.eclipse.edc.runtime.metamodel.annotation.Inject; |
| @@ -35,6 +38,7 @@ | ||
| 35 | 38 | |
| 36 | 39 | import java.util.Map; |
| 37 | 40 | |
| 41 | +import static org.eclipse.edc.connector.controlplane.api.management.policy.model.PolicyEvaluationPlanRequest.EDC_POLICY_EVALUATION_PLAN_REQUEST_TYPE; | |
| 38 | 42 | import static org.eclipse.edc.connector.controlplane.policy.spi.PolicyDefinition.EDC_POLICY_DEFINITION_TYPE; |
| 39 | 43 | import static org.eclipse.edc.spi.constants.CoreConstants.JSON_LD; |
| 40 | 44 | |
| @@ -69,11 +73,14 @@ | ||
| 69 | 73 | var jsonBuilderFactory = Json.createBuilderFactory(Map.of()); |
| 70 | 74 | var managementApiTransformerRegistry = transformerRegistry.forContext("management-api"); |
| 71 | 75 | var mapper = typeManager.getMapper(JSON_LD); |
| 76 | + managementApiTransformerRegistry.register(new JsonObjectToPolicyEvaluationPlanRequestTransformer()); | |
| 72 | 77 | managementApiTransformerRegistry.register(new JsonObjectToPolicyDefinitionTransformer()); |
| 73 | 78 | managementApiTransformerRegistry.register(new JsonObjectFromPolicyDefinitionTransformer(jsonBuilderFactory, mapper)); |
| 74 | 79 | managementApiTransformerRegistry.register(new JsonObjectFromPolicyValidationResultTransformer(jsonBuilderFactory)); |
| 80 | + managementApiTransformerRegistry.register(new JsonObjectFromPolicyEvaluationPlanTransformer(jsonBuilderFactory)); | |
| 75 | 81 | |
| 76 | 82 | validatorRegistry.register(EDC_POLICY_DEFINITION_TYPE, PolicyDefinitionValidator.instance()); |
| 83 | + validatorRegistry.register(EDC_POLICY_EVALUATION_PLAN_REQUEST_TYPE, PolicyEvaluationPlanRequestValidator.instance()); | |
| 77 | 84 | |
| 78 | 85 | var monitor = context.getMonitor(); |
| 79 | 86 | webService.registerResource(ApiContext.MANAGEMENT, new PolicyDefinitionApiV2Controller(monitor, managementApiTransformerRegistry, service, validatorRegistry)); |
added extensions/control-plane/api/management-api/policy-definition-api/src/main/java/org/eclipse/edc/connector/controlplane/api/management/policy/model/PolicyEvaluationPlanRequest.java +22 −0
| @@ -0,0 +1,22 @@ | ||
| 1 | +/* | |
| 2 | + * Copyright (c) 2024 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) | |
| 3 | + * | |
| 4 | + * This program and the accompanying materials are made available under the | |
| 5 | + * terms of the Apache License, Version 2.0 which is available at | |
| 6 | + * https://www.apache.org/licenses/LICENSE-2.0 | |
| 7 | + * | |
| 8 | + * SPDX-License-Identifier: Apache-2.0 | |
| 9 | + * | |
| 10 | + * Contributors: | |
| 11 | + * Bayerische Motoren Werke Aktiengesellschaft (BMW AG) - initial API and implementation | |
| 12 | + * | |
| 13 | + */ | |
| 14 | + | |
| 15 | +package org.eclipse.edc.connector.controlplane.api.management.policy.model; | |
| 16 | + | |
| 17 | +import static org.eclipse.edc.spi.constants.CoreConstants.EDC_NAMESPACE; | |
| 18 | + | |
| 19 | +public record PolicyEvaluationPlanRequest(String policyScope) { | |
| 20 | + public static final String EDC_POLICY_EVALUATION_PLAN_REQUEST_TYPE = EDC_NAMESPACE + "PolicyEvaluationPlanRequest"; | |
| 21 | + public static final String EDC_POLICY_EVALUATION_PLAN_REQUEST_POLICY_SCOPE = EDC_NAMESPACE + "policyScope"; | |
| 22 | +} |
added extensions/control-plane/api/management-api/policy-definition-api/src/main/java/org/eclipse/edc/connector/controlplane/api/management/policy/transform/JsonObjectFromPolicyEvaluationPlanTransformer.java +200 −0
| @@ -0,0 +1,200 @@ | ||
| 1 | +/* | |
| 2 | + * Copyright (c) 2024 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) | |
| 3 | + * | |
| 4 | + * This program and the accompanying materials are made available under the | |
| 5 | + * terms of the Apache License, Version 2.0 which is available at | |
| 6 | + * https://www.apache.org/licenses/LICENSE-2.0 | |
| 7 | + * | |
| 8 | + * SPDX-License-Identifier: Apache-2.0 | |
| 9 | + * | |
| 10 | + * Contributors: | |
| 11 | + * Bayerische Motoren Werke Aktiengesellschaft (BMW AG) - initial API and implementation | |
| 12 | + * | |
| 13 | + */ | |
| 14 | + | |
| 15 | +package org.eclipse.edc.connector.controlplane.api.management.policy.transform; | |
| 16 | + | |
| 17 | +import jakarta.json.JsonBuilderFactory; | |
| 18 | +import jakarta.json.JsonObject; | |
| 19 | +import jakarta.json.JsonObjectBuilder; | |
| 20 | +import org.eclipse.edc.jsonld.spi.transformer.AbstractJsonLdTransformer; | |
| 21 | +import org.eclipse.edc.policy.engine.spi.plan.PolicyEvaluationPlan; | |
| 22 | +import org.eclipse.edc.policy.engine.spi.plan.step.AndConstraintStep; | |
| 23 | +import org.eclipse.edc.policy.engine.spi.plan.step.AtomicConstraintStep; | |
| 24 | +import org.eclipse.edc.policy.engine.spi.plan.step.ConstraintStep; | |
| 25 | +import org.eclipse.edc.policy.engine.spi.plan.step.DutyStep; | |
| 26 | +import org.eclipse.edc.policy.engine.spi.plan.step.MultiplicityConstraintStep; | |
| 27 | +import org.eclipse.edc.policy.engine.spi.plan.step.OrConstraintStep; | |
| 28 | +import org.eclipse.edc.policy.engine.spi.plan.step.PermissionStep; | |
| 29 | +import org.eclipse.edc.policy.engine.spi.plan.step.ProhibitionStep; | |
| 30 | +import org.eclipse.edc.policy.engine.spi.plan.step.RuleFunctionStep; | |
| 31 | +import org.eclipse.edc.policy.engine.spi.plan.step.RuleStep; | |
| 32 | +import org.eclipse.edc.policy.engine.spi.plan.step.ValidatorStep; | |
| 33 | +import org.eclipse.edc.policy.engine.spi.plan.step.XoneConstraintStep; | |
| 34 | +import org.eclipse.edc.policy.model.MultiplicityConstraint; | |
| 35 | +import org.eclipse.edc.policy.model.Rule; | |
| 36 | +import org.eclipse.edc.transform.spi.TransformerContext; | |
| 37 | +import org.jetbrains.annotations.NotNull; | |
| 38 | +import org.jetbrains.annotations.Nullable; | |
| 39 | + | |
| 40 | +import java.util.Optional; | |
| 41 | + | |
| 42 | +import static org.eclipse.edc.jsonld.spi.JsonLdKeywords.TYPE; | |
| 43 | +import static org.eclipse.edc.policy.engine.spi.plan.PolicyEvaluationPlan.EDC_POLICY_EVALUATION_PLAN_OBLIGATION_STEPS; | |
| 44 | +import static org.eclipse.edc.policy.engine.spi.plan.PolicyEvaluationPlan.EDC_POLICY_EVALUATION_PLAN_PERMISSION_STEPS; | |
| 45 | +import static org.eclipse.edc.policy.engine.spi.plan.PolicyEvaluationPlan.EDC_POLICY_EVALUATION_PLAN_POST_VALIDATORS; | |
| 46 | +import static org.eclipse.edc.policy.engine.spi.plan.PolicyEvaluationPlan.EDC_POLICY_EVALUATION_PLAN_PRE_VALIDATORS; | |
| 47 | +import static org.eclipse.edc.policy.engine.spi.plan.PolicyEvaluationPlan.EDC_POLICY_EVALUATION_PLAN_PROHIBITION_STEPS; | |
| 48 | +import static org.eclipse.edc.policy.engine.spi.plan.PolicyEvaluationPlan.EDC_POLICY_EVALUATION_PLAN_TYPE; | |
| 49 | +import static org.eclipse.edc.policy.engine.spi.plan.step.AndConstraintStep.EDC_AND_CONSTRAINT_STEP_TYPE; | |
| 50 | +import static org.eclipse.edc.policy.engine.spi.plan.step.AtomicConstraintStep.EDC_ATOMIC_CONSTRAINT_STEP_FILTERING_REASONS; | |
| 51 | +import static org.eclipse.edc.policy.engine.spi.plan.step.AtomicConstraintStep.EDC_ATOMIC_CONSTRAINT_STEP_FUNCTION_NAME; | |
| 52 | +import static org.eclipse.edc.policy.engine.spi.plan.step.AtomicConstraintStep.EDC_ATOMIC_CONSTRAINT_STEP_FUNCTION_PARAMS; | |
| 53 | +import static org.eclipse.edc.policy.engine.spi.plan.step.AtomicConstraintStep.EDC_ATOMIC_CONSTRAINT_STEP_IS_FILTERED; | |
| 54 | +import static org.eclipse.edc.policy.engine.spi.plan.step.AtomicConstraintStep.EDC_ATOMIC_CONSTRAINT_STEP_TYPE; | |
| 55 | +import static org.eclipse.edc.policy.engine.spi.plan.step.DutyStep.EDC_DUTY_STEP_TYPE; | |
| 56 | +import static org.eclipse.edc.policy.engine.spi.plan.step.MultiplicityConstraintStep.EDC_MULTIPLICITY_CONSTRAINT_STEPS; | |
| 57 | +import static org.eclipse.edc.policy.engine.spi.plan.step.OrConstraintStep.EDC_OR_CONSTRAINT_STEP_TYPE; | |
| 58 | +import static org.eclipse.edc.policy.engine.spi.plan.step.PermissionStep.EDC_PERMISSION_STEP_DUTY_STEPS; | |
| 59 | +import static org.eclipse.edc.policy.engine.spi.plan.step.PermissionStep.EDC_PERMISSION_STEP_TYPE; | |
| 60 | +import static org.eclipse.edc.policy.engine.spi.plan.step.ProhibitionStep.EDC_PROHIBITION_STEP_TYPE; | |
| 61 | +import static org.eclipse.edc.policy.engine.spi.plan.step.RuleStep.EDC_RULE_CONSTRAINT_STEPS; | |
| 62 | +import static org.eclipse.edc.policy.engine.spi.plan.step.RuleStep.EDC_RULE_FUNCTIONS; | |
| 63 | +import static org.eclipse.edc.policy.engine.spi.plan.step.RuleStep.EDC_RULE_STEP_FILTERING_REASONS; | |
| 64 | +import static org.eclipse.edc.policy.engine.spi.plan.step.RuleStep.EDC_RULE_STEP_IS_FILTERED; | |
| 65 | +import static org.eclipse.edc.policy.engine.spi.plan.step.XoneConstraintStep.EDC_XONE_CONSTRAINT_STEP_TYPE; | |
| 66 | + | |
| 67 | +public class JsonObjectFromPolicyEvaluationPlanTransformer extends AbstractJsonLdTransformer<PolicyEvaluationPlan, JsonObject> { | |
| 68 | + | |
| 69 | + private final JsonBuilderFactory jsonFactory; | |
| 70 | + | |
| 71 | + public JsonObjectFromPolicyEvaluationPlanTransformer(JsonBuilderFactory jsonFactory) { | |
| 72 | + super(PolicyEvaluationPlan.class, JsonObject.class); | |
| 73 | + this.jsonFactory = jsonFactory; | |
| 74 | + } | |
| 75 | + | |
| 76 | + @Override | |
| 77 | + public @Nullable JsonObject transform(@NotNull PolicyEvaluationPlan plan, @NotNull TransformerContext context) { | |
| 78 | + var objectBuilder = jsonFactory.createObjectBuilder(); | |
| 79 | + objectBuilder.add(TYPE, EDC_POLICY_EVALUATION_PLAN_TYPE); | |
| 80 | + | |
| 81 | + var preValidators = jsonFactory.createArrayBuilder(); | |
| 82 | + plan.getPreValidators().stream().map(ValidatorStep::name).forEach(preValidators::add); | |
| 83 | + | |
| 84 | + var postValidators = jsonFactory.createArrayBuilder(); | |
| 85 | + plan.getPostValidators().stream().map(ValidatorStep::name).forEach(postValidators::add); | |
| 86 | + | |
| 87 | + var permissionSteps = jsonFactory.createArrayBuilder(); | |
| 88 | + plan.getPermissionSteps().stream().map(this::transformPermissionStep) | |
| 89 | + .forEach(permissionSteps::add); | |
| 90 | + | |
| 91 | + var prohibitionSteps = jsonFactory.createArrayBuilder(); | |
| 92 | + plan.getProhibitionSteps().stream().map(this::transformProhibitionStep) | |
| 93 | + .forEach(prohibitionSteps::add); | |
| 94 | + | |
| 95 | + var dutySteps = jsonFactory.createArrayBuilder(); | |
| 96 | + plan.getObligationSteps().stream().map(this::transformDutyStep) | |
| 97 | + .forEach(dutySteps::add); | |
| 98 | + | |
| 99 | + objectBuilder.add(EDC_POLICY_EVALUATION_PLAN_PRE_VALIDATORS, preValidators); | |
| 100 | + objectBuilder.add(EDC_POLICY_EVALUATION_PLAN_PERMISSION_STEPS, permissionSteps); | |
| 101 | + objectBuilder.add(EDC_POLICY_EVALUATION_PLAN_PROHIBITION_STEPS, prohibitionSteps); | |
| 102 | + objectBuilder.add(EDC_POLICY_EVALUATION_PLAN_OBLIGATION_STEPS, dutySteps); | |
| 103 | + objectBuilder.add(EDC_POLICY_EVALUATION_PLAN_POST_VALIDATORS, postValidators); | |
| 104 | + | |
| 105 | + return objectBuilder.build(); | |
| 106 | + } | |
| 107 | + | |
| 108 | + private JsonObjectBuilder transformDutyStep(DutyStep dutyStep) { | |
| 109 | + return transformRuleStep(dutyStep, EDC_DUTY_STEP_TYPE); | |
| 110 | + } | |
| 111 | + | |
| 112 | + private JsonObjectBuilder transformPermissionStep(PermissionStep permissionStep) { | |
| 113 | + var dutySteps = jsonFactory.createArrayBuilder(); | |
| 114 | + | |
| 115 | + permissionStep.getDutySteps().stream().map(this::transformDutyStep) | |
| 116 | + .forEach(dutySteps::add); | |
| 117 | + | |
| 118 | + return transformRuleStep(permissionStep, EDC_PERMISSION_STEP_TYPE) | |
| 119 | + .add(EDC_PERMISSION_STEP_DUTY_STEPS, dutySteps); | |
| 120 | + } | |
| 121 | + | |
| 122 | + private JsonObjectBuilder transformProhibitionStep(ProhibitionStep prohibitionStep) { | |
| 123 | + return transformRuleStep(prohibitionStep, EDC_PROHIBITION_STEP_TYPE); | |
| 124 | + } | |
| 125 | + | |
| 126 | + private <R extends Rule> JsonObjectBuilder transformRuleStep(RuleStep<R> ruleStep, String type) { | |
| 127 | + | |
| 128 | + var builder = jsonFactory.createObjectBuilder(); | |
| 129 | + var constraintSteps = jsonFactory.createArrayBuilder(); | |
| 130 | + var ruleFunctionSteps = jsonFactory.createArrayBuilder(); | |
| 131 | + | |
| 132 | + ruleStep.getConstraintSteps().stream() | |
| 133 | + .map(this::transformConstraintStep) | |
| 134 | + .forEach(constraintSteps::add); | |
| 135 | + | |
| 136 | + ruleStep.getRuleFunctions().stream() | |
| 137 | + .map(RuleFunctionStep::functionName) | |
| 138 | + .forEach(ruleFunctionSteps::add); | |
| 139 | + | |
| 140 | + builder.add(TYPE, type); | |
| 141 | + builder.add(EDC_RULE_STEP_IS_FILTERED, ruleStep.isFiltered()); | |
| 142 | + builder.add(EDC_RULE_STEP_FILTERING_REASONS, jsonFactory.createArrayBuilder(ruleStep.getFilteringReasons())); | |
| 143 | + builder.add(EDC_RULE_FUNCTIONS, ruleFunctionSteps); | |
| 144 | + builder.add(EDC_RULE_CONSTRAINT_STEPS, constraintSteps); | |
| 145 | + | |
| 146 | + return builder; | |
| 147 | + } | |
| 148 | + | |
| 149 | + private JsonObject transformConstraintStep(ConstraintStep constraintStep) { | |
| 150 | + // TODO replace with pattern matching once we move to JDK 21 | |
| 151 | + if (constraintStep instanceof AtomicConstraintStep atomicConstraintStep) { | |
| 152 | + return transformAtomicConstraintStep(atomicConstraintStep); | |
| 153 | + } else if (constraintStep instanceof AndConstraintStep andConstraintStep) { | |
| 154 | + return transformAndConstraintStep(andConstraintStep); | |
| 155 | + } else if (constraintStep instanceof OrConstraintStep orConstraintStep) { | |
| 156 | + return transformOrConstraintStep(orConstraintStep); | |
| 157 | + } else if (constraintStep instanceof XoneConstraintStep xoneConstraintStep) { | |
| 158 | + return transformXoneConstraintStep(xoneConstraintStep); | |
| 159 | + } | |
| 160 | + return jsonFactory.createObjectBuilder().build(); | |
| 161 | + } | |
| 162 | + | |
| 163 | + private JsonObject transformAtomicConstraintStep(AtomicConstraintStep atomicConstraintStep) { | |
| 164 | + var builder = jsonFactory.createObjectBuilder(); | |
| 165 | + builder.add(TYPE, EDC_ATOMIC_CONSTRAINT_STEP_TYPE); | |
| 166 | + builder.add(EDC_ATOMIC_CONSTRAINT_STEP_IS_FILTERED, atomicConstraintStep.isFiltered()); | |
| 167 | + builder.add(EDC_ATOMIC_CONSTRAINT_STEP_FILTERING_REASONS, jsonFactory.createArrayBuilder(atomicConstraintStep.filteringReasons())); | |
| 168 | + | |
| 169 | + Optional.ofNullable(atomicConstraintStep.functionName()) | |
| 170 | + .ifPresent(name -> builder.add(EDC_ATOMIC_CONSTRAINT_STEP_FUNCTION_NAME, name)); | |
| 171 | + | |
| 172 | + builder.add(EDC_ATOMIC_CONSTRAINT_STEP_FUNCTION_PARAMS, jsonFactory.createArrayBuilder(atomicConstraintStep.functionParams())); | |
| 173 | + return builder.build(); | |
| 174 | + } | |
| 175 | + | |
| 176 | + private JsonObject transformOrConstraintStep(OrConstraintStep orConstraintStep) { | |
| 177 | + return transformMultiplicityConstraintStep(orConstraintStep, EDC_OR_CONSTRAINT_STEP_TYPE); | |
| 178 | + } | |
| 179 | + | |
| 180 | + private JsonObject transformAndConstraintStep(AndConstraintStep andConstraintStep) { | |
| 181 | + return transformMultiplicityConstraintStep(andConstraintStep, EDC_AND_CONSTRAINT_STEP_TYPE); | |
| 182 | + | |
| 183 | + } | |
| 184 | + | |
| 185 | + private JsonObject transformXoneConstraintStep(XoneConstraintStep xoneConstraintStep) { | |
| 186 | + return transformMultiplicityConstraintStep(xoneConstraintStep, EDC_XONE_CONSTRAINT_STEP_TYPE); | |
| 187 | + } | |
| 188 | + | |
| 189 | + private JsonObject transformMultiplicityConstraintStep(MultiplicityConstraintStep<? extends MultiplicityConstraint> multiplicityConstraintStep, String type) { | |
| 190 | + var builder = jsonFactory.createObjectBuilder(); | |
| 191 | + var constraintSteps = jsonFactory.createArrayBuilder(); | |
| 192 | + | |
| 193 | + multiplicityConstraintStep.getConstraintSteps().stream().map(this::transformConstraintStep) | |
| 194 | + .forEach(constraintSteps::add); | |
| 195 | + | |
| 196 | + builder.add(TYPE, type); | |
| 197 | + builder.add(EDC_MULTIPLICITY_CONSTRAINT_STEPS, constraintSteps); | |
| 198 | + return builder.build(); | |
| 199 | + } | |
| 200 | +} |
added extensions/control-plane/api/management-api/policy-definition-api/src/main/java/org/eclipse/edc/connector/controlplane/api/management/policy/transform/JsonObjectToPolicyEvaluationPlanRequestTransformer.java +38 −0
| @@ -0,0 +1,38 @@ | ||
| 1 | +/* | |
| 2 | + * Copyright (c) 2023 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) | |
| 3 | + * | |
| 4 | + * This program and the accompanying materials are made available under the | |
| 5 | + * terms of the Apache License, Version 2.0 which is available at | |
| 6 | + * https://www.apache.org/licenses/LICENSE-2.0 | |
| 7 | + * | |
| 8 | + * SPDX-License-Identifier: Apache-2.0 | |
| 9 | + * | |
| 10 | + * Contributors: | |
| 11 | + * Bayerische Motoren Werke Aktiengesellschaft (BMW AG) - initial API and implementation | |
| 12 | + * | |
| 13 | + */ | |
| 14 | + | |
| 15 | +package org.eclipse.edc.connector.controlplane.api.management.policy.transform; | |
| 16 | + | |
| 17 | +import jakarta.json.JsonObject; | |
| 18 | +import org.eclipse.edc.connector.controlplane.api.management.policy.model.PolicyEvaluationPlanRequest; | |
| 19 | +import org.eclipse.edc.jsonld.spi.transformer.AbstractJsonLdTransformer; | |
| 20 | +import org.eclipse.edc.transform.spi.TransformerContext; | |
| 21 | +import org.jetbrains.annotations.NotNull; | |
| 22 | +import org.jetbrains.annotations.Nullable; | |
| 23 | + | |
| 24 | +import static org.eclipse.edc.connector.controlplane.api.management.policy.model.PolicyEvaluationPlanRequest.EDC_POLICY_EVALUATION_PLAN_REQUEST_POLICY_SCOPE; | |
| 25 | + | |
| 26 | +public class JsonObjectToPolicyEvaluationPlanRequestTransformer extends AbstractJsonLdTransformer<JsonObject, PolicyEvaluationPlanRequest> { | |
| 27 | + | |
| 28 | + public JsonObjectToPolicyEvaluationPlanRequestTransformer() { | |
| 29 | + super(JsonObject.class, PolicyEvaluationPlanRequest.class); | |
| 30 | + } | |
| 31 | + | |
| 32 | + @Override | |
| 33 | + public @Nullable PolicyEvaluationPlanRequest transform(@NotNull JsonObject input, @NotNull TransformerContext context) { | |
| 34 | + var policyScope = transformString(input.get(EDC_POLICY_EVALUATION_PLAN_REQUEST_POLICY_SCOPE), context); | |
| 35 | + return new PolicyEvaluationPlanRequest(policyScope); | |
| 36 | + } | |
| 37 | + | |
| 38 | +} |
modified extensions/control-plane/api/management-api/policy-definition-api/src/main/java/org/eclipse/edc/connector/controlplane/api/management/policy/v31alpha/PolicyDefinitionApiV31Alpha.java +64 −1
| @@ -104,12 +104,23 @@ | ||
| 104 | 104 | @Operation(description = "Validates an existing Policy, If the Policy is not found, an error is reported", |
| 105 | 105 | responses = { |
| 106 | 106 | @ApiResponse(responseCode = "200", description = "Returns the validation result", content = @Content(schema = @Schema(implementation = PolicyValidationResultSchema.class))), |
| 107 | - @ApiResponse(responseCode = "404", description = "policy definition could not be updated, because it does not exists", | |
| 107 | + @ApiResponse(responseCode = "404", description = "policy definition could not be validated, because it does not exists", | |
| 108 | 108 | content = @Content(schema = @Schema(implementation = ApiCoreSchema.ApiErrorDetailSchema.class))) |
| 109 | 109 | } |
| 110 | 110 | ) |
| 111 | 111 | JsonObject validatePolicyDefinitionV3(String id); |
| 112 | 112 | |
| 113 | + | |
| 114 | + @Operation(description = "Creates an execution plane for an existing Policy, If the Policy is not found, an error is reported", | |
| 115 | + requestBody = @RequestBody(content = @Content(schema = @Schema(implementation = PolicyEvaluationPlanRequestSchema.class))), | |
| 116 | + responses = { | |
| 117 | + @ApiResponse(responseCode = "200", description = "Returns the evaluation plan", content = @Content(schema = @Schema(implementation = PolicyEvaluationPlanSchema.class))), | |
| 118 | + @ApiResponse(responseCode = "404", description = "An evaluation plan could not be created, because the policy definition does not exists", | |
| 119 | + content = @Content(schema = @Schema(implementation = ApiCoreSchema.ApiErrorDetailSchema.class))) | |
| 120 | + } | |
| 121 | + ) | |
| 122 | + JsonObject createExecutionPlaneV3(String id, JsonObject input); | |
| 123 | + | |
| 113 | 124 | @Schema(name = "PolicyDefinitionInput", example = PolicyDefinitionInputSchema.POLICY_DEFINITION_INPUT_EXAMPLE) |
| 114 | 125 | record PolicyDefinitionInputSchema( |
| 115 | 126 | @Schema(name = CONTEXT, requiredMode = REQUIRED) |
| @@ -197,4 +208,56 @@ | ||
| 197 | 208 | """; |
| 198 | 209 | } |
| 199 | 210 | |
| 211 | + @Schema(name = "PolicyEvaluationPlanRequestSchema", example = PolicyEvaluationPlanRequestSchema.POLICY_EVALUATION_PLAN_REQUEST_INPUT_EXAMPLE) | |
| 212 | + record PolicyEvaluationPlanRequestSchema( | |
| 213 | + String policyScope) { | |
| 214 | + | |
| 215 | + public static final String POLICY_EVALUATION_PLAN_REQUEST_INPUT_EXAMPLE = """ | |
| 216 | + { | |
| 217 | + "@context": { "@vocab": "https://w3id.org/edc/v0.0.1/ns/" }, | |
| 218 | + "@type": "PolicyEvaluationPlanRequest", | |
| 219 | + "policyScope": "catalog" | |
| 220 | + } | |
| 221 | + """; | |
| 222 | + } | |
| 223 | + | |
| 224 | + @Schema(name = "PolicyEvaluationPlanSchema", example = PolicyEvaluationPlanSchema.POLICY_EVALUATION_PLANE_OUTPUT_EXAMPLE) | |
| 225 | + record PolicyEvaluationPlanSchema() { | |
| 226 | + | |
| 227 | + public static final String POLICY_EVALUATION_PLANE_OUTPUT_EXAMPLE = """ | |
| 228 | + { | |
| 229 | + "@type": "PolicyEvaluationPlan", | |
| 230 | + "preValidators": "DcpScopeExtractorFunction", | |
| 231 | + "permissionSteps": { | |
| 232 | + "@type": "PermissionStep", | |
| 233 | + "isFiltered": false, | |
| 234 | + "filteringReasons": [], | |
| 235 | + "ruleFunctions": [], | |
| 236 | + "constraintSteps": { | |
| 237 | + "@type": "AtomicConstraintStep", | |
| 238 | + "isFiltered": true, | |
| 239 | + "filteringReasons": [ | |
| 240 | + "leftOperand 'MembershipCredential' is not bound to scope 'request.catalog'", | |
| 241 | + "leftOperand 'MembershipCredential' is not bound to any function within scope 'request.catalog'" | |
| 242 | + ], | |
| 243 | + "functionParams": [ | |
| 244 | + "'MembershipCredential'", | |
| 245 | + "EQ", | |
| 246 | + "'active'" | |
| 247 | + ] | |
| 248 | + }, | |
| 249 | + "dutySteps": [] | |
| 250 | + }, | |
| 251 | + "prohibitionSteps": [], | |
| 252 | + "obligationSteps": [], | |
| 253 | + "postValidators": "DefaultScopeMappingFunction", | |
| 254 | + "@context": { | |
| 255 | + "@vocab": "https://w3id.org/edc/v0.0.1/ns/", | |
| 256 | + "edc": "https://w3id.org/edc/v0.0.1/ns/", | |
| 257 | + "odrl": "http://www.w3.org/ns/odrl/2/" | |
| 258 | + } | |
| 259 | + } | |
| 260 | + """; | |
| 261 | + } | |
| 262 | + | |
| 200 | 263 | } |
modified extensions/control-plane/api/management-api/policy-definition-api/src/main/java/org/eclipse/edc/connector/controlplane/api/management/policy/v31alpha/PolicyDefinitionApiV31AlphaController.java +27 −0
| @@ -25,6 +25,7 @@ | ||
| 25 | 25 | import jakarta.ws.rs.PathParam; |
| 26 | 26 | import jakarta.ws.rs.Produces; |
| 27 | 27 | import org.eclipse.edc.connector.controlplane.api.management.policy.BasePolicyDefinitionApiController; |
| 28 | +import org.eclipse.edc.connector.controlplane.api.management.policy.model.PolicyEvaluationPlanRequest; | |
| 28 | 29 | import org.eclipse.edc.connector.controlplane.api.management.policy.model.PolicyValidationResult; |
| 29 | 30 | import org.eclipse.edc.connector.controlplane.policy.spi.PolicyDefinition; |
| 30 | 31 | import org.eclipse.edc.connector.controlplane.services.spi.policydefinition.PolicyDefinitionService; |
| @@ -32,11 +33,15 @@ | ||
| 32 | 33 | import org.eclipse.edc.spi.monitor.Monitor; |
| 33 | 34 | import org.eclipse.edc.transform.spi.TypeTransformerRegistry; |
| 34 | 35 | import org.eclipse.edc.validator.spi.JsonObjectValidatorRegistry; |
| 36 | +import org.eclipse.edc.web.spi.exception.InvalidRequestException; | |
| 35 | 37 | import org.eclipse.edc.web.spi.exception.ObjectNotFoundException; |
| 38 | +import org.eclipse.edc.web.spi.exception.ValidationFailureException; | |
| 36 | 39 | |
| 37 | 40 | import java.util.ArrayList; |
| 38 | 41 | |
| 39 | 42 | import static jakarta.ws.rs.core.MediaType.APPLICATION_JSON; |
| 43 | +import static org.eclipse.edc.connector.controlplane.api.management.policy.model.PolicyEvaluationPlanRequest.EDC_POLICY_EVALUATION_PLAN_REQUEST_TYPE; | |
| 44 | +import static org.eclipse.edc.web.spi.exception.ServiceResultHandler.exceptionMapper; | |
| 40 | 45 | |
| 41 | 46 | @Consumes(APPLICATION_JSON) |
| 42 | 47 | @Produces(APPLICATION_JSON) |
| @@ -101,4 +106,26 @@ | ||
| 101 | 106 | return transformerRegistry.transform(validationResult, JsonObject.class) |
| 102 | 107 | .orElseThrow(f -> new EdcException("Error creating response body: " + f.getFailureDetail())); |
| 103 | 108 | } |
| 109 | + | |
| 110 | + @POST | |
| 111 | + @Path("{id}/evaluationplan") | |
| 112 | + @Override | |
| 113 | + public JsonObject createExecutionPlaneV3(@PathParam("id") String id, JsonObject request) { | |
| 114 | + | |
| 115 | + validatorRegistry.validate(EDC_POLICY_EVALUATION_PLAN_REQUEST_TYPE, request).orElseThrow(ValidationFailureException::new); | |
| 116 | + | |
| 117 | + var planeRequest = transformerRegistry.transform(request, PolicyEvaluationPlanRequest.class) | |
| 118 | + .orElseThrow(InvalidRequestException::new); | |
| 119 | + | |
| 120 | + var definition = service.findById(id); | |
| 121 | + if (definition == null) { | |
| 122 | + throw new ObjectNotFoundException(PolicyDefinition.class, id); | |
| 123 | + } | |
| 124 | + | |
| 125 | + var plan = service.createEvaluationPlan(planeRequest.policyScope(), definition.getPolicy()) | |
| 126 | + .orElseThrow(exceptionMapper(PolicyDefinition.class, definition.getId())); | |
| 127 | + | |
| 128 | + return transformerRegistry.transform(plan, JsonObject.class) | |
| 129 | + .orElseThrow(f -> new EdcException("Error creating response body: " + f.getFailureDetail())); | |
| 130 | + } | |
| 104 | 131 | } |
added extensions/control-plane/api/management-api/policy-definition-api/src/main/java/org/eclipse/edc/connector/controlplane/api/management/policy/validation/PolicyEvaluationPlanRequestValidator.java +31 −0
| @@ -0,0 +1,31 @@ | ||
| 1 | +/* | |
| 2 | + * Copyright (c) 2024 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) | |
| 3 | + * | |
| 4 | + * This program and the accompanying materials are made available under the | |
| 5 | + * terms of the Apache License, Version 2.0 which is available at | |
| 6 | + * https://www.apache.org/licenses/LICENSE-2.0 | |
| 7 | + * | |
| 8 | + * SPDX-License-Identifier: Apache-2.0 | |
| 9 | + * | |
| 10 | + * Contributors: | |
| 11 | + * Bayerische Motoren Werke Aktiengesellschaft (BMW AG) - initial API and implementation | |
| 12 | + * | |
| 13 | + */ | |
| 14 | + | |
| 15 | +package org.eclipse.edc.connector.controlplane.api.management.policy.validation; | |
| 16 | + | |
| 17 | +import jakarta.json.JsonObject; | |
| 18 | +import org.eclipse.edc.validator.jsonobject.JsonObjectValidator; | |
| 19 | +import org.eclipse.edc.validator.jsonobject.validators.MandatoryValue; | |
| 20 | +import org.eclipse.edc.validator.spi.Validator; | |
| 21 | + | |
| 22 | +import static org.eclipse.edc.connector.controlplane.api.management.policy.model.PolicyEvaluationPlanRequest.EDC_POLICY_EVALUATION_PLAN_REQUEST_POLICY_SCOPE; | |
| 23 | + | |
| 24 | +public class PolicyEvaluationPlanRequestValidator { | |
| 25 | + | |
| 26 | + public static Validator<JsonObject> instance() { | |
| 27 | + return JsonObjectValidator.newValidator() | |
| 28 | + .verify(EDC_POLICY_EVALUATION_PLAN_REQUEST_POLICY_SCOPE, MandatoryValue::new) | |
| 29 | + .build(); | |
| 30 | + } | |
| 31 | +} |
modified extensions/control-plane/api/management-api/policy-definition-api/src/test/java/org/eclipse/edc/connector/controlplane/api/management/policy/PolicyDefinitionApiTest.java +37 −1
| @@ -29,12 +29,16 @@ | ||
| 29 | 29 | import org.junit.jupiter.api.BeforeEach; |
| 30 | 30 | import org.junit.jupiter.api.Test; |
| 31 | 31 | |
| 32 | -import static org.assertj.core.api.AssertionsForClassTypes.assertThat; | |
| 32 | +import static org.assertj.core.api.Assertions.assertThat; | |
| 33 | +import static org.eclipse.edc.connector.controlplane.api.management.policy.model.PolicyEvaluationPlanRequest.EDC_POLICY_EVALUATION_PLAN_REQUEST_POLICY_SCOPE; | |
| 34 | +import static org.eclipse.edc.connector.controlplane.api.management.policy.model.PolicyEvaluationPlanRequest.EDC_POLICY_EVALUATION_PLAN_REQUEST_TYPE; | |
| 33 | 35 | import static org.eclipse.edc.connector.controlplane.api.management.policy.model.PolicyValidationResult.EDC_POLICY_VALIDATION_RESULT_ERRORS; |
| 34 | 36 | import static org.eclipse.edc.connector.controlplane.api.management.policy.model.PolicyValidationResult.EDC_POLICY_VALIDATION_RESULT_IS_VALID; |
| 35 | 37 | import static org.eclipse.edc.connector.controlplane.api.management.policy.model.PolicyValidationResult.EDC_POLICY_VALIDATION_RESULT_TYPE; |
| 36 | 38 | import static org.eclipse.edc.connector.controlplane.api.management.policy.v2.PolicyDefinitionApiV2.PolicyDefinitionInputSchema.POLICY_DEFINITION_INPUT_EXAMPLE; |
| 37 | 39 | import static org.eclipse.edc.connector.controlplane.api.management.policy.v2.PolicyDefinitionApiV2.PolicyDefinitionOutputSchema.POLICY_DEFINITION_OUTPUT_EXAMPLE; |
| 40 | +import static org.eclipse.edc.connector.controlplane.api.management.policy.v31alpha.PolicyDefinitionApiV31Alpha.PolicyEvaluationPlanRequestSchema.POLICY_EVALUATION_PLAN_REQUEST_INPUT_EXAMPLE; | |
| 41 | +import static org.eclipse.edc.connector.controlplane.api.management.policy.v31alpha.PolicyDefinitionApiV31Alpha.PolicyEvaluationPlanSchema.POLICY_EVALUATION_PLANE_OUTPUT_EXAMPLE; | |
| 38 | 42 | import static org.eclipse.edc.connector.controlplane.api.management.policy.v31alpha.PolicyDefinitionApiV31Alpha.PolicyValidationResultSchema.POLICY_VALIDATION_RESULT_OUTPUT_EXAMPLE; |
| 39 | 43 | import static org.eclipse.edc.connector.controlplane.policy.spi.PolicyDefinition.EDC_POLICY_DEFINITION_POLICY; |
| 40 | 44 | import static org.eclipse.edc.jsonld.spi.JsonLdKeywords.ID; |
| @@ -43,6 +47,12 @@ | ||
| 43 | 47 | import static org.eclipse.edc.jsonld.spi.PropertyAndTypeNames.EDC_CREATED_AT; |
| 44 | 48 | import static org.eclipse.edc.junit.assertions.AbstractResultAssert.assertThat; |
| 45 | 49 | import static org.eclipse.edc.junit.extensions.TestServiceExtensionContext.testServiceExtensionContext; |
| 50 | +import static org.eclipse.edc.policy.engine.spi.plan.PolicyEvaluationPlan.EDC_POLICY_EVALUATION_PLAN_OBLIGATION_STEPS; | |
| 51 | +import static org.eclipse.edc.policy.engine.spi.plan.PolicyEvaluationPlan.EDC_POLICY_EVALUATION_PLAN_PERMISSION_STEPS; | |
| 52 | +import static org.eclipse.edc.policy.engine.spi.plan.PolicyEvaluationPlan.EDC_POLICY_EVALUATION_PLAN_POST_VALIDATORS; | |
| 53 | +import static org.eclipse.edc.policy.engine.spi.plan.PolicyEvaluationPlan.EDC_POLICY_EVALUATION_PLAN_PRE_VALIDATORS; | |
| 54 | +import static org.eclipse.edc.policy.engine.spi.plan.PolicyEvaluationPlan.EDC_POLICY_EVALUATION_PLAN_PROHIBITION_STEPS; | |
| 55 | +import static org.eclipse.edc.policy.engine.spi.plan.PolicyEvaluationPlan.EDC_POLICY_EVALUATION_PLAN_TYPE; | |
| 46 | 56 | import static org.mockito.Mockito.mock; |
| 47 | 57 | |
| 48 | 58 | class PolicyDefinitionApiTest { |
| @@ -100,4 +110,30 @@ | ||
| 100 | 110 | assertThat(content.getJsonArray(EDC_POLICY_VALIDATION_RESULT_ERRORS).size()).isEqualTo(2); |
| 101 | 111 | }); |
| 102 | 112 | } |
| 113 | + | |
| 114 | + @Test | |
| 115 | + void policyEvaluationPlanRequestExample() throws JsonProcessingException { | |
| 116 | + var jsonObject = objectMapper.readValue(POLICY_EVALUATION_PLAN_REQUEST_INPUT_EXAMPLE, JsonObject.class); | |
| 117 | + var expanded = jsonLd.expand(jsonObject); | |
| 118 | + | |
| 119 | + assertThat(expanded).isSucceeded().satisfies(content -> { | |
| 120 | + assertThat(content.getJsonArray(TYPE).getString(0)).isEqualTo(EDC_POLICY_EVALUATION_PLAN_REQUEST_TYPE); | |
| 121 | + assertThat(content.getJsonArray(EDC_POLICY_EVALUATION_PLAN_REQUEST_POLICY_SCOPE).getJsonObject(0).getString(VALUE)).isEqualTo("catalog"); | |
| 122 | + }); | |
| 123 | + } | |
| 124 | + | |
| 125 | + @Test | |
| 126 | + void policyEvaluationPlanOutputExample() throws JsonProcessingException { | |
| 127 | + var jsonObject = objectMapper.readValue(POLICY_EVALUATION_PLANE_OUTPUT_EXAMPLE, JsonObject.class); | |
| 128 | + var expanded = jsonLd.expand(jsonObject); | |
| 129 | + | |
| 130 | + assertThat(expanded).isSucceeded().satisfies(content -> { | |
| 131 | + assertThat(content.getJsonArray(TYPE).getString(0)).isEqualTo(EDC_POLICY_EVALUATION_PLAN_TYPE); | |
| 132 | + assertThat(content.getJsonArray(EDC_POLICY_EVALUATION_PLAN_PRE_VALIDATORS)).hasSize(1); | |
| 133 | + assertThat(content.getJsonArray(EDC_POLICY_EVALUATION_PLAN_PERMISSION_STEPS)).hasSize(1); | |
| 134 | + assertThat(content.getJsonArray(EDC_POLICY_EVALUATION_PLAN_PROHIBITION_STEPS)).hasSize(0); | |
| 135 | + assertThat(content.getJsonArray(EDC_POLICY_EVALUATION_PLAN_OBLIGATION_STEPS)).hasSize(0); | |
| 136 | + assertThat(content.getJsonArray(EDC_POLICY_EVALUATION_PLAN_POST_VALIDATORS)).hasSize(1); | |
| 137 | + }); | |
| 138 | + } | |
| 103 | 139 | } |
added extensions/control-plane/api/management-api/policy-definition-api/src/test/java/org/eclipse/edc/connector/controlplane/api/management/policy/transform/JsonObjectFromPolicyEvaluationPlanTransformerTest.java +228 −0
| @@ -0,0 +1,228 @@ | ||
| 1 | +/* | |
| 2 | + * Copyright (c) 2024 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) | |
| 3 | + * | |
| 4 | + * This program and the accompanying materials are made available under the | |
| 5 | + * terms of the Apache License, Version 2.0 which is available at | |
| 6 | + * https://www.apache.org/licenses/LICENSE-2.0 | |
| 7 | + * | |
| 8 | + * SPDX-License-Identifier: Apache-2.0 | |
| 9 | + * | |
| 10 | + * Contributors: | |
| 11 | + * Bayerische Motoren Werke Aktiengesellschaft (BMW AG) - initial API and implementation | |
| 12 | + * | |
| 13 | + */ | |
| 14 | + | |
| 15 | +package org.eclipse.edc.connector.controlplane.api.management.policy.transform; | |
| 16 | + | |
| 17 | +import jakarta.json.Json; | |
| 18 | +import jakarta.json.JsonObject; | |
| 19 | +import org.eclipse.edc.policy.engine.spi.AtomicConstraintFunction; | |
| 20 | +import org.eclipse.edc.policy.engine.spi.RuleFunction; | |
| 21 | +import org.eclipse.edc.policy.engine.spi.plan.PolicyEvaluationPlan; | |
| 22 | +import org.eclipse.edc.policy.engine.spi.plan.step.AndConstraintStep; | |
| 23 | +import org.eclipse.edc.policy.engine.spi.plan.step.AtomicConstraintStep; | |
| 24 | +import org.eclipse.edc.policy.engine.spi.plan.step.ConstraintStep; | |
| 25 | +import org.eclipse.edc.policy.engine.spi.plan.step.DutyStep; | |
| 26 | +import org.eclipse.edc.policy.engine.spi.plan.step.OrConstraintStep; | |
| 27 | +import org.eclipse.edc.policy.engine.spi.plan.step.PermissionStep; | |
| 28 | +import org.eclipse.edc.policy.engine.spi.plan.step.ProhibitionStep; | |
| 29 | +import org.eclipse.edc.policy.engine.spi.plan.step.RuleFunctionStep; | |
| 30 | +import org.eclipse.edc.policy.engine.spi.plan.step.ValidatorStep; | |
| 31 | +import org.eclipse.edc.policy.engine.spi.plan.step.XoneConstraintStep; | |
| 32 | +import org.eclipse.edc.policy.model.AtomicConstraint; | |
| 33 | +import org.eclipse.edc.policy.model.LiteralExpression; | |
| 34 | +import org.eclipse.edc.policy.model.Permission; | |
| 35 | +import org.eclipse.edc.policy.model.Rule; | |
| 36 | +import org.eclipse.edc.transform.spi.TransformerContext; | |
| 37 | +import org.junit.jupiter.api.Test; | |
| 38 | +import org.junit.jupiter.api.extension.ExtensionContext; | |
| 39 | +import org.junit.jupiter.params.ParameterizedTest; | |
| 40 | +import org.junit.jupiter.params.provider.Arguments; | |
| 41 | +import org.junit.jupiter.params.provider.ArgumentsProvider; | |
| 42 | +import org.junit.jupiter.params.provider.ArgumentsSource; | |
| 43 | + | |
| 44 | +import java.util.List; | |
| 45 | +import java.util.stream.Stream; | |
| 46 | + | |
| 47 | +import static java.util.Collections.emptyMap; | |
| 48 | +import static org.assertj.core.api.Assertions.assertThat; | |
| 49 | +import static org.eclipse.edc.jsonld.spi.JsonLdKeywords.TYPE; | |
| 50 | +import static org.eclipse.edc.policy.engine.spi.plan.PolicyEvaluationPlan.EDC_POLICY_EVALUATION_PLAN_OBLIGATION_STEPS; | |
| 51 | +import static org.eclipse.edc.policy.engine.spi.plan.PolicyEvaluationPlan.EDC_POLICY_EVALUATION_PLAN_PERMISSION_STEPS; | |
| 52 | +import static org.eclipse.edc.policy.engine.spi.plan.PolicyEvaluationPlan.EDC_POLICY_EVALUATION_PLAN_POST_VALIDATORS; | |
| 53 | +import static org.eclipse.edc.policy.engine.spi.plan.PolicyEvaluationPlan.EDC_POLICY_EVALUATION_PLAN_PRE_VALIDATORS; | |
| 54 | +import static org.eclipse.edc.policy.engine.spi.plan.PolicyEvaluationPlan.EDC_POLICY_EVALUATION_PLAN_PROHIBITION_STEPS; | |
| 55 | +import static org.eclipse.edc.policy.engine.spi.plan.step.AndConstraintStep.EDC_AND_CONSTRAINT_STEP_TYPE; | |
| 56 | +import static org.eclipse.edc.policy.engine.spi.plan.step.AtomicConstraintStep.EDC_ATOMIC_CONSTRAINT_STEP_FILTERING_REASONS; | |
| 57 | +import static org.eclipse.edc.policy.engine.spi.plan.step.AtomicConstraintStep.EDC_ATOMIC_CONSTRAINT_STEP_FUNCTION_NAME; | |
| 58 | +import static org.eclipse.edc.policy.engine.spi.plan.step.AtomicConstraintStep.EDC_ATOMIC_CONSTRAINT_STEP_FUNCTION_PARAMS; | |
| 59 | +import static org.eclipse.edc.policy.engine.spi.plan.step.AtomicConstraintStep.EDC_ATOMIC_CONSTRAINT_STEP_IS_FILTERED; | |
| 60 | +import static org.eclipse.edc.policy.engine.spi.plan.step.AtomicConstraintStep.EDC_ATOMIC_CONSTRAINT_STEP_TYPE; | |
| 61 | +import static org.eclipse.edc.policy.engine.spi.plan.step.MultiplicityConstraintStep.EDC_MULTIPLICITY_CONSTRAINT_STEPS; | |
| 62 | +import static org.eclipse.edc.policy.engine.spi.plan.step.OrConstraintStep.EDC_OR_CONSTRAINT_STEP_TYPE; | |
| 63 | +import static org.eclipse.edc.policy.engine.spi.plan.step.PermissionStep.EDC_PERMISSION_STEP_DUTY_STEPS; | |
| 64 | +import static org.eclipse.edc.policy.engine.spi.plan.step.PermissionStep.EDC_PERMISSION_STEP_TYPE; | |
| 65 | +import static org.eclipse.edc.policy.engine.spi.plan.step.RuleStep.EDC_RULE_CONSTRAINT_STEPS; | |
| 66 | +import static org.eclipse.edc.policy.engine.spi.plan.step.RuleStep.EDC_RULE_FUNCTIONS; | |
| 67 | +import static org.eclipse.edc.policy.engine.spi.plan.step.RuleStep.EDC_RULE_STEP_FILTERING_REASONS; | |
| 68 | +import static org.eclipse.edc.policy.engine.spi.plan.step.RuleStep.EDC_RULE_STEP_IS_FILTERED; | |
| 69 | +import static org.eclipse.edc.policy.engine.spi.plan.step.XoneConstraintStep.EDC_XONE_CONSTRAINT_STEP_TYPE; | |
| 70 | +import static org.eclipse.edc.policy.model.Operator.EQ; | |
| 71 | +import static org.junit.jupiter.params.provider.Arguments.of; | |
| 72 | +import static org.mockito.Mockito.mock; | |
| 73 | +import static org.mockito.Mockito.when; | |
| 74 | + | |
| 75 | +public class JsonObjectFromPolicyEvaluationPlanTransformerTest { | |
| 76 | + | |
| 77 | + private final JsonObjectFromPolicyEvaluationPlanTransformer transformer = new JsonObjectFromPolicyEvaluationPlanTransformer(Json.createBuilderFactory(emptyMap())); | |
| 78 | + private final TransformerContext context = mock(TransformerContext.class); | |
| 79 | + | |
| 80 | + private static AtomicConstraint atomicConstraint(String key, String value) { | |
| 81 | + var left = new LiteralExpression(key); | |
| 82 | + var right = new LiteralExpression(value); | |
| 83 | + return AtomicConstraint.Builder.newInstance() | |
| 84 | + .leftExpression(left) | |
| 85 | + .operator(EQ) | |
| 86 | + .rightExpression(right) | |
| 87 | + .build(); | |
| 88 | + } | |
| 89 | + | |
| 90 | + private static AtomicConstraintStep atomicConstraintStep(AtomicConstraint atomicConstraint) { | |
| 91 | + AtomicConstraintFunction<Rule> function = mock(); | |
| 92 | + when(function.name()).thenReturn("AtomicConstraintFunction"); | |
| 93 | + return new AtomicConstraintStep(atomicConstraint, List.of("filtered constraint"), mock(), function); | |
| 94 | + } | |
| 95 | + | |
| 96 | + @Test | |
| 97 | + void types() { | |
| 98 | + assertThat(transformer.getInputType()).isEqualTo(PolicyEvaluationPlan.class); | |
| 99 | + assertThat(transformer.getOutputType()).isEqualTo(JsonObject.class); | |
| 100 | + } | |
| 101 | + | |
| 102 | + @Test | |
| 103 | + void transform_withPermissionStep() { | |
| 104 | + var plan = PolicyEvaluationPlan.Builder.newInstance().permission(permissionStep()).build(); | |
| 105 | + | |
| 106 | + var result = transformer.transform(plan, context); | |
| 107 | + | |
| 108 | + assertThat(result).isNotNull(); | |
| 109 | + assertThat(result.getJsonArray(EDC_POLICY_EVALUATION_PLAN_PERMISSION_STEPS)).hasSize(1); | |
| 110 | + var permission = result.getJsonArray(EDC_POLICY_EVALUATION_PLAN_PERMISSION_STEPS).get(0).asJsonObject(); | |
| 111 | + | |
| 112 | + assertThat(permission.getString(TYPE)).isEqualTo(EDC_PERMISSION_STEP_TYPE); | |
| 113 | + assertThat(permission.getBoolean(EDC_RULE_STEP_IS_FILTERED)).isEqualTo(true); | |
| 114 | + assertThat(permission.getJsonArray(EDC_RULE_STEP_FILTERING_REASONS)).contains(Json.createValue("filter reason")); | |
| 115 | + assertThat(permission.getJsonArray(EDC_PERMISSION_STEP_DUTY_STEPS)).hasSize(1); | |
| 116 | + assertThat(permission.getJsonArray(EDC_RULE_FUNCTIONS)).hasSize(1).contains(Json.createValue("PermissionFunction")); | |
| 117 | + assertThat(permission.getJsonArray(EDC_RULE_CONSTRAINT_STEPS)).hasSize(1); | |
| 118 | + | |
| 119 | + var constraint = permission.getJsonArray(EDC_RULE_CONSTRAINT_STEPS).get(0).asJsonObject(); | |
| 120 | + | |
| 121 | + assertThat(constraint.getString(TYPE)).isEqualTo(EDC_ATOMIC_CONSTRAINT_STEP_TYPE); | |
| 122 | + assertThat(constraint.getBoolean(EDC_ATOMIC_CONSTRAINT_STEP_IS_FILTERED)).isTrue(); | |
| 123 | + assertThat(constraint.getJsonArray(EDC_ATOMIC_CONSTRAINT_STEP_FILTERING_REASONS)).hasSize(1) | |
| 124 | + .contains(Json.createValue("filtered constraint")); | |
| 125 | + assertThat(constraint.getString(EDC_ATOMIC_CONSTRAINT_STEP_FUNCTION_NAME)).isEqualTo("AtomicConstraintFunction"); | |
| 126 | + assertThat(constraint.getJsonArray(EDC_ATOMIC_CONSTRAINT_STEP_FUNCTION_PARAMS)) | |
| 127 | + .hasSize(3) | |
| 128 | + .containsExactly(Json.createValue("'foo'"), Json.createValue("EQ"), Json.createValue("'bar'")); | |
| 129 | + | |
| 130 | + } | |
| 131 | + | |
| 132 | + @Test | |
| 133 | + void transform_withValidators() { | |
| 134 | + | |
| 135 | + var validator = new ValidatorStep(mock()); | |
| 136 | + var plan = PolicyEvaluationPlan.Builder.newInstance() | |
| 137 | + .preValidator(validator) | |
| 138 | + .postValidator(validator) | |
| 139 | + .build(); | |
| 140 | + | |
| 141 | + var result = transformer.transform(plan, context); | |
| 142 | + | |
| 143 | + assertThat(result).isNotNull(); | |
| 144 | + assertThat(result.getJsonArray(EDC_POLICY_EVALUATION_PLAN_PRE_VALIDATORS)).hasSize(1); | |
| 145 | + assertThat(result.getJsonArray(EDC_POLICY_EVALUATION_PLAN_POST_VALIDATORS)).hasSize(1); | |
| 146 | + | |
| 147 | + } | |
| 148 | + | |
| 149 | + @ParameterizedTest | |
| 150 | + @ArgumentsSource(MultiplicityStepProvider.class) | |
| 151 | + void transformWithMultiplicitySteps(PolicyEvaluationPlan plan, String ruleStepProperty, String multiplicityType) { | |
| 152 | + | |
| 153 | + var result = transformer.transform(plan, context); | |
| 154 | + | |
| 155 | + assertThat(result).isNotNull(); | |
| 156 | + | |
| 157 | + assertThat(result.getJsonArray(ruleStepProperty)).hasSize(1); | |
| 158 | + var rule = result.getJsonArray(ruleStepProperty).get(0).asJsonObject(); | |
| 159 | + | |
| 160 | + assertThat(rule.getJsonArray(EDC_RULE_CONSTRAINT_STEPS)).hasSize(1); | |
| 161 | + var constraint = rule.getJsonArray(EDC_RULE_CONSTRAINT_STEPS).get(0).asJsonObject(); | |
| 162 | + | |
| 163 | + assertThat(constraint.getString(TYPE)).isEqualTo(multiplicityType); | |
| 164 | + assertThat(constraint.getJsonArray(EDC_MULTIPLICITY_CONSTRAINT_STEPS)).hasSize(2); | |
| 165 | + | |
| 166 | + } | |
| 167 | + | |
| 168 | + private PolicyEvaluationPlan createPlan() { | |
| 169 | + return PolicyEvaluationPlan.Builder.newInstance() | |
| 170 | + .preValidator(new ValidatorStep(mock())) | |
| 171 | + .duty(dutyStep()) | |
| 172 | + .permission(permissionStep()) | |
| 173 | + .prohibition(prohibitionStep()) | |
| 174 | + .postValidator(new ValidatorStep(mock())) | |
| 175 | + .build(); | |
| 176 | + } | |
| 177 | + | |
| 178 | + private DutyStep dutyStep() { | |
| 179 | + return DutyStep.Builder.newInstance().rule(mock()).filtered(false).build(); | |
| 180 | + } | |
| 181 | + | |
| 182 | + private PermissionStep permissionStep() { | |
| 183 | + return permissionStep(atomicConstraintStep(atomicConstraint("foo", "bar"))); | |
| 184 | + } | |
| 185 | + | |
| 186 | + private PermissionStep permissionStep(ConstraintStep constraintStep) { | |
| 187 | + RuleFunction<Permission> function = mock(); | |
| 188 | + when(function.name()).thenReturn("PermissionFunction"); | |
| 189 | + return PermissionStep.Builder.newInstance() | |
| 190 | + .rule(mock()) | |
| 191 | + .filtered(true) | |
| 192 | + .filteringReason("filter reason") | |
| 193 | + .ruleFunction(new RuleFunctionStep<>(function, mock())) | |
| 194 | + .constraint(constraintStep) | |
| 195 | + .dutyStep(DutyStep.Builder.newInstance().rule(mock()).filtered(false).build()).build(); | |
| 196 | + } | |
| 197 | + | |
| 198 | + private ProhibitionStep prohibitionStep() { | |
| 199 | + return ProhibitionStep.Builder.newInstance() | |
| 200 | + .rule(mock()) | |
| 201 | + .build(); | |
| 202 | + } | |
| 203 | + | |
| 204 | + private static class MultiplicityStepProvider implements ArgumentsProvider { | |
| 205 | + @Override | |
| 206 | + public Stream<? extends Arguments> provideArguments(ExtensionContext context) { | |
| 207 | + | |
| 208 | + var firstConstraint = atomicConstraintStep(atomicConstraint("foo", "bar")); | |
| 209 | + var secondConstraint = atomicConstraintStep(atomicConstraint("baz", "bar")); | |
| 210 | + | |
| 211 | + List<ConstraintStep> constraints = List.of(firstConstraint, secondConstraint); | |
| 212 | + | |
| 213 | + var orConstraintStep = new OrConstraintStep(constraints, mock()); | |
| 214 | + var andConstraintStep = new AndConstraintStep(constraints, mock()); | |
| 215 | + var xoneConstraintStep = new XoneConstraintStep(constraints, mock()); | |
| 216 | + | |
| 217 | + var permission = PermissionStep.Builder.newInstance().constraint(orConstraintStep).rule(mock()).build(); | |
| 218 | + var duty = DutyStep.Builder.newInstance().constraint(xoneConstraintStep).rule(mock()).build(); | |
| 219 | + var prohibition = ProhibitionStep.Builder.newInstance().constraint(andConstraintStep).rule(mock()).build(); | |
| 220 | + | |
| 221 | + return Stream.of( | |
| 222 | + of(PolicyEvaluationPlan.Builder.newInstance().permission(permission).build(), EDC_POLICY_EVALUATION_PLAN_PERMISSION_STEPS, EDC_OR_CONSTRAINT_STEP_TYPE), | |
| 223 | + of(PolicyEvaluationPlan.Builder.newInstance().duty(duty).build(), EDC_POLICY_EVALUATION_PLAN_OBLIGATION_STEPS, EDC_XONE_CONSTRAINT_STEP_TYPE), | |
| 224 | + of(PolicyEvaluationPlan.Builder.newInstance().prohibition(prohibition).build(), EDC_POLICY_EVALUATION_PLAN_PROHIBITION_STEPS, EDC_AND_CONSTRAINT_STEP_TYPE) | |
| 225 | + ); | |
| 226 | + } | |
| 227 | + } | |
| 228 | +} |
added extensions/control-plane/api/management-api/policy-definition-api/src/test/java/org/eclipse/edc/connector/controlplane/api/management/policy/transform/JsonObjectFromPolicyValidationResultTransformerTest.java +60 −0
| @@ -0,0 +1,60 @@ | ||
| 1 | +/* | |
| 2 | + * Copyright (c) 2024 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) | |
| 3 | + * | |
| 4 | + * This program and the accompanying materials are made available under the | |
| 5 | + * terms of the Apache License, Version 2.0 which is available at | |
| 6 | + * https://www.apache.org/licenses/LICENSE-2.0 | |
| 7 | + * | |
| 8 | + * SPDX-License-Identifier: Apache-2.0 | |
| 9 | + * | |
| 10 | + * Contributors: | |
| 11 | + * Bayerische Motoren Werke Aktiengesellschaft (BMW AG) - initial API and implementation | |
| 12 | + * | |
| 13 | + */ | |
| 14 | + | |
| 15 | +package org.eclipse.edc.connector.controlplane.api.management.policy.transform; | |
| 16 | + | |
| 17 | +import jakarta.json.Json; | |
| 18 | +import jakarta.json.JsonBuilderFactory; | |
| 19 | +import jakarta.json.JsonObject; | |
| 20 | +import org.eclipse.edc.connector.controlplane.api.management.policy.model.PolicyValidationResult; | |
| 21 | +import org.eclipse.edc.transform.spi.TransformerContext; | |
| 22 | +import org.junit.jupiter.api.Test; | |
| 23 | + | |
| 24 | +import java.util.List; | |
| 25 | +import java.util.Map; | |
| 26 | + | |
| 27 | +import static org.assertj.core.api.Assertions.assertThat; | |
| 28 | +import static org.eclipse.edc.connector.controlplane.api.management.policy.model.PolicyValidationResult.EDC_POLICY_VALIDATION_RESULT_ERRORS; | |
| 29 | +import static org.eclipse.edc.connector.controlplane.api.management.policy.model.PolicyValidationResult.EDC_POLICY_VALIDATION_RESULT_IS_VALID; | |
| 30 | +import static org.eclipse.edc.connector.controlplane.api.management.policy.model.PolicyValidationResult.EDC_POLICY_VALIDATION_RESULT_TYPE; | |
| 31 | +import static org.eclipse.edc.jsonld.spi.JsonLdKeywords.TYPE; | |
| 32 | +import static org.mockito.Mockito.mock; | |
| 33 | + | |
| 34 | +class JsonObjectFromPolicyValidationResultTransformerTest { | |
| 35 | + | |
| 36 | + private final JsonBuilderFactory jsonFactory = Json.createBuilderFactory(Map.of()); | |
| 37 | + | |
| 38 | + private final JsonObjectFromPolicyValidationResultTransformer transformer = new JsonObjectFromPolicyValidationResultTransformer(jsonFactory); | |
| 39 | + private final TransformerContext context = mock(TransformerContext.class); | |
| 40 | + | |
| 41 | + @Test | |
| 42 | + void types() { | |
| 43 | + assertThat(transformer.getOutputType()).isEqualTo(JsonObject.class); | |
| 44 | + assertThat(transformer.getInputType()).isEqualTo(PolicyValidationResult.class); | |
| 45 | + } | |
| 46 | + | |
| 47 | + @Test | |
| 48 | + void transform() { | |
| 49 | + var validationResult = new PolicyValidationResult(false, List.of("error1", "error2")); | |
| 50 | + | |
| 51 | + var result = transformer.transform(validationResult, context); | |
| 52 | + | |
| 53 | + assertThat(result).isNotNull(); | |
| 54 | + assertThat(result.getString(TYPE)).isEqualTo(EDC_POLICY_VALIDATION_RESULT_TYPE); | |
| 55 | + assertThat(result.getBoolean(EDC_POLICY_VALIDATION_RESULT_IS_VALID)).isFalse(); | |
| 56 | + assertThat(result.getJsonArray(EDC_POLICY_VALIDATION_RESULT_ERRORS)).hasSize(2) | |
| 57 | + .contains(Json.createValue("error1"), Json.createValue("error2")); | |
| 58 | + } | |
| 59 | + | |
| 60 | +} |
added extensions/control-plane/api/management-api/policy-definition-api/src/test/java/org/eclipse/edc/connector/controlplane/api/management/policy/transform/JsonObjectToPolicyEvaluationPlanRequestTransformerTest.java +59 −0
| @@ -0,0 +1,59 @@ | ||
| 1 | +/* | |
| 2 | + * Copyright (c) 2024 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) | |
| 3 | + * | |
| 4 | + * This program and the accompanying materials are made available under the | |
| 5 | + * terms of the Apache License, Version 2.0 which is available at | |
| 6 | + * https://www.apache.org/licenses/LICENSE-2.0 | |
| 7 | + * | |
| 8 | + * SPDX-License-Identifier: Apache-2.0 | |
| 9 | + * | |
| 10 | + * Contributors: | |
| 11 | + * Bayerische Motoren Werke Aktiengesellschaft (BMW AG) - initial API and implementation | |
| 12 | + * | |
| 13 | + */ | |
| 14 | + | |
| 15 | +package org.eclipse.edc.connector.controlplane.api.management.policy.transform; | |
| 16 | + | |
| 17 | +import jakarta.json.JsonObject; | |
| 18 | +import org.eclipse.edc.connector.controlplane.api.management.policy.model.PolicyEvaluationPlanRequest; | |
| 19 | +import org.eclipse.edc.jsonld.TitaniumJsonLd; | |
| 20 | +import org.eclipse.edc.spi.monitor.Monitor; | |
| 21 | +import org.eclipse.edc.transform.spi.TransformerContext; | |
| 22 | +import org.junit.jupiter.api.Test; | |
| 23 | + | |
| 24 | +import static jakarta.json.Json.createObjectBuilder; | |
| 25 | +import static org.assertj.core.api.Assertions.assertThat; | |
| 26 | +import static org.eclipse.edc.connector.controlplane.api.management.policy.model.PolicyEvaluationPlanRequest.EDC_POLICY_EVALUATION_PLAN_REQUEST_POLICY_SCOPE; | |
| 27 | +import static org.eclipse.edc.connector.controlplane.api.management.policy.model.PolicyEvaluationPlanRequest.EDC_POLICY_EVALUATION_PLAN_REQUEST_TYPE; | |
| 28 | +import static org.eclipse.edc.jsonld.spi.JsonLdKeywords.TYPE; | |
| 29 | +import static org.mockito.Mockito.mock; | |
| 30 | + | |
| 31 | +public class JsonObjectToPolicyEvaluationPlanRequestTransformerTest { | |
| 32 | + | |
| 33 | + private final JsonObjectToPolicyEvaluationPlanRequestTransformer transformer = new JsonObjectToPolicyEvaluationPlanRequestTransformer(); | |
| 34 | + private final TransformerContext context = mock(TransformerContext.class); | |
| 35 | + private final TitaniumJsonLd jsonLd = new TitaniumJsonLd(mock(Monitor.class)); | |
| 36 | + | |
| 37 | + @Test | |
| 38 | + void types() { | |
| 39 | + assertThat(transformer.getInputType()).isEqualTo(JsonObject.class); | |
| 40 | + assertThat(transformer.getOutputType()).isEqualTo(PolicyEvaluationPlanRequest.class); | |
| 41 | + } | |
| 42 | + | |
| 43 | + @Test | |
| 44 | + void transform() { | |
| 45 | + var json = createObjectBuilder() | |
| 46 | + .add(TYPE, EDC_POLICY_EVALUATION_PLAN_REQUEST_TYPE) | |
| 47 | + .add(EDC_POLICY_EVALUATION_PLAN_REQUEST_POLICY_SCOPE, "scope") | |
| 48 | + .build(); | |
| 49 | + | |
| 50 | + var result = transformer.transform(expand(json), context); | |
| 51 | + | |
| 52 | + assertThat(result).isNotNull(); | |
| 53 | + assertThat(result.policyScope()).isEqualTo("scope"); | |
| 54 | + } | |
| 55 | + | |
| 56 | + private JsonObject expand(JsonObject jsonObject) { | |
| 57 | + return jsonLd.expand(jsonObject).orElseThrow(f -> new AssertionError(f.getFailureDetail())); | |
| 58 | + } | |
| 59 | +} |
modified extensions/control-plane/api/management-api/policy-definition-api/src/test/java/org/eclipse/edc/connector/controlplane/api/management/policy/v31alpha/PolicyDefinitionApiV31AlphaControllerTest.java +72 −2
| @@ -18,16 +18,21 @@ | ||
| 18 | 18 | import jakarta.json.Json; |
| 19 | 19 | import jakarta.json.JsonObject; |
| 20 | 20 | import org.eclipse.edc.connector.controlplane.api.management.policy.BasePolicyDefinitionApiControllerTest; |
| 21 | +import org.eclipse.edc.connector.controlplane.api.management.policy.model.PolicyEvaluationPlanRequest; | |
| 21 | 22 | import org.eclipse.edc.connector.controlplane.api.management.policy.model.PolicyValidationResult; |
| 22 | 23 | import org.eclipse.edc.connector.controlplane.policy.spi.PolicyDefinition; |
| 24 | +import org.eclipse.edc.policy.engine.spi.plan.PolicyEvaluationPlan; | |
| 23 | 25 | import org.eclipse.edc.policy.model.Policy; |
| 24 | 26 | import org.eclipse.edc.spi.result.Result; |
| 27 | +import org.eclipse.edc.spi.result.ServiceResult; | |
| 28 | +import org.eclipse.edc.validator.spi.ValidationResult; | |
| 25 | 29 | import org.junit.jupiter.api.Test; |
| 26 | 30 | |
| 27 | 31 | import java.util.List; |
| 28 | 32 | |
| 29 | 33 | import static io.restassured.RestAssured.given; |
| 30 | 34 | import static io.restassured.http.ContentType.JSON; |
| 35 | +import static org.eclipse.edc.validator.spi.Violation.violation; | |
| 31 | 36 | import static org.hamcrest.Matchers.is; |
| 32 | 37 | import static org.mockito.ArgumentMatchers.any; |
| 33 | 38 | import static org.mockito.ArgumentMatchers.eq; |
| @@ -54,7 +59,7 @@ | ||
| 54 | 59 | var policyDefinition = PolicyDefinition.Builder.newInstance().policy(Policy.Builder.newInstance().build()).build(); |
| 55 | 60 | |
| 56 | 61 | when(service.findById(any())).thenReturn(policyDefinition); |
| 57 | - when(service.validate(policyDefinition.getPolicy())).thenReturn(Result.success()); | |
| 62 | + when(service.validate(policyDefinition.getPolicy())).thenReturn(ServiceResult.success()); | |
| 58 | 63 | when(transformerRegistry.transform(any(PolicyValidationResult.class), eq(JsonObject.class))).then(answer -> { |
| 59 | 64 | PolicyValidationResult result = answer.getArgument(0); |
| 60 | 65 | var response = Json.createObjectBuilder() |
| @@ -81,7 +86,7 @@ | ||
| 81 | 86 | |
| 82 | 87 | |
| 83 | 88 | when(service.findById(any())).thenReturn(policyDefinition); |
| 84 | - when(service.validate(policyDefinition.getPolicy())).thenReturn(Result.failure(List.of("error1", "error2"))); | |
| 89 | + when(service.validate(policyDefinition.getPolicy())).thenReturn(ServiceResult.badRequest(List.of("error1", "error2"))); | |
| 85 | 90 | when(transformerRegistry.transform(any(PolicyValidationResult.class), eq(JsonObject.class))).then(answer -> { |
| 86 | 91 | PolicyValidationResult result = answer.getArgument(0); |
| 87 | 92 | var response = Json.createObjectBuilder() |
| @@ -101,6 +106,71 @@ | ||
| 101 | 106 | .body("errors.size()", is(2)); |
| 102 | 107 | } |
| 103 | 108 | |
| 109 | + @Test | |
| 110 | + void createEvaluationPlan() { | |
| 111 | + | |
| 112 | + var policyScope = "scope"; | |
| 113 | + var policyDefinition = PolicyDefinition.Builder.newInstance().policy(Policy.Builder.newInstance().build()).build(); | |
| 114 | + var plan = PolicyEvaluationPlan.Builder.newInstance().build(); | |
| 115 | + var response = Json.createObjectBuilder().build(); | |
| 116 | + var body = Json.createObjectBuilder().add("policyScope", policyScope).build(); | |
| 117 | + | |
| 118 | + when(validatorRegistry.validate(any(), any())).thenReturn(ValidationResult.success()); | |
| 119 | + when(service.findById(any())).thenReturn(policyDefinition); | |
| 120 | + when(service.createEvaluationPlan(policyScope, policyDefinition.getPolicy())).thenReturn(ServiceResult.success(plan)); | |
| 121 | + | |
| 122 | + when(transformerRegistry.transform(any(JsonObject.class), eq(PolicyEvaluationPlanRequest.class))) | |
| 123 | + .thenReturn(Result.success(new PolicyEvaluationPlanRequest(policyScope))); | |
| 124 | + | |
| 125 | + when(transformerRegistry.transform(any(PolicyEvaluationPlan.class), eq(JsonObject.class))).thenReturn(Result.success(response)); | |
| 126 | + | |
| 127 | + baseRequest() | |
| 128 | + .contentType(JSON) | |
| 129 | + .body(body) | |
| 130 | + .post("/id/evaluationplan") | |
| 131 | + .then() | |
| 132 | + .statusCode(200) | |
| 133 | + .contentType(JSON); | |
| 134 | + } | |
| 135 | + | |
| 136 | + @Test | |
| 137 | + void createEvaluationPlan_fails_whenPolicyNotFound() { | |
| 138 | + | |
| 139 | + var policyScope = "scope"; | |
| 140 | + var body = Json.createObjectBuilder().add("policyScope", policyScope).build(); | |
| 141 | + | |
| 142 | + when(validatorRegistry.validate(any(), any())).thenReturn(ValidationResult.success()); | |
| 143 | + when(service.findById(any())).thenReturn(null); | |
| 144 | + when(transformerRegistry.transform(any(JsonObject.class), eq(PolicyEvaluationPlanRequest.class))) | |
| 145 | + .thenReturn(Result.success(new PolicyEvaluationPlanRequest(policyScope))); | |
| 146 | + | |
| 147 | + baseRequest() | |
| 148 | + .contentType(JSON) | |
| 149 | + .body(body) | |
| 150 | + .post("/id/evaluationplan") | |
| 151 | + .then() | |
| 152 | + .statusCode(404); | |
| 153 | + } | |
| 154 | + | |
| 155 | + @Test | |
| 156 | + void createEvaluationPlan_fails_whenRequestValidation() { | |
| 157 | + | |
| 158 | + var policyScope = "scope"; | |
| 159 | + var body = Json.createObjectBuilder().add("policyScope", policyScope).build(); | |
| 160 | + | |
| 161 | + when(validatorRegistry.validate(any(), any())).thenReturn(ValidationResult.failure(violation("failure", "failure path"))); | |
| 162 | + when(service.findById(any())).thenReturn(null); | |
| 163 | + when(transformerRegistry.transform(any(JsonObject.class), eq(PolicyEvaluationPlanRequest.class))) | |
| 164 | + .thenReturn(Result.success(new PolicyEvaluationPlanRequest(policyScope))); | |
| 165 | + | |
| 166 | + baseRequest() | |
| 167 | + .contentType(JSON) | |
| 168 | + .body(body) | |
| 169 | + .post("/id/evaluationplan") | |
| 170 | + .then() | |
| 171 | + .statusCode(400); | |
| 172 | + } | |
| 173 | + | |
| 104 | 174 | @Override |
| 105 | 175 | protected Object controller() { |
| 106 | 176 | return new PolicyDefinitionApiV31AlphaController(monitor, transformerRegistry, service, validatorRegistry); |
added extensions/control-plane/api/management-api/policy-definition-api/src/test/java/org/eclipse/edc/connector/controlplane/api/management/policy/validation/PolicyEvaluationPlanRequestValidatorTest.java +62 −0
| @@ -0,0 +1,62 @@ | ||
| 1 | +/* | |
| 2 | + * Copyright (c) 2024 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) | |
| 3 | + * | |
| 4 | + * This program and the accompanying materials are made available under the | |
| 5 | + * terms of the Apache License, Version 2.0 which is available at | |
| 6 | + * https://www.apache.org/licenses/LICENSE-2.0 | |
| 7 | + * | |
| 8 | + * SPDX-License-Identifier: Apache-2.0 | |
| 9 | + * | |
| 10 | + * Contributors: | |
| 11 | + * Bayerische Motoren Werke Aktiengesellschaft (BMW AG) - initial API and implementation | |
| 12 | + * | |
| 13 | + */ | |
| 14 | + | |
| 15 | +package org.eclipse.edc.connector.controlplane.api.management.policy.validation; | |
| 16 | + | |
| 17 | +import jakarta.json.JsonArrayBuilder; | |
| 18 | +import jakarta.json.JsonObject; | |
| 19 | +import org.assertj.core.api.Assertions; | |
| 20 | +import org.eclipse.edc.validator.spi.ValidationFailure; | |
| 21 | +import org.eclipse.edc.validator.spi.Validator; | |
| 22 | +import org.eclipse.edc.validator.spi.Violation; | |
| 23 | +import org.junit.jupiter.api.Test; | |
| 24 | + | |
| 25 | +import static jakarta.json.Json.createArrayBuilder; | |
| 26 | +import static jakarta.json.Json.createObjectBuilder; | |
| 27 | +import static org.assertj.core.api.InstanceOfAssertFactories.list; | |
| 28 | +import static org.eclipse.edc.connector.controlplane.api.management.policy.model.PolicyEvaluationPlanRequest.EDC_POLICY_EVALUATION_PLAN_REQUEST_POLICY_SCOPE; | |
| 29 | +import static org.eclipse.edc.jsonld.spi.JsonLdKeywords.VALUE; | |
| 30 | +import static org.eclipse.edc.junit.assertions.AbstractResultAssert.assertThat; | |
| 31 | + | |
| 32 | +public class PolicyEvaluationPlanRequestValidatorTest { | |
| 33 | + | |
| 34 | + private final Validator<JsonObject> validator = PolicyEvaluationPlanRequestValidator.instance(); | |
| 35 | + | |
| 36 | + @Test | |
| 37 | + void shouldSucceed_whenObjectIsValid() { | |
| 38 | + var request = createObjectBuilder() | |
| 39 | + .add(EDC_POLICY_EVALUATION_PLAN_REQUEST_POLICY_SCOPE, value("scope")) | |
| 40 | + .build(); | |
| 41 | + | |
| 42 | + var result = validator.validate(request); | |
| 43 | + | |
| 44 | + assertThat(result).isSucceeded(); | |
| 45 | + } | |
| 46 | + | |
| 47 | + @Test | |
| 48 | + void shouldFail_whenIdIsBlank() { | |
| 49 | + var request = createObjectBuilder() | |
| 50 | + .build(); | |
| 51 | + | |
| 52 | + var result = validator.validate(request); | |
| 53 | + | |
| 54 | + assertThat(result).isFailed().extracting(ValidationFailure::getViolations).asInstanceOf(list(Violation.class)) | |
| 55 | + .isNotEmpty() | |
| 56 | + .anySatisfy(violation -> Assertions.assertThat(violation.message()).contains("blank")); | |
| 57 | + } | |
| 58 | + | |
| 59 | + private JsonArrayBuilder value(String value) { | |
| 60 | + return createArrayBuilder().add(createObjectBuilder().add(VALUE, value)); | |
| 61 | + } | |
| 62 | +} |
modified spi/common/policy-engine-spi/src/main/java/org/eclipse/edc/policy/engine/spi/AtomicConstraintFunction.java +8 −2
| @@ -34,8 +34,7 @@ | ||
| 34 | 34 | * @param context the policy context |
| 35 | 35 | */ |
| 36 | 36 | boolean evaluate(Operator operator, Object rightValue, R rule, PolicyContext context); |
| 37 | - | |
| 38 | - | |
| 37 | + | |
| 39 | 38 | /** |
| 40 | 39 | * Performs a validation of an atomic constraint |
| 41 | 40 | * |
| @@ -47,4 +46,11 @@ | ||
| 47 | 46 | default Result<Void> validate(Operator operator, Object rightValue, R rule) { |
| 48 | 47 | return Result.success(); |
| 49 | 48 | } |
| 49 | + | |
| 50 | + /** | |
| 51 | + * Returns the name of the function | |
| 52 | + */ | |
| 53 | + default String name() { | |
| 54 | + return getClass().getSimpleName(); | |
| 55 | + } | |
| 50 | 56 | } |
modified spi/common/policy-engine-spi/src/main/java/org/eclipse/edc/policy/engine/spi/DynamicAtomicConstraintFunction.java +7 −1
| @@ -43,7 +43,6 @@ | ||
| 43 | 43 | */ |
| 44 | 44 | boolean canHandle(Object leftValue); |
| 45 | 45 | |
| 46 | - | |
| 47 | 46 | /** |
| 48 | 47 | * Performs a validation of an atomic constraint |
| 49 | 48 | * |
| @@ -57,4 +56,11 @@ | ||
| 57 | 56 | return Result.success(); |
| 58 | 57 | } |
| 59 | 58 | |
| 59 | + /** | |
| 60 | + * Returns the name of the function | |
| 61 | + */ | |
| 62 | + default String name() { | |
| 63 | + return getClass().getSimpleName(); | |
| 64 | + } | |
| 65 | + | |
| 60 | 66 | } |
modified spi/common/policy-engine-spi/src/main/java/org/eclipse/edc/policy/engine/spi/RuleFunction.java +7 −0
| @@ -25,4 +25,11 @@ | ||
| 25 | 25 | * Performs the rule evaluation. |
| 26 | 26 | */ |
| 27 | 27 | boolean evaluate(R rule, PolicyContext context); |
| 28 | + | |
| 29 | + /** | |
| 30 | + * Returns the name of the function | |
| 31 | + */ | |
| 32 | + default String name() { | |
| 33 | + return getClass().getSimpleName(); | |
| 34 | + } | |
| 28 | 35 | } |
modified spi/common/policy-engine-spi/src/main/java/org/eclipse/edc/policy/engine/spi/plan/PolicyEvaluationPlan.java +15 −5
| @@ -23,17 +23,27 @@ | ||
| 23 | 23 | import java.util.ArrayList; |
| 24 | 24 | import java.util.List; |
| 25 | 25 | |
| 26 | +import static org.eclipse.edc.spi.constants.CoreConstants.EDC_NAMESPACE; | |
| 27 | + | |
| 26 | 28 | /** |
| 27 | 29 | * The {@link PolicyEvaluationPlan} contains information about the evaluation process of a {@link Policy} |
| 28 | 30 | * withing a scope without executing it. |
| 29 | 31 | */ |
| 30 | 32 | public class PolicyEvaluationPlan { |
| 31 | 33 | |
| 34 | + public static final String EDC_POLICY_EVALUATION_PLAN_TYPE = EDC_NAMESPACE + "PolicyEvaluationPlan"; | |
| 35 | + public static final String EDC_POLICY_EVALUATION_PLAN_PRE_VALIDATORS = EDC_NAMESPACE + "preValidators"; | |
| 36 | + public static final String EDC_POLICY_EVALUATION_PLAN_POST_VALIDATORS = EDC_NAMESPACE + "postValidators"; | |
| 37 | + public static final String EDC_POLICY_EVALUATION_PLAN_PERMISSION_STEPS = EDC_NAMESPACE + "permissionSteps"; | |
| 38 | + public static final String EDC_POLICY_EVALUATION_PLAN_PROHIBITION_STEPS = EDC_NAMESPACE + "prohibitionSteps"; | |
| 39 | + public static final String EDC_POLICY_EVALUATION_PLAN_OBLIGATION_STEPS = EDC_NAMESPACE + "obligationSteps"; | |
| 40 | + | |
| 41 | + | |
| 32 | 42 | private final List<ValidatorStep> preValidators = new ArrayList<>(); |
| 33 | 43 | private final List<ValidatorStep> postValidators = new ArrayList<>(); |
| 34 | 44 | private final List<PermissionStep> permissionSteps = new ArrayList<>(); |
| 35 | 45 | private final List<ProhibitionStep> prohibitionSteps = new ArrayList<>(); |
| 36 | - private final List<DutyStep> dutySteps = new ArrayList<>(); | |
| 46 | + private final List<DutyStep> obligationSteps = new ArrayList<>(); | |
| 37 | 47 | |
| 38 | 48 | public List<ValidatorStep> getPostValidators() { |
| 39 | 49 | return postValidators; |
| @@ -47,8 +57,8 @@ | ||
| 47 | 57 | return permissionSteps; |
| 48 | 58 | } |
| 49 | 59 | |
| 50 | - public List<DutyStep> getDutySteps() { | |
| 51 | - return dutySteps; | |
| 60 | + public List<DutyStep> getObligationSteps() { | |
| 61 | + return obligationSteps; | |
| 52 | 62 | } |
| 53 | 63 | |
| 54 | 64 | public List<ProhibitionStep> getProhibitionSteps() { |
| @@ -83,8 +93,8 @@ | ||
| 83 | 93 | return this; |
| 84 | 94 | } |
| 85 | 95 | |
| 86 | - public Builder obligation(DutyStep dutyStep) { | |
| 87 | - plan.dutySteps.add(dutyStep); | |
| 96 | + public Builder duty(DutyStep dutyStep) { | |
| 97 | + plan.obligationSteps.add(dutyStep); | |
| 88 | 98 | return this; |
| 89 | 99 | } |
| 90 | 100 |
modified spi/common/policy-engine-spi/src/main/java/org/eclipse/edc/policy/engine/spi/plan/step/AndConstraintStep.java +4 −0
| @@ -18,11 +18,15 @@ | ||
| 18 | 18 | |
| 19 | 19 | import java.util.List; |
| 20 | 20 | |
| 21 | +import static org.eclipse.edc.spi.constants.CoreConstants.EDC_NAMESPACE; | |
| 22 | + | |
| 21 | 23 | /** |
| 22 | 24 | * An evaluation step for {@link AndConstraint} |
| 23 | 25 | */ |
| 24 | 26 | public final class AndConstraintStep extends MultiplicityConstraintStep<AndConstraint> implements ConstraintStep { |
| 25 | 27 | |
| 28 | + public static final String EDC_AND_CONSTRAINT_STEP_TYPE = EDC_NAMESPACE + "AndConstraintStep"; | |
| 29 | + | |
| 26 | 30 | public AndConstraintStep(List<ConstraintStep> steps, AndConstraint constraint) { |
| 27 | 31 | super(steps, constraint); |
| 28 | 32 | } |
modified spi/common/policy-engine-spi/src/main/java/org/eclipse/edc/policy/engine/spi/plan/step/AtomicConstraintStep.java +30 −1
| @@ -18,13 +18,42 @@ | ||
| 18 | 18 | import org.eclipse.edc.policy.model.AtomicConstraint; |
| 19 | 19 | import org.eclipse.edc.policy.model.Rule; |
| 20 | 20 | |
| 21 | +import java.util.List; | |
| 22 | +import java.util.Optional; | |
| 23 | + | |
| 24 | +import static org.eclipse.edc.spi.constants.CoreConstants.EDC_NAMESPACE; | |
| 25 | + | |
| 21 | 26 | /** |
| 22 | 27 | * An evaluation step for {@link AtomicConstraint}. |
| 23 | 28 | * <p> |
| 24 | 29 | * The {@link AtomicConstraintStep} should be considered filtered when the left expression is not bound to a |
| 25 | 30 | * scope or an evaluation function {@link AtomicConstraintFunction} |
| 26 | 31 | */ |
| 27 | -public record AtomicConstraintStep(AtomicConstraint constraint, boolean isFiltered, Rule rule, | |
| 32 | +public record AtomicConstraintStep(AtomicConstraint constraint, | |
| 33 | + List<String> filteringReasons, | |
| 34 | + Rule rule, | |
| 28 | 35 | AtomicConstraintFunction<? extends Rule> function) implements ConstraintStep { |
| 29 | 36 | |
| 37 | + public static final String EDC_ATOMIC_CONSTRAINT_STEP_TYPE = EDC_NAMESPACE + "AtomicConstraintStep"; | |
| 38 | + public static final String EDC_ATOMIC_CONSTRAINT_STEP_IS_FILTERED = EDC_NAMESPACE + "isFiltered"; | |
| 39 | + public static final String EDC_ATOMIC_CONSTRAINT_STEP_FILTERING_REASONS = EDC_NAMESPACE + "filteringReasons"; | |
| 40 | + public static final String EDC_ATOMIC_CONSTRAINT_STEP_FUNCTION_NAME = EDC_NAMESPACE + "functionName"; | |
| 41 | + public static final String EDC_ATOMIC_CONSTRAINT_STEP_FUNCTION_PARAMS = EDC_NAMESPACE + "functionParams"; | |
| 42 | + | |
| 43 | + public boolean isFiltered() { | |
| 44 | + return !filteringReasons.isEmpty(); | |
| 45 | + } | |
| 46 | + | |
| 47 | + public String functionName() { | |
| 48 | + return Optional.ofNullable(function) | |
| 49 | + .map(AtomicConstraintFunction::name) | |
| 50 | + .orElse(null); | |
| 51 | + } | |
| 52 | + | |
| 53 | + public List<String> functionParams() { | |
| 54 | + return List.of( | |
| 55 | + constraint.getLeftExpression().toString(), | |
| 56 | + constraint.getOperator().toString(), | |
| 57 | + constraint.getRightExpression().toString()); | |
| 58 | + } | |
| 30 | 59 | } |
modified spi/common/policy-engine-spi/src/main/java/org/eclipse/edc/policy/engine/spi/plan/step/DutyStep.java +4 −0
| @@ -16,11 +16,15 @@ | ||
| 16 | 16 | |
| 17 | 17 | import org.eclipse.edc.policy.model.Duty; |
| 18 | 18 | |
| 19 | +import static org.eclipse.edc.spi.constants.CoreConstants.EDC_NAMESPACE; | |
| 20 | + | |
| 19 | 21 | /** |
| 20 | 22 | * An evaluation step for {@link Duty} rule; |
| 21 | 23 | */ |
| 22 | 24 | public class DutyStep extends RuleStep<Duty> { |
| 23 | 25 | |
| 26 | + public static final String EDC_DUTY_STEP_TYPE = EDC_NAMESPACE + "DutyStep"; | |
| 27 | + | |
| 24 | 28 | public static class Builder extends RuleStep.Builder<Duty, DutyStep, Builder> { |
| 25 | 29 | |
| 26 | 30 | private Builder() { |
modified spi/common/policy-engine-spi/src/main/java/org/eclipse/edc/policy/engine/spi/plan/step/MultiplicityConstraintStep.java +9 −5
| @@ -18,22 +18,26 @@ | ||
| 18 | 18 | |
| 19 | 19 | import java.util.List; |
| 20 | 20 | |
| 21 | +import static org.eclipse.edc.spi.constants.CoreConstants.EDC_NAMESPACE; | |
| 22 | + | |
| 21 | 23 | /** |
| 22 | 24 | * Base evaluation step for {@link MultiplicityConstraint}. It carries the {@link MultiplicityConstraint} |
| 23 | 25 | * and the collection of child {@link ConstraintStep}. |
| 24 | 26 | */ |
| 25 | 27 | public abstract class MultiplicityConstraintStep<T extends MultiplicityConstraint> { |
| 28 | + | |
| 29 | + public static final String EDC_MULTIPLICITY_CONSTRAINT_STEPS = EDC_NAMESPACE + "constraintSteps"; | |
| 26 | 30 | |
| 27 | - private final List<ConstraintStep> steps; | |
| 31 | + private final List<ConstraintStep> constraintSteps; | |
| 28 | 32 | private final T constraint; |
| 29 | 33 | |
| 30 | - public MultiplicityConstraintStep(List<ConstraintStep> steps, T constraint) { | |
| 34 | + public MultiplicityConstraintStep(List<ConstraintStep> constraintSteps, T constraint) { | |
| 31 | 35 | this.constraint = constraint; |
| 32 | - this.steps = steps; | |
| 36 | + this.constraintSteps = constraintSteps; | |
| 33 | 37 | } |
| 34 | 38 | |
| 35 | - public List<ConstraintStep> getSteps() { | |
| 36 | - return steps; | |
| 39 | + public List<ConstraintStep> getConstraintSteps() { | |
| 40 | + return constraintSteps; | |
| 37 | 41 | } |
| 38 | 42 | |
| 39 | 43 | public T getConstraint() { |
modified spi/common/policy-engine-spi/src/main/java/org/eclipse/edc/policy/engine/spi/plan/step/OrConstraintStep.java +5 −0
| @@ -18,12 +18,17 @@ | ||
| 18 | 18 | |
| 19 | 19 | import java.util.List; |
| 20 | 20 | |
| 21 | +import static org.eclipse.edc.spi.constants.CoreConstants.EDC_NAMESPACE; | |
| 22 | + | |
| 21 | 23 | /** |
| 22 | 24 | * An evaluation step for {@link OrConstraint} |
| 23 | 25 | */ |
| 24 | 26 | public final class OrConstraintStep extends MultiplicityConstraintStep<OrConstraint> implements ConstraintStep { |
| 25 | 27 | |
| 28 | + public static final String EDC_OR_CONSTRAINT_STEP_TYPE = EDC_NAMESPACE + "OrConstraintStep"; | |
| 29 | + | |
| 26 | 30 | public OrConstraintStep(List<ConstraintStep> steps, OrConstraint constraint) { |
| 27 | 31 | super(steps, constraint); |
| 28 | 32 | } |
| 33 | + | |
| 29 | 34 | } |
modified spi/common/policy-engine-spi/src/main/java/org/eclipse/edc/policy/engine/spi/plan/step/PermissionStep.java +6 −1
| @@ -19,11 +19,16 @@ | ||
| 19 | 19 | import java.util.ArrayList; |
| 20 | 20 | import java.util.List; |
| 21 | 21 | |
| 22 | +import static org.eclipse.edc.spi.constants.CoreConstants.EDC_NAMESPACE; | |
| 23 | + | |
| 22 | 24 | /** |
| 23 | 25 | * An evaluation step for {@link Permission} rule; |
| 24 | 26 | */ |
| 25 | 27 | public class PermissionStep extends RuleStep<Permission> { |
| 26 | - | |
| 28 | + | |
| 29 | + public static final String EDC_PERMISSION_STEP_TYPE = EDC_NAMESPACE + "PermissionStep"; | |
| 30 | + public static final String EDC_PERMISSION_STEP_DUTY_STEPS = EDC_NAMESPACE + "dutySteps"; | |
| 31 | + | |
| 27 | 32 | private final List<DutyStep> dutySteps = new ArrayList<>(); |
| 28 | 33 | |
| 29 | 34 | public List<DutyStep> getDutySteps() { |
modified spi/common/policy-engine-spi/src/main/java/org/eclipse/edc/policy/engine/spi/plan/step/ProhibitionStep.java +4 −0
| @@ -17,11 +17,15 @@ | ||
| 17 | 17 | import com.fasterxml.jackson.annotation.JsonCreator; |
| 18 | 18 | import org.eclipse.edc.policy.model.Prohibition; |
| 19 | 19 | |
| 20 | +import static org.eclipse.edc.spi.constants.CoreConstants.EDC_NAMESPACE; | |
| 21 | + | |
| 20 | 22 | /** |
| 21 | 23 | * An evaluation step for {@link Prohibition} rule; |
| 22 | 24 | */ |
| 23 | 25 | public class ProhibitionStep extends RuleStep<Prohibition> { |
| 24 | 26 | |
| 27 | + public static final String EDC_PROHIBITION_STEP_TYPE = EDC_NAMESPACE + "ProhibitionStep"; | |
| 28 | + | |
| 25 | 29 | public static class Builder extends RuleStep.Builder<Prohibition, ProhibitionStep, Builder> { |
| 26 | 30 | |
| 27 | 31 | private Builder() { |
modified spi/common/policy-engine-spi/src/main/java/org/eclipse/edc/policy/engine/spi/plan/step/RuleFunctionStep.java +6 −0
| @@ -22,4 +22,10 @@ | ||
| 22 | 22 | */ |
| 23 | 23 | public record RuleFunctionStep<R extends Rule>(RuleFunction<R> function, R rule) { |
| 24 | 24 | |
| 25 | + /** | |
| 26 | + * Returns the {@link RuleFunction#name()} | |
| 27 | + */ | |
| 28 | + public String functionName() { | |
| 29 | + return function.name(); | |
| 30 | + } | |
| 25 | 31 | } |
| No newline at the end of the file |
modified spi/common/policy-engine-spi/src/main/java/org/eclipse/edc/policy/engine/spi/plan/step/RuleStep.java +17 −0
| @@ -20,6 +20,8 @@ | ||
| 20 | 20 | import java.util.List; |
| 21 | 21 | import java.util.Objects; |
| 22 | 22 | |
| 23 | +import static org.eclipse.edc.spi.constants.CoreConstants.EDC_NAMESPACE; | |
| 24 | + | |
| 23 | 25 | /** |
| 24 | 26 | * Base step class for {@link Rule}s evaluation. A rule can have multiple {@link ConstraintStep} |
| 25 | 27 | * and {@link RuleFunctionStep} associated during the evaluation process. |
| @@ -27,10 +29,16 @@ | ||
| 27 | 29 | */ |
| 28 | 30 | public abstract class RuleStep<R extends Rule> { |
| 29 | 31 | |
| 32 | + public static final String EDC_RULE_STEP_IS_FILTERED = EDC_NAMESPACE + "isFiltered"; | |
| 33 | + public static final String EDC_RULE_STEP_FILTERING_REASONS = EDC_NAMESPACE + "filteringReasons"; | |
| 34 | + public static final String EDC_RULE_CONSTRAINT_STEPS = EDC_NAMESPACE + "constraintSteps"; | |
| 35 | + public static final String EDC_RULE_FUNCTIONS = EDC_NAMESPACE + "ruleFunctions"; | |
| 36 | + | |
| 30 | 37 | protected R rule; |
| 31 | 38 | protected boolean isFiltered = false; |
| 32 | 39 | |
| 33 | 40 | protected List<ConstraintStep> constraintSteps = new ArrayList<>(); |
| 41 | + protected List<String> filteringReasons = new ArrayList<>(); | |
| 34 | 42 | |
| 35 | 43 | protected List<RuleFunctionStep<R>> ruleFunctions = new ArrayList<>(); |
| 36 | 44 | |
| @@ -42,6 +50,10 @@ | ||
| 42 | 50 | return ruleFunctions; |
| 43 | 51 | } |
| 44 | 52 | |
| 53 | + public List<String> getFilteringReasons() { | |
| 54 | + return filteringReasons; | |
| 55 | + } | |
| 56 | + | |
| 45 | 57 | public boolean isFiltered() { |
| 46 | 58 | return isFiltered; |
| 47 | 59 | } |
| @@ -71,6 +83,11 @@ | ||
| 71 | 83 | return (B) this; |
| 72 | 84 | } |
| 73 | 85 | |
| 86 | + public B filteringReason(String reason) { | |
| 87 | + ruleStep.filteringReasons.add(reason); | |
| 88 | + return (B) this; | |
| 89 | + } | |
| 90 | + | |
| 74 | 91 | public T build() { |
| 75 | 92 | Objects.requireNonNull(ruleStep.rule, "Rule should not be null"); |
| 76 | 93 | return ruleStep; |
modified spi/common/policy-engine-spi/src/main/java/org/eclipse/edc/policy/engine/spi/plan/step/ValidatorStep.java +6 −0
| @@ -24,4 +24,10 @@ | ||
| 24 | 24 | */ |
| 25 | 25 | public record ValidatorStep(BiFunction<Policy, PolicyContext, Boolean> validator) { |
| 26 | 26 | |
| 27 | + /** | |
| 28 | + * Returns the name of the validator | |
| 29 | + */ | |
| 30 | + public String name() { | |
| 31 | + return validator.getClass().getSimpleName(); | |
| 32 | + } | |
| 27 | 33 | } |
modified spi/common/policy-engine-spi/src/main/java/org/eclipse/edc/policy/engine/spi/plan/step/XoneConstraintStep.java +4 −0
| @@ -18,11 +18,15 @@ | ||
| 18 | 18 | |
| 19 | 19 | import java.util.List; |
| 20 | 20 | |
| 21 | +import static org.eclipse.edc.spi.constants.CoreConstants.EDC_NAMESPACE; | |
| 22 | + | |
| 21 | 23 | /** |
| 22 | 24 | * An evaluation step for {@link XoneConstraint} |
| 23 | 25 | */ |
| 24 | 26 | public final class XoneConstraintStep extends MultiplicityConstraintStep<XoneConstraint> implements ConstraintStep { |
| 25 | 27 | |
| 28 | + public static final String EDC_XONE_CONSTRAINT_STEP_TYPE = EDC_NAMESPACE + "XoneConstraintStep"; | |
| 29 | + | |
| 26 | 30 | public XoneConstraintStep(List<ConstraintStep> steps, XoneConstraint constraint) { |
| 27 | 31 | super(steps, constraint); |
| 28 | 32 | } |
modified spi/control-plane/control-plane-spi/src/main/java/org/eclipse/edc/connector/controlplane/services/spi/policydefinition/PolicyDefinitionService.java +10 −3
| @@ -15,10 +15,10 @@ | ||
| 15 | 15 | package org.eclipse.edc.connector.controlplane.services.spi.policydefinition; |
| 16 | 16 | |
| 17 | 17 | import org.eclipse.edc.connector.controlplane.policy.spi.PolicyDefinition; |
| 18 | +import org.eclipse.edc.policy.engine.spi.plan.PolicyEvaluationPlan; | |
| 18 | 19 | import org.eclipse.edc.policy.model.Policy; |
| 19 | 20 | import org.eclipse.edc.runtime.metamodel.annotation.ExtensionPoint; |
| 20 | 21 | import org.eclipse.edc.spi.query.QuerySpec; |
| 21 | -import org.eclipse.edc.spi.result.Result; | |
| 22 | 22 | import org.eclipse.edc.spi.result.ServiceResult; |
| 23 | 23 | import org.jetbrains.annotations.NotNull; |
| 24 | 24 | |
| @@ -80,6 +80,13 @@ | ||
| 80 | 80 | * @param policy the policy |
| 81 | 81 | * @return successful if valid, a failure otherwise |
| 82 | 82 | */ |
| 83 | - Result<Void> validate(Policy policy); | |
| 84 | - | |
| 83 | + ServiceResult<Void> validate(Policy policy); | |
| 84 | + | |
| 85 | + /** | |
| 86 | + * Validates a {@link Policy} | |
| 87 | + * | |
| 88 | + * @param policy the policy | |
| 89 | + * @return successful if valid, a failure otherwise | |
| 90 | + */ | |
| 91 | + ServiceResult<PolicyEvaluationPlan> createEvaluationPlan(String scope, Policy policy); | |
| 85 | 92 | } |
modified system-tests/management-api/management-api-test-runner/src/test/java/org/eclipse/edc/test/e2e/managementapi/PolicyDefinitionApiEndToEndTest.java +51 −0
| @@ -43,6 +43,8 @@ | ||
| 43 | 43 | import static org.eclipse.edc.spi.query.Criterion.criterion; |
| 44 | 44 | import static org.hamcrest.Matchers.hasEntry; |
| 45 | 45 | import static org.hamcrest.Matchers.is; |
| 46 | +import static org.hamcrest.Matchers.notNullValue; | |
| 47 | +import static org.hamcrest.Matchers.nullValue; | |
| 46 | 48 | |
| 47 | 49 | public class PolicyDefinitionApiEndToEndTest { |
| 48 | 50 | |
| @@ -303,6 +305,55 @@ | ||
| 303 | 305 | |
| 304 | 306 | } |
| 305 | 307 | |
| 308 | + @Test | |
| 309 | + void shouldCreateEvaluationPlan(ManagementEndToEndTestContext context) { | |
| 310 | + var requestBody = createObjectBuilder() | |
| 311 | + .add(CONTEXT, createObjectBuilder() | |
| 312 | + .add(VOCAB, EDC_NAMESPACE) | |
| 313 | + .build()) | |
| 314 | + .add(TYPE, "PolicyDefinition") | |
| 315 | + .add("policy", sampleOdrlPolicy()) | |
| 316 | + .build(); | |
| 317 | + | |
| 318 | + var id = context.baseRequest() | |
| 319 | + .body(requestBody) | |
| 320 | + .contentType(JSON) | |
| 321 | + .post("/v3/policydefinitions") | |
| 322 | + .then() | |
| 323 | + .statusCode(200) | |
| 324 | + .extract().jsonPath().getString(ID); | |
| 325 | + | |
| 326 | + var planBody = createObjectBuilder().add(CONTEXT, createObjectBuilder() | |
| 327 | + .add(VOCAB, EDC_NAMESPACE) | |
| 328 | + .build()) | |
| 329 | + .add(TYPE, "PolicyEvaluationPlanRequest") | |
| 330 | + .add("policyScope", "catalog") | |
| 331 | + .build(); | |
| 332 | + | |
| 333 | + context.baseRequest() | |
| 334 | + .contentType(JSON) | |
| 335 | + .body(planBody) | |
| 336 | + .post("/v3.1alpha/policydefinitions/" + id + "/evaluationplan") | |
| 337 | + .then() | |
| 338 | + .statusCode(200) | |
| 339 | + .body("preValidators.size()", is(0)) | |
| 340 | + .body("permissionSteps.isFiltered", is(false)) | |
| 341 | + .body("permissionSteps.filteringReasons.size()", is(0)) | |
| 342 | + .body("permissionSteps.constraintSteps.'@type'", is("AtomicConstraintStep")) | |
| 343 | + .body("permissionSteps.constraintSteps.isFiltered", is(true)) | |
| 344 | + .body("permissionSteps.constraintSteps.filteringReasons.size()", is(2)) | |
| 345 | + .body("permissionSteps.constraintSteps.functionName", nullValue()) | |
| 346 | + .body("permissionSteps.constraintSteps.functionParams.size()", is(3)) | |
| 347 | + .body("prohibitionSteps.isFiltered", is(true)) | |
| 348 | + .body("prohibitionSteps.filteringReasons", notNullValue()) | |
| 349 | + .body("prohibitionSteps.constraintSteps.size()", is(0)) | |
| 350 | + .body("obligationSteps.isFiltered", is(false)) | |
| 351 | + .body("obligationSteps.filteringReasons.size()", is(0)) | |
| 352 | + .body("obligationSteps.constraintSteps.size()", is(0)) | |
| 353 | + .body("postValidators.size()", is(0)); | |
| 354 | + | |
| 355 | + } | |
| 356 | + | |
| 306 | 357 | private JsonObject sampleOdrlPolicy() { |
| 307 | 358 | return createObjectBuilder() |
| 308 | 359 | .add(CONTEXT, "http://www.w3.org/ns/odrl.jsonld") |