-
Notifications
You must be signed in to change notification settings - Fork 246
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(policy): provide new contexts and function interfaces for po…
…licy engine (#4542) * refactor(policy-engine): provide new contexts and function interfaces * pr remark
- Loading branch information
Showing
28 changed files
with
693 additions
and
104 deletions.
There are no files selected for viewing
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
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
57 changes: 57 additions & 0 deletions
57
...ine-spi/src/main/java/org/eclipse/edc/policy/engine/spi/AtomicConstraintRuleFunction.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,57 @@ | ||
/* | ||
* Copyright (c) 2021 Microsoft Corporation | ||
* | ||
* 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: | ||
* Microsoft Corporation - initial API and implementation | ||
* | ||
*/ | ||
|
||
package org.eclipse.edc.policy.engine.spi; | ||
|
||
import org.eclipse.edc.policy.model.Operator; | ||
import org.eclipse.edc.policy.model.Rule; | ||
import org.eclipse.edc.spi.result.Result; | ||
|
||
/** | ||
* Invoked during policy evaluation when the left operand of an atomic constraint evaluates to a key associated with this function. The function is responsible for performing | ||
* policy evaluation on the right operand. | ||
*/ | ||
@FunctionalInterface | ||
public interface AtomicConstraintRuleFunction<R extends Rule, C extends PolicyContext> { | ||
|
||
/** | ||
* Performs the evaluation. | ||
* | ||
* @param operator the operation | ||
* @param rightValue the right-side expression for the constraint; the concrete type may be a string, primitive or object such as a JSON-LD encoded collection. | ||
* @param rule the rule associated with the constraint | ||
* @param context the policy context | ||
*/ | ||
boolean evaluate(Operator operator, Object rightValue, R rule, C context); | ||
|
||
/** | ||
* Performs a validation of an atomic constraint | ||
* | ||
* @param operator the operation | ||
* @param rightValue the right-side expression for the constraint; the concrete type may be a string, primitive or object such as a JSON-LD encoded collection | ||
* @param rule the rule associated with the constraint | ||
* @return the result of the validation | ||
*/ | ||
default Result<Void> validate(Operator operator, Object rightValue, R rule) { | ||
return Result.success(); | ||
} | ||
|
||
/** | ||
* Returns the name of the function | ||
*/ | ||
default String name() { | ||
return getClass().getSimpleName(); | ||
} | ||
|
||
} |
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
66 changes: 66 additions & 0 deletions
66
.../src/main/java/org/eclipse/edc/policy/engine/spi/DynamicAtomicConstraintRuleFunction.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,66 @@ | ||
/* | ||
* Copyright (c) 2024 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) | ||
* | ||
* 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: | ||
* Bayerische Motoren Werke Aktiengesellschaft (BMW AG) - initial API and implementation | ||
* | ||
*/ | ||
|
||
package org.eclipse.edc.policy.engine.spi; | ||
|
||
import org.eclipse.edc.policy.model.Operator; | ||
import org.eclipse.edc.policy.model.Rule; | ||
import org.eclipse.edc.spi.result.Result; | ||
|
||
/** | ||
* Invoked during policy evaluation as when the left operand of an atomic constraint evaluates to a key that is not bound to a {@link AtomicConstraintRuleFunction}. | ||
* The function is responsible for performing policy evaluation on the right operand and the left operand. | ||
*/ | ||
public interface DynamicAtomicConstraintRuleFunction<R extends Rule, C extends PolicyContext> { | ||
|
||
/** | ||
* Performs the evaluation. | ||
* | ||
* @param leftValue the left-side expression for the constraint | ||
* @param operator the operation | ||
* @param rightValue the right-side expression for the constraint; the concrete type may be a string, primitive or object such as a JSON-LD encoded collection. | ||
* @param rule the rule associated with the constraint | ||
* @param context the policy context | ||
*/ | ||
boolean evaluate(Object leftValue, Operator operator, Object rightValue, R rule, C context); | ||
|
||
/** | ||
* Returns true if the function can evaluate the input left operand. | ||
* | ||
* @param leftValue the left-side expression for the constraint | ||
* @return true if the function can evaluate the left operand, false otherwise | ||
*/ | ||
boolean canHandle(Object leftValue); | ||
|
||
/** | ||
* Performs a validation of an atomic constraint | ||
* | ||
* @param leftValue the left-side expression for the constraint | ||
* @param operator the operation | ||
* @param rightValue the right-side expression for the constraint; the concrete type may be a string, primitive or object such as a JSON-LD encoded collection | ||
* @param rule the rule associated with the constraint | ||
* @return the result of the validation | ||
*/ | ||
default Result<Void> validate(Object leftValue, Operator operator, Object rightValue, R rule) { | ||
return Result.success(); | ||
} | ||
|
||
/** | ||
* Returns the name of the function | ||
*/ | ||
default String name() { | ||
return getClass().getSimpleName(); | ||
} | ||
|
||
} |
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.