Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New IRS release #179

Merged
merged 25 commits into from
Oct 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
5a3cd87
feat(irs-edc-client): [TRI-1594] Extension of Policy Checker Routine …
ds-ext-abugajewski Sep 24, 2023
7857478
feat(irs-edc-client): [TRI-1594] Extension of Policy Checker Routine …
ds-ext-abugajewski Sep 26, 2023
5e68d41
feat(irs-edc-client): [TRI-1594] Extension of Policy Checker Routine …
ds-ext-abugajewski Sep 26, 2023
0236425
feat(irs-edc-client): [TRI-1594] Extension of Policy Checker Routine …
ds-ext-abugajewski Sep 26, 2023
c8eedef
feat(irs-edc-client): [TRI-1594] Extension of Policy Checker Routine …
ds-ext-abugajewski Sep 26, 2023
72f33d3
feat(irs-edc):[TRI-1594] Refactoring
ds-jhartmann Sep 29, 2023
ab5326b
feat(irs-edc):[TRI-1594] Refactoring
ds-jhartmann Sep 29, 2023
2af563f
feat(testing):[TRI-1594] Update insomnia collection
ds-jhartmann Sep 29, 2023
92dc6fa
feat(impl):[TRI-1666] insomnia collection update
ds-ext-kmassalski Oct 3, 2023
5b34182
feat(impl):[TRI-1666] insomnia collection update
ds-ext-kmassalski Oct 3, 2023
73459c4
Merge pull request #563 from catenax-ng/feature/TRI-1666-insomnia-col…
ds-ext-kmassalski Oct 4, 2023
e7201c8
feat(testing):[TRI-1594] Add additional test for failing policy
ds-jhartmann Oct 4, 2023
14c8546
Merge remote-tracking branch 'origin/main' into feature/TRI-1594_poli…
ds-jhartmann Oct 4, 2023
12c4995
feat(testing):[TRI-1594] Disable JsonValidatorServiceTest due to unex…
ds-jhartmann Oct 4, 2023
4349f3e
feat(testing):[TRI-1594] Disable JsonValidatorServiceTest due to unex…
ds-jhartmann Oct 4, 2023
4f18e95
feat(testing):[TRI-1594] Disable JsonValidatorServiceTest due to unex…
ds-jhartmann Oct 4, 2023
73150b7
Merge pull request #550 from catenax-ng/feature/TRI-1594_policy_store…
ds-jhartmann Oct 4, 2023
ad1f648
Merge pull request #564 from eclipse-tractusx/main
ds-ext-kmassalski Oct 5, 2023
874ab6b
feat(impl):[TRI-1678] fix jsonschema validation
ds-ext-kmassalski Oct 5, 2023
4388970
feat(impl):[TRI-1664] fix deps
ds-ext-kmassalski Oct 5, 2023
2dfe2ff
Merge pull request #566 from catenax-ng/feature/TRI-1678-fix-jsonsche…
ds-ext-kmassalski Oct 5, 2023
b7d3ec4
chore(doc): Update CHANGELOG.md
ds-jhartmann Oct 5, 2023
c1b2686
Merge pull request #567 from catenax-ng/fix/hotfix-3.5.1
ds-ext-kmassalski Oct 5, 2023
d0809d2
chore(release): Prepare release for Helm version 6.7.2
ds-jhartmann Oct 5, 2023
8ca2569
Merge pull request #568 from catenax-ng/chore/prepare-helm-release-6.7.2
ds-jhartmann Oct 5, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [3.5.1] - 2023-10-05
### Fixed
- Fix json schema validation

## [3.5.0] - 2023-09-27
### Changed
- IRS now makes use of the value `dspEndpoint` in `subprotocolBody` of the Asset Administration Shell to request submodel data directly.
Expand Down Expand Up @@ -350,7 +354,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Unresolved
- **Select Aspects you need** You are able to select the needed aspects for which you want to collect the correct endpoint information.

