Skip to content

Commit

Permalink
fix: Connector-Restricted-Usage Policy #727 (#792)
Browse files Browse the repository at this point in the history
  • Loading branch information
efiege authored Feb 13, 2024
1 parent 78d92b0 commit dbf9575
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 10 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ please see [changelog_updates.md](docs/dev/changelog_updates.md).

#### Minor Changes
- Add new MDS fields and migrate existing MDS asset keys to mobilityDCAT-AP
- Fix Connector-Restricted-Usage Policy

#### Patch Changes
- Docs: Enhanced starting a Http-Pull over the EDC-Ui documentation
Expand Down
1 change: 1 addition & 0 deletions extensions/policy-referring-connector/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ plugins {
dependencies {
api("${edcGroup}:auth-spi:${edcVersion}")
api("${edcGroup}:policy-engine-spi:${edcVersion}")
api("${edcGroup}:contract-spi:${edcVersion}")
testImplementation("${edcGroup}:junit:${edcVersion}")

testImplementation("org.mockito:mockito-core:${mockitoVersion}")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,15 @@
import de.sovity.edc.extension.policy.functions.ReferringConnectorDutyFunction;
import de.sovity.edc.extension.policy.functions.ReferringConnectorPermissionFunction;
import de.sovity.edc.extension.policy.functions.ReferringConnectorProhibitionFunction;
import org.eclipse.edc.connector.contract.spi.offer.ContractDefinitionResolver;
import org.eclipse.edc.connector.contract.spi.validation.ContractValidationService;
import org.eclipse.edc.policy.engine.spi.AtomicConstraintFunction;
import org.eclipse.edc.policy.engine.spi.PolicyEngine;
import org.eclipse.edc.policy.engine.spi.RuleBindingRegistry;
import org.eclipse.edc.policy.model.Duty;
import org.eclipse.edc.policy.model.Permission;
import org.eclipse.edc.policy.model.Prohibition;
import org.eclipse.edc.policy.model.Rule;
import org.eclipse.edc.runtime.metamodel.annotation.Inject;
import org.eclipse.edc.spi.system.ServiceExtension;
import org.eclipse.edc.spi.system.ServiceExtensionContext;
Expand Down Expand Up @@ -97,17 +101,16 @@ public String name() {

@Override
public void initialize(ServiceExtensionContext context) {
final var monitor = context.getMonitor();
ruleBindingRegistry.bind(REFERRING_CONNECTOR_CONSTRAINT_KEY, ContractValidationService.NEGOTIATION_SCOPE);
ruleBindingRegistry.bind(REFERRING_CONNECTOR_CONSTRAINT_KEY, ContractDefinitionResolver.CATALOGING_SCOPE);

final var dutyFunction = new ReferringConnectorDutyFunction(monitor);
final var permissionFunction = new ReferringConnectorPermissionFunction(monitor);
final var prohibitionFunction = new ReferringConnectorProhibitionFunction(monitor);

ruleBindingRegistry.bind("USE", ALL_SCOPES);
ruleBindingRegistry.bind(REFERRING_CONNECTOR_CONSTRAINT_KEY, ALL_SCOPES);
var monitor = context.getMonitor();
registerPolicyFunction(Duty.class, new ReferringConnectorDutyFunction(monitor));
registerPolicyFunction(Permission.class, new ReferringConnectorPermissionFunction(monitor));
registerPolicyFunction(Prohibition.class, new ReferringConnectorProhibitionFunction(monitor));
}

policyEngine.registerFunction(ALL_SCOPES, Duty.class, REFERRING_CONNECTOR_CONSTRAINT_KEY, dutyFunction);
policyEngine.registerFunction(ALL_SCOPES, Permission.class, REFERRING_CONNECTOR_CONSTRAINT_KEY, permissionFunction);
policyEngine.registerFunction(ALL_SCOPES, Prohibition.class, REFERRING_CONNECTOR_CONSTRAINT_KEY, prohibitionFunction);
private <R extends Rule> void registerPolicyFunction(Class<R> type, AtomicConstraintFunction<R> function) {
policyEngine.registerFunction(ALL_SCOPES, type, REFERRING_CONNECTOR_CONSTRAINT_KEY, function);
}
}

0 comments on commit dbf9575

Please sign in to comment.