generated from amosproj/amos202Xss0Y-projname
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #106 from amosproj/ui-improvements
UI improvements and policy function
- Loading branch information
Showing
12 changed files
with
359 additions
and
41 deletions.
There are no files selected for viewing
48 changes: 48 additions & 0 deletions
48
...or/connector/src/main/java/org/eclipse/edc/extension/policy/PolicyConstraintFunction.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/* | ||
* Copyright (c) 2024 Fraunhofer Institute for Software and Systems Engineering | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Apache License, Version 2.0 which is available at | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* Contributors: | ||
* Fraunhofer Institute for Software and Systems Engineering - initial API and implementation | ||
* | ||
*/ | ||
|
||
package org.eclipse.edc.extension.policy; | ||
|
||
import org.eclipse.edc.policy.engine.spi.AtomicConstraintFunction; | ||
import org.eclipse.edc.policy.engine.spi.PolicyContext; | ||
import org.eclipse.edc.policy.model.Operator; | ||
import org.eclipse.edc.policy.model.Permission; | ||
import org.eclipse.edc.spi.agent.ParticipantAgent; | ||
import org.eclipse.edc.spi.monitor.Monitor; | ||
|
||
import java.util.Objects; | ||
|
||
import static java.lang.String.format; | ||
|
||
public class PolicyConstraintFunction implements AtomicConstraintFunction<Permission> { | ||
|
||
private final Monitor monitor; | ||
|
||
public PolicyConstraintFunction(Monitor monitor) { | ||
this.monitor = monitor; | ||
} | ||
|
||
@Override | ||
public boolean evaluate(Operator operator, Object rightValue, Permission rule, PolicyContext context) { | ||
var role = context.getContextData(ParticipantAgent.class).getClaims().get("role"); | ||
|
||
monitor.info(format("Evaluating constraint: role %s %s", operator, rightValue.toString())); | ||
|
||
return switch (operator) { | ||
case EQ -> Objects.equals(role, rightValue); | ||
case NEQ -> !Objects.equals(role, rightValue); | ||
default -> false; | ||
}; | ||
} | ||
} |
50 changes: 50 additions & 0 deletions
50
...or/connector/src/main/java/org/eclipse/edc/extension/policy/PolicyFunctionsExtension.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
/* | ||
* Copyright (c) 2024 Fraunhofer Institute for Software and Systems Engineering | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Apache License, Version 2.0 which is available at | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* Contributors: | ||
* Fraunhofer Institute for Software and Systems Engineering - initial API and implementation | ||
* | ||
*/ | ||
|
||
package org.eclipse.edc.extension.policy; | ||
|
||
import org.eclipse.edc.policy.engine.spi.PolicyEngine; | ||
import org.eclipse.edc.policy.engine.spi.RuleBindingRegistry; | ||
import org.eclipse.edc.policy.model.Permission; | ||
import org.eclipse.edc.runtime.metamodel.annotation.Inject; | ||
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.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; | ||
|
||
public class PolicyFunctionsExtension implements ServiceExtension { | ||
private static final String ROLE_CONSTRAINT_KEY = EDC_NAMESPACE + "role"; | ||
|
||
@Inject | ||
private RuleBindingRegistry ruleBindingRegistry; | ||
@Inject | ||
private PolicyEngine policyEngine; | ||
|
||
@Override | ||
public String name() { | ||
return "Policy functions"; | ||
} | ||
|
||
@Override | ||
public void initialize(ServiceExtensionContext context) { | ||
var monitor = context.getMonitor(); | ||
|
||
ruleBindingRegistry.bind(ODRL_USE_ACTION_ATTRIBUTE, ALL_SCOPES); | ||
ruleBindingRegistry.bind(ROLE_CONSTRAINT_KEY, NEGOTIATION_SCOPE); | ||
policyEngine.registerFunction(ALL_SCOPES, Permission.class, ROLE_CONSTRAINT_KEY, new PolicyConstraintFunction(monitor)); | ||
} | ||
} |
3 changes: 2 additions & 1 deletion
3
...onnector/src/main/resources/META-INF/services/org.eclipse.edc.spi.system.ServiceExtension
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
org.eclipse.edc.extension.status.StatusEndpointExtension | ||
org.eclipse.edc.extension.bootstrap.BootstrapLoaderExtension | ||
org.eclipse.edc.extension.bootstrap.BootstrapLoaderExtension | ||
org.eclipse.edc.extension.policy.PolicyFunctionsExtension |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.