[Unreleased]: https://github.com/eclipse-tractusx/item-relationship-service/compare/3.5.0...HEAD
[Unreleased]: https://github.com/eclipse-tractusx/item-relationship-service/compare/3.5.1...HEAD
[3.5.1]: https://github.com/eclipse-tractusx/item-relationship-service/compare/3.5.0...3.5.1
[3.5.0]: https://github.com/eclipse-tractusx/item-relationship-service/compare/3.4.1...3.5.0
[3.4.1]: https://github.com/eclipse-tractusx/item-relationship-service/compare/3.4.0...3.4.1
[3.4.0]: https://github.com/eclipse-tractusx/item-relationship-service/compare/3.3.5...3.4.0
Expand Down
6 changes: 3 additions & 3 deletions DEPENDENCIES
Original file line number Diff line number Diff line change
Expand Up @@ -198,9 +198,9 @@ maven/mavencentral/net.java.dev.jna/jna/5.8.0, Apache-2.0 OR LGPL-2.1-or-later,
maven/mavencentral/net.javacrumbs.json-unit/json-unit-assertj/2.36.0, Apache-2.0, approved, clearlydefined
maven/mavencentral/net.javacrumbs.json-unit/json-unit-core/2.36.0, Apache-2.0, approved, clearlydefined
maven/mavencentral/net.javacrumbs.json-unit/json-unit-json-path/2.36.0, Apache-2.0, approved, clearlydefined
maven/mavencentral/net.jimblackler.jsonschemafriend/core/0.11.4, Apache-2.0, approved, #3269
maven/mavencentral/net.jimblackler.jsonschemafriend/extra/0.11.4, Apache-2.0, approved, #3270
maven/mavencentral/net.jimblackler/jsonschemafriend/0.11.4, Apache-2.0, approved, #3271
maven/mavencentral/net.jimblackler.jsonschemafriend/core/0.12.0, , restricted, clearlydefined
maven/mavencentral/net.jimblackler.jsonschemafriend/extra/0.12.0, , restricted, clearlydefined
maven/mavencentral/net.jimblackler/jsonschemafriend/0.12.0, , restricted, clearlydefined
maven/mavencentral/net.jodah/typetools/0.6.3, Apache-2.0, approved, clearlydefined
maven/mavencentral/net.minidev/accessors-smart/2.4.11, Apache-2.0, approved, #7515
maven/mavencentral/net.minidev/accessors-smart/2.4.9, Apache-2.0, approved, #7515
Expand Down
4 changes: 4 additions & 0 deletions charts/irs-helm/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [6.7.2] - 2023-10-05
### Changed
- Update IRS version to 3.5.1

