diff --git a/policy/policy-01-policy-enforcement/README.md b/policy/policy-01-policy-enforcement/README.md index cdde3832..15a66dc0 100644 --- a/policy/policy-01-policy-enforcement/README.md +++ b/policy/policy-01-policy-enforcement/README.md @@ -37,25 +37,25 @@ When creating a rule binding, we can bind an action type or constraint to either Here, we bind the action type `use` to all scopes, so that rules with this action type are always evaluated. For the location constraint we choose the negotiation scope, meaning it will only be evaluated during the contract negotiation. Information on available scopes can be found -[here](https://github.com/eclipse-edc/Connector/blob/main/docs/developer/policy-engine.md). +[here](https://eclipse-edc.github.io/documentation/for-adopters/control-plane/policy-engine/). ### Implementing the function for evaluation With the rule bindings in place, the provider will now try to evaluate our policy including the constraint during a contract negotiation, but it does not yet know *how* to evaluate this constraint. For this, we need to implement a -function, for which the EDC offer two interfaces: `AtomicConstraintFunction` and `RuleFunction`. The former is meant -for evaluating a single constraint of a rule, while is latter is meant for evaluating a complete rule node (including -constraints as well as duties that may be associated with a permission). For our example, we choose to implement an -`AtomicConstraintFunction`, as we want to evaluate our location constraint: +function, for which the EDC offer two interfaces: `AtomicConstraintRuleFunction` and `PolicyRuleFunction`. The former is +meant for evaluating a single constraint of a rule, while is latter is meant for evaluating a complete rule node +(including constraints as well as duties that may be associated with a permission). For our example, we choose to +implement an `AtomicConstraintRuleFunction`, as we want to evaluate our location constraint: ```java -public class LocationConstraintFunction implements AtomicConstraintFunction { +public class LocationConstraintFunction implements AtomicConstraintRuleFunction { //... @Override - public boolean evaluate(Operator operator, Object rightValue, Permission rule, PolicyContext context) { - var region = context.getContextData(ParticipantAgent.class).getClaims().get("region"); + public boolean evaluate(Operator operator, Object rightValue, Permission rule, ContractNegotiationPolicyContext context) { + var region = context.participantAgent().getClaims().get("region"); monitor.info(format("Evaluating constraint: location %s %s", operator, rightValue.toString())); @@ -70,12 +70,13 @@ public class LocationConstraintFunction implements AtomicConstraintFunction { +public class LocationConstraintFunction implements AtomicConstraintRuleFunction { private final Monitor monitor; @@ -35,8 +34,8 @@ public LocationConstraintFunction(Monitor monitor) { } @Override - public boolean evaluate(Operator operator, Object rightValue, Permission rule, PolicyContext context) { - var region = context.getContextData(ParticipantAgent.class).getClaims().get("region"); + public boolean evaluate(Operator operator, Object rightValue, Permission rule, ContractNegotiationPolicyContext context) { + var region = context.participantAgent().getClaims().get("region"); monitor.info(format("Evaluating constraint: location %s %s", operator, rightValue.toString())); @@ -47,4 +46,4 @@ public boolean evaluate(Operator operator, Object rightValue, Permission rule, P default -> false; }; } -} \ No newline at end of file +} diff --git a/policy/policy-01-policy-enforcement/policy-functions/src/main/java/org/eclipse/edc/sample/extension/policy/PolicyFunctionsExtension.java b/policy/policy-01-policy-enforcement/policy-functions/src/main/java/org/eclipse/edc/sample/extension/policy/PolicyFunctionsExtension.java index 0d1018d7..85f80c09 100644 --- a/policy/policy-01-policy-enforcement/policy-functions/src/main/java/org/eclipse/edc/sample/extension/policy/PolicyFunctionsExtension.java +++ b/policy/policy-01-policy-enforcement/policy-functions/src/main/java/org/eclipse/edc/sample/extension/policy/PolicyFunctionsExtension.java @@ -14,6 +14,7 @@ package org.eclipse.edc.sample.extension.policy; +import org.eclipse.edc.connector.controlplane.contract.spi.policy.ContractNegotiationPolicyContext; import org.eclipse.edc.policy.engine.spi.PolicyEngine; import org.eclipse.edc.policy.engine.spi.RuleBindingRegistry; import org.eclipse.edc.policy.model.Permission; @@ -21,7 +22,7 @@ import org.eclipse.edc.spi.system.ServiceExtension; import org.eclipse.edc.spi.system.ServiceExtensionContext; -import static org.eclipse.edc.connector.controlplane.contract.spi.validation.ContractValidationService.NEGOTIATION_SCOPE; +import static org.eclipse.edc.connector.controlplane.contract.spi.policy.ContractNegotiationPolicyContext.NEGOTIATION_SCOPE; import static org.eclipse.edc.jsonld.spi.PropertyAndTypeNames.ODRL_USE_ACTION_ATTRIBUTE; import static org.eclipse.edc.policy.engine.spi.PolicyEngine.ALL_SCOPES; import static org.eclipse.edc.spi.constants.CoreConstants.EDC_NAMESPACE; @@ -45,6 +46,6 @@ public void initialize(ServiceExtensionContext context) { ruleBindingRegistry.bind(ODRL_USE_ACTION_ATTRIBUTE, ALL_SCOPES); ruleBindingRegistry.bind(LOCATION_CONSTRAINT_KEY, NEGOTIATION_SCOPE); - policyEngine.registerFunction(ALL_SCOPES, Permission.class, LOCATION_CONSTRAINT_KEY, new LocationConstraintFunction(monitor)); + policyEngine.registerFunction(ContractNegotiationPolicyContext.class, Permission.class, LOCATION_CONSTRAINT_KEY, new LocationConstraintFunction(monitor)); } }