-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: strict policy definition validation
- Loading branch information
Showing
13 changed files
with
369 additions
and
26 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
42 changes: 42 additions & 0 deletions
42
...eclipse/tractusx/edc/policy/cx/contractreference/ContractReferenceConstraintFunction.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,42 @@ | ||
/* | ||
* Copyright (c) 2024 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) | ||
* | ||
* See the NOTICE file(s) distributed with this work for additional | ||
* information regarding copyright ownership. | ||
* | ||
* 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. | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
* License for the specific language governing permissions and limitations | ||
* under the License. | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package org.eclipse.tractusx.edc.policy.cx.contractreference; | ||
|
||
import org.eclipse.edc.iam.verifiablecredentials.spi.model.VerifiableCredential; | ||
import org.eclipse.edc.participant.spi.ParticipantAgent; | ||
import org.eclipse.edc.participant.spi.ParticipantAgentPolicyContext; | ||
import org.eclipse.edc.policy.engine.spi.AtomicConstraintRuleFunction; | ||
import org.eclipse.edc.policy.engine.spi.PolicyContext; | ||
import org.eclipse.edc.policy.model.Operator; | ||
import org.eclipse.edc.policy.model.Permission; | ||
|
||
|
||
/** | ||
* This constraint function checks that a MembershipCredential is present in a list of {@link VerifiableCredential} | ||
* objects extracted from a {@link ParticipantAgent} which is expected to be present on the {@link PolicyContext}. | ||
*/ | ||
public class ContractReferenceConstraintFunction<C extends ParticipantAgentPolicyContext> implements AtomicConstraintRuleFunction<Permission, C> { | ||
public static final String CONTRACT_REFERENCE = "ContractReference"; | ||
|
||
@Override | ||
public boolean evaluate(Operator operator, Object rightOperand, Permission permission, C c) { | ||
return true; | ||
} | ||
} |
42 changes: 42 additions & 0 deletions
42
...rc/main/java/org/eclipse/tractusx/edc/policy/cx/usage/UsagePurposeConstraintFunction.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,42 @@ | ||
/* | ||
* Copyright (c) 2024 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) | ||
* | ||
* See the NOTICE file(s) distributed with this work for additional | ||
* information regarding copyright ownership. | ||
* | ||
* 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. | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
* License for the specific language governing permissions and limitations | ||
* under the License. | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package org.eclipse.tractusx.edc.policy.cx.usage; | ||
|
||
import org.eclipse.edc.iam.verifiablecredentials.spi.model.VerifiableCredential; | ||
import org.eclipse.edc.participant.spi.ParticipantAgent; | ||
import org.eclipse.edc.participant.spi.ParticipantAgentPolicyContext; | ||
import org.eclipse.edc.policy.engine.spi.AtomicConstraintRuleFunction; | ||
import org.eclipse.edc.policy.engine.spi.PolicyContext; | ||
import org.eclipse.edc.policy.model.Operator; | ||
import org.eclipse.edc.policy.model.Permission; | ||
|
||
|
||
/** | ||
* This constraint function checks that a MembershipCredential is present in a list of {@link VerifiableCredential} | ||
* objects extracted from a {@link ParticipantAgent} which is expected to be present on the {@link PolicyContext}. | ||
*/ | ||
public class UsagePurposeConstraintFunction<C extends ParticipantAgentPolicyContext> implements AtomicConstraintRuleFunction<Permission, C> { | ||
public static final String USAGE_PURPOSE = "UsagePurpose"; | ||
|
||
@Override | ||
public boolean evaluate(Operator operator, Object rightOperand, Permission permission, C c) { | ||
return true; | ||
} | ||
} |
42 changes: 42 additions & 0 deletions
42
...pse/tractusx/edc/policy/cx/contractreference/ContractReferenceConstraintFunctionTest.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,42 @@ | ||
/******************************************************************************** | ||
* Copyright (c) 2024 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) | ||
* | ||
* See the NOTICE file(s) distributed with this work for additional | ||
* information regarding copyright ownership. | ||
* | ||
* 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. | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
* License for the specific language governing permissions and limitations | ||
* under the License. | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
********************************************************************************/ | ||
|
||
package org.eclipse.tractusx.edc.policy.cx.contractreference; | ||
|
||
import org.eclipse.edc.participant.spi.ParticipantAgent; | ||
import org.eclipse.edc.participant.spi.ParticipantAgentPolicyContext; | ||
import org.eclipse.edc.policy.model.Operator; | ||
import org.eclipse.tractusx.edc.policy.cx.TestParticipantAgentPolicyContext; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static org.mockito.Mockito.mock; | ||
|
||
class ContractReferenceConstraintFunctionTest { | ||
|
||
private final ParticipantAgent participantAgent = mock(); | ||
private final ContractReferenceConstraintFunction<ParticipantAgentPolicyContext> function = new ContractReferenceConstraintFunction<>(); | ||
private final ParticipantAgentPolicyContext context = new TestParticipantAgentPolicyContext(participantAgent); | ||
|
||
@Test | ||
void evaluate() { | ||
assertThat(function.evaluate(Operator.EQ, "contractRef", null, context)).isTrue(); | ||
} | ||
|
||
} |
42 changes: 42 additions & 0 deletions
42
...est/java/org/eclipse/tractusx/edc/policy/cx/usage/UsagePurposeConstraintFunctionTest.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,42 @@ | ||
/******************************************************************************** | ||
* Copyright (c) 2024 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) | ||
* | ||
* See the NOTICE file(s) distributed with this work for additional | ||
* information regarding copyright ownership. | ||
* | ||
* 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. | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
* License for the specific language governing permissions and limitations | ||
* under the License. | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
********************************************************************************/ | ||
|
||
package org.eclipse.tractusx.edc.policy.cx.usage; | ||
|
||
import org.eclipse.edc.participant.spi.ParticipantAgent; | ||
import org.eclipse.edc.participant.spi.ParticipantAgentPolicyContext; | ||
import org.eclipse.edc.policy.model.Operator; | ||
import org.eclipse.tractusx.edc.policy.cx.TestParticipantAgentPolicyContext; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static org.mockito.Mockito.mock; | ||
|
||
class UsagePurposeConstraintFunctionTest { | ||
|
||
private final ParticipantAgent participantAgent = mock(); | ||
private final UsagePurposeConstraintFunction<ParticipantAgentPolicyContext> function = new UsagePurposeConstraintFunction<>(); | ||
private final ParticipantAgentPolicyContext context = new TestParticipantAgentPolicyContext(participantAgent); | ||
|
||
@Test | ||
void evaluate() { | ||
assertThat(function.evaluate(Operator.EQ, "usagePurpose", null, context)).isTrue(); | ||
} | ||
|
||
} |
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.