## [6.7.1] - 2023-09-29
### Changed
- Added toString template for `edc.controlplane.apikey.secret`
Expand Down
4 changes: 2 additions & 2 deletions charts/irs-helm/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,12 @@ type: application
# This is the chart version. This version number should be incremented each time you make changes
# to the chart and its templates, including the app version.
# Versions are expected to follow Semantic Versioning (https://semver.org/)
version: 6.7.1
version: 6.7.2
# This is the version number of the application being deployed. This version number should be
# incremented each time you make changes to the application. Versions are not expected to
# follow Semantic Versioning. They should reflect the version the application is using.
# It is recommended to use it with quotes.
appVersion: "3.5.0"
appVersion: "3.5.1"
dependencies:
- name: common
repository: https://charts.bitnami.com/bitnami
Expand Down
2 changes: 1 addition & 1 deletion irs-api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@
<dependency>
<groupId>net.jimblackler</groupId>
<artifactId>jsonschemafriend</artifactId>
<version>0.11.4</version>
<version>0.12.0</version>
<exclusions>
<exclusion>
<groupId>org.jsoup</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
*/
public class UsagePolicyException extends EdcClientException {
public UsagePolicyException(final String itemId) {
super("Consumption of asset '" + itemId + "' is not permitted as the required catalog offer policies do not comply with defined IRS policies.");
super("Consumption of asset '" + itemId
+ "' is not permitted as the required catalog offer policies do not comply with defined IRS policies.");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@
/**
* A policy accepted for negotiation.
*
* @param policyId the ID of the policy
* @param policy policy with permissions
Dismissed Show dismissed Hide dismissed
* @param validUntil the timestamp after which the policy will no longer be accepted
*/
public record AcceptedPolicy(String policyId, OffsetDateTime validUntil) {
public record AcceptedPolicy(Policy policy, OffsetDateTime validUntil) {
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
*
* SPDX-License-Identifier: Apache-2.0
********************************************************************************/
package org.eclipse.tractusx.irs.policystore.models;
package org.eclipse.tractusx.irs.edc.client.policy;

import java.util.List;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
/********************************************************************************
* Copyright (c) 2021,2022,2023
* 2022: ZF Friedrichshafen AG
* 2022: ISTOS GmbH
* 2022,2023: Bayerische Motoren Werke Aktiengesellschaft (BMW AG)
* 2022,2023: BOSCH AG
* Copyright (c) 2021,2022,2023 Contributors to the Eclipse Foundation
*
* 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.irs.edc.client.policy;

import java.util.Collection;
import java.util.List;

import lombok.extern.slf4j.Slf4j;
import org.eclipse.edc.policy.model.AndConstraint;
import org.eclipse.edc.policy.model.AtomicConstraint;
import org.eclipse.edc.policy.model.Constraint;
import org.eclipse.edc.policy.model.Operator;
import org.eclipse.edc.policy.model.OrConstraint;
import org.springframework.stereotype.Service;

/**
* Check and validate Constraint from Policy in Catalog
* fetch from EDC providers against accepted Policies.
*/
@Slf4j
@Service
public class ConstraintCheckerService {

public boolean hasAllConstraint(final Policy acceptedPolicy, final List<Constraint> constraints) {
final List<Constraints> acceptedConstraintsList = acceptedPolicy.getPermissions()
.stream()
.map(Permission::getConstraints)
.flatMap(Collection::stream)
.toList();

return constraints.stream().allMatch(constraint -> isValidOnList(constraint, acceptedConstraintsList));
}

private boolean isValidOnList(final Constraint constraint, final List<Constraints> acceptedConstraintsList) {
return acceptedConstraintsList.stream()
.anyMatch(acceptedConstraints -> isSameAs(constraint, acceptedConstraints));
}

private boolean isSameAs(final Constraint constraint, final Constraints acceptedConstraints) {
if (constraint instanceof AtomicConstraint atomicConstraint) {
return acceptedConstraints.getOr().stream().anyMatch(p -> isSameAs(atomicConstraint, p))
|| acceptedConstraints.getAnd().stream().anyMatch(p -> isSameAs(atomicConstraint, p));
}
if (constraint instanceof AndConstraint andConstraint) {
return andConstraint.getConstraints()
.stream()
.allMatch(constr -> isInList(constr, acceptedConstraints.getAnd()));
}
if (constraint instanceof OrConstraint orConstraint) {
return orConstraint.getConstraints()
.stream()
.anyMatch(constr -> isInList(constr, acceptedConstraints.getOr()));
}
return false;
}

private boolean isInList(final Constraint constraint,
final List<org.eclipse.tractusx.irs.edc.client.policy.Constraint> acceptedConstraints) {
if (constraint instanceof AtomicConstraint atomicConstraint) {
return acceptedConstraints.stream().anyMatch(ac -> isSameAs(atomicConstraint, ac));
} else {
return false;
}
}

private boolean isSameAs(final AtomicConstraint atomicConstraint,
final org.eclipse.tractusx.irs.edc.client.policy.Constraint acceptedConstraint) {
return AtomicConstraintValidator.builder()
.atomicConstraint(atomicConstraint)
.leftExpressionValue(acceptedConstraint.getLeftOperand())
.rightExpressionValue(
acceptedConstraint.getRightOperand().stream().findFirst().orElse(""))
.expectedOperator(Operator.valueOf(acceptedConstraint.getOperator().name()))
.build()
.isValid();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
*
* SPDX-License-Identifier: Apache-2.0
********************************************************************************/
package org.eclipse.tractusx.irs.policystore.models;
package org.eclipse.tractusx.irs.edc.client.policy;

import java.util.List;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
*
* SPDX-License-Identifier: Apache-2.0
********************************************************************************/
package org.eclipse.tractusx.irs.policystore.models;
package org.eclipse.tractusx.irs.edc.client.policy;

import java.util.NoSuchElementException;
import java.util.stream.Stream;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
*
* SPDX-License-Identifier: Apache-2.0
********************************************************************************/
package org.eclipse.tractusx.irs.policystore.models;
package org.eclipse.tractusx.irs.edc.client.policy;

import java.util.List;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
*
* SPDX-License-Identifier: Apache-2.0
********************************************************************************/
package org.eclipse.tractusx.irs.policystore.models;
package org.eclipse.tractusx.irs.edc.client.policy;

import java.time.OffsetDateTime;
import java.util.List;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,22 +24,13 @@
package org.eclipse.tractusx.irs.edc.client.policy;

import java.time.OffsetDateTime;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Stream;

import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.eclipse.edc.policy.model.AndConstraint;
import org.eclipse.edc.policy.model.AtomicConstraint;
import org.eclipse.edc.policy.model.Constraint;
import org.eclipse.edc.policy.model.Operator;
import org.eclipse.edc.policy.model.OrConstraint;
import org.eclipse.edc.policy.model.Permission;
import org.eclipse.edc.policy.model.Policy;
import org.eclipse.edc.policy.model.XoneConstraint;
import org.eclipse.tractusx.irs.data.StringMapper;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.web.util.UriUtils;

Expand All @@ -52,93 +43,35 @@
public class PolicyCheckerService {

private final AcceptedPoliciesProvider policyStore;
@Value("${irs-edc-client.catalog.policies.acceptedRightOperands:active}")
private final List<String> acceptedRightOperands;
@Value("${irs-edc-client.catalog.policies.acceptedLeftOperands:PURPOSE}")
private final List<String> acceptedLeftOperands;
private final ConstraintCheckerService constraintCheckerService;

public boolean isValid(final Policy policy) {
final List<PolicyDefinition> policyList = getAllowedPolicies();
log.info("Checking policy {} against allowed policies: {}", StringMapper.mapToString(policy),
String.join(",", policyList.stream().map(PolicyDefinition::getRightExpressionValue).toList()));
if (getValidStoredPolicyIds().contains("*")) {
return true;
}
return policy.getPermissions().stream().allMatch(permission -> isValid(permission, policyList));
}

private List<PolicyDefinition> getAllowedPolicies() {
final List<String> policyIds = getValidStoredPolicyIds();
final List<PolicyDefinition> allowedPolicies = new ArrayList<>();
acceptedRightOperands.forEach(rightOperand -> allowedPolicies.addAll(
policyIds.stream().map(policy -> createPolicy(policy, rightOperand)).toList()));
acceptedLeftOperands.forEach(leftOperand -> allowedPolicies.addAll(
policyIds.stream().map(policy -> createPolicy(leftOperand, policy)).toList()));
return policy.getPermissions().stream().allMatch(permission -> isValid(permission, getValidStoredPolicies()));
}

return allowedPolicies;
private boolean isValid(final Permission permission, final List<AcceptedPolicy> validStoredPolicies) {
return validStoredPolicies.stream().anyMatch(acceptedPolicy ->
constraintCheckerService.hasAllConstraint(acceptedPolicy.policy(), permission.getConstraints()));
}

private List<String> getValidStoredPolicyIds() {
return policyStore.getAcceptedPolicies()
.stream()
.filter(p -> p.validUntil().isAfter(OffsetDateTime.now()))
.map(AcceptedPolicy::policyId)
.map(acceptedPolicy -> acceptedPolicy.policy().getPolicyId())
.flatMap(this::addEncodedVersion)
.toList();
}

private boolean isValid(final Permission permission, final List<PolicyDefinition> policyDefinitions) {
final boolean permissionTypesMatch = policyDefinitions.stream()
.allMatch(
policyDefinition -> policyDefinition.getPermissionActionType()
.equals(permission.getAction()
.getType()));
final boolean constraintsMatch = permission.getConstraints()
.stream()
.allMatch(constraint -> isValid(constraint, policyDefinitions));
return permissionTypesMatch && constraintsMatch;
}

private boolean isValid(final Constraint constraint, final List<PolicyDefinition> policyDefinitions) {
if (constraint instanceof AtomicConstraint atomicConstraint) {
return validateAtomicConstraint(atomicConstraint, policyDefinitions);
} else if (constraint instanceof AndConstraint andConstraint) {
return andConstraint.getConstraints().stream().allMatch(constr -> isValid(constr, policyDefinitions));
} else if (constraint instanceof OrConstraint orConstraint) {
return orConstraint.getConstraints().stream().anyMatch(constr -> isValid(constr, policyDefinitions));
} else if (constraint instanceof XoneConstraint xoneConstraint) {
return xoneConstraint.getConstraints().stream().filter(constr -> isValid(constr, policyDefinitions)).count()
== 1;
}
return false;
}

private boolean validateAtomicConstraint(final AtomicConstraint atomicConstraint,
final PolicyDefinition policyDefinition) {
return AtomicConstraintValidator.builder()
.atomicConstraint(atomicConstraint)
.leftExpressionValue(policyDefinition.getLeftExpressionValue())
.rightExpressionValue(policyDefinition.getRightExpressionValue())
.expectedOperator(Operator.valueOf(policyDefinition.getConstraintOperator()))
.build()
.isValid();
}

private boolean validateAtomicConstraint(final AtomicConstraint atomicConstraint,
final List<PolicyDefinition> policyDefinitions) {
return policyDefinitions.stream()
.anyMatch(policyDefinition -> validateAtomicConstraint(atomicConstraint,
policyDefinition));
}

private PolicyDefinition createPolicy(final String leftExpression, final String rightExpression) {
return PolicyDefinition.builder()
.permissionActionType("USE")
.constraintType("AtomicConstraint")
.leftExpressionValue(leftExpression)
.rightExpressionValue(rightExpression)
.constraintOperator("EQ")
.build();
private List<AcceptedPolicy> getValidStoredPolicies() {
return policyStore.getAcceptedPolicies()
.stream()
.filter(p -> p.validUntil().isAfter(OffsetDateTime.now()))
.toList();
}

private Stream<String> addEncodedVersion(final String original) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
*
* SPDX-License-Identifier: Apache-2.0
********************************************************************************/
package org.eclipse.tractusx.irs.policystore.models;
package org.eclipse.tractusx.irs.edc.client.policy;

/**
* A PolicyType object use in Permission
Expand Down
Loading
Loading