From eedb7668d63dc01739949b071d97bc3e6bf43a47 Mon Sep 17 00:00:00 2001 From: Matthias Fischer Date: Wed, 17 Jul 2024 19:03:41 +0200 Subject: [PATCH 01/11] feat(impl): [#542] add a mapFromString method with TypeReference to StringMapper reason: this allows type-safe mapping to List --- .../tractusx/irs/util/StringMapperTest.java | 91 ++++++++++++++++++- .../tractusx/irs/data/StringMapper.java | 9 ++ 2 files changed, 98 insertions(+), 2 deletions(-) diff --git a/irs-api/src/test/java/org/eclipse/tractusx/irs/util/StringMapperTest.java b/irs-api/src/test/java/org/eclipse/tractusx/irs/util/StringMapperTest.java index 4120d778cb..62028a5d30 100644 --- a/irs-api/src/test/java/org/eclipse/tractusx/irs/util/StringMapperTest.java +++ b/irs-api/src/test/java/org/eclipse/tractusx/irs/util/StringMapperTest.java @@ -26,10 +26,20 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; +import java.time.OffsetDateTime; +import java.util.List; + +import com.fasterxml.jackson.core.type.TypeReference; import org.eclipse.tractusx.irs.component.Bpn; import org.eclipse.tractusx.irs.component.Description; import org.eclipse.tractusx.irs.data.JsonParseException; import org.eclipse.tractusx.irs.data.StringMapper; +import org.eclipse.tractusx.irs.edc.client.policy.Constraint; +import org.eclipse.tractusx.irs.edc.client.policy.Constraints; +import org.eclipse.tractusx.irs.edc.client.policy.OperatorType; +import org.eclipse.tractusx.irs.edc.client.policy.Permission; +import org.eclipse.tractusx.irs.edc.client.policy.Policy; +import org.eclipse.tractusx.irs.edc.client.policy.PolicyType; import org.junit.jupiter.api.Test; class StringMapperTest { @@ -44,8 +54,7 @@ void mapToString() { @Test void shouldThrowParseExceptionWhenMappingToString() { final var object = new Object(); - assertThatThrownBy(() -> StringMapper.mapToString(object)).isInstanceOf( - JsonParseException.class); + assertThatThrownBy(() -> StringMapper.mapToString(object)).isInstanceOf(JsonParseException.class); } @Test @@ -61,4 +70,82 @@ void shouldThrowParseExceptionWhenMappingFromString() { assertThatThrownBy(() -> StringMapper.mapFromString("test", Description.class)).isInstanceOf( JsonParseException.class); } + + @Test + void shouldMapFromStringUsingTypeReference() { + + // ARRANGE + final TypeReference> listOfPoliciesType = new TypeReference<>() { + }; + + final String originalJson = """ + [{ + "policyId": "default-trace-policy", + "createdOn": "2024-07-17T16:15:14.12345678Z", + "validUntil": "9999-01-01T00:00:00.00000000Z", + "permissions": [ + { + "action": "use", + "constraint": { + "and": [ + { + "leftOperand": "https://w3id.org/catenax/policy/FrameworkAgreement", + "operator": { + "@id": "eq" + }, + "rightOperand": "traceability:1.0" + }, + { + "leftOperand": "https://w3id.org/catenax/policy/UsagePurpose", + "operator": { + "@id": "eq" + }, + "rightOperand": "cx.core.industrycore:1" + } + ] + } + } + ] + }] + """; + + // ACT + // convert back andConstraints forth to facilitate comparison + final List listOfPolicies = StringMapper.mapFromString(originalJson, listOfPoliciesType); + final String backToString = StringMapper.mapToString(listOfPolicies); + final List backToObj = StringMapper.mapFromString(backToString, listOfPoliciesType); + + // ASSERT + { + assertThat(listOfPolicies).hasSize(1); + assertThat(backToObj).hasSize(1); + assertThat(backToObj).usingRecursiveComparison().isEqualTo(listOfPolicies); + + final Policy policy = listOfPolicies.get(0); + assertThat(policy.getPolicyId()).isEqualTo("default-trace-policy"); + assertThat(policy.getValidUntil()).isEqualTo(OffsetDateTime.parse("9999-01-01T00:00:00.00000000Z")); + assertThat(policy.getCreatedOn()).isEqualTo(OffsetDateTime.parse("2024-07-17T16:15:14.12345678Z")); + assertThat(policy.getPermissions()).hasSize(1); + + final Permission permission = policy.getPermissions().get(0); + assertThat(permission.getAction()).isEqualTo(PolicyType.USE); + + final Constraints constraints = permission.getConstraint(); + final List andConstraints = constraints.getAnd(); + assertThat(andConstraints).hasSize(2); + { + final Constraint constraint = andConstraints.get(0); + assertThat(constraint.getLeftOperand()).isEqualTo("https://w3id.org/catenax/policy/FrameworkAgreement"); + assertThat(constraint.getOperator().getOperatorType()).isEqualTo(OperatorType.EQ); + assertThat(constraint.getRightOperand()).isEqualTo("traceability:1.0"); + } + { + final Constraint constraint = andConstraints.get(1); + assertThat(constraint.getLeftOperand()).isEqualTo("https://w3id.org/catenax/policy/UsagePurpose"); + assertThat(constraint.getOperator().getOperatorType()).isEqualTo(OperatorType.EQ); + assertThat(constraint.getRightOperand()).isEqualTo("cx.core.industrycore:1"); + } + } + } + } \ No newline at end of file diff --git a/irs-models/src/main/java/org/eclipse/tractusx/irs/data/StringMapper.java b/irs-models/src/main/java/org/eclipse/tractusx/irs/data/StringMapper.java index 9f60be9b4c..65e2f2e19f 100644 --- a/irs-models/src/main/java/org/eclipse/tractusx/irs/data/StringMapper.java +++ b/irs-models/src/main/java/org/eclipse/tractusx/irs/data/StringMapper.java @@ -24,6 +24,7 @@ package org.eclipse.tractusx.irs.data; import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.databind.DeserializationFeature; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.SerializationFeature; @@ -64,4 +65,12 @@ public static T mapFromString(final String value, final Class clazz) { } } + public static T mapFromString(final String value, final TypeReference typeReference) { + try { + return MAPPER.readValue(value, typeReference); + } catch (final JsonProcessingException e) { + throw new JsonParseException(e); + } + } + } From 749a52acb09a9baf8e99a48df64eb067c7a9f935 Mon Sep 17 00:00:00 2001 From: Matthias Fischer Date: Thu, 18 Jul 2024 03:03:35 +0200 Subject: [PATCH 02/11] feat(impl): [#542] add a mapFromBase64String method with TypeReference to StringMapper --- .../eclipse/tractusx/irs/util/StringMapperTest.java | 10 +++++++--- .../org/eclipse/tractusx/irs/data/StringMapper.java | 7 +++++++ 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/irs-api/src/test/java/org/eclipse/tractusx/irs/util/StringMapperTest.java b/irs-api/src/test/java/org/eclipse/tractusx/irs/util/StringMapperTest.java index 62028a5d30..7ee83c63a0 100644 --- a/irs-api/src/test/java/org/eclipse/tractusx/irs/util/StringMapperTest.java +++ b/irs-api/src/test/java/org/eclipse/tractusx/irs/util/StringMapperTest.java @@ -26,7 +26,9 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; +import java.nio.charset.StandardCharsets; import java.time.OffsetDateTime; +import java.util.Base64; import java.util.List; import com.fasterxml.jackson.core.type.TypeReference; @@ -72,13 +74,13 @@ void shouldThrowParseExceptionWhenMappingFromString() { } @Test - void shouldMapFromStringUsingTypeReference() { + void shouldMapFromBase64StringUsingTypeReference() { // ARRANGE final TypeReference> listOfPoliciesType = new TypeReference<>() { }; - final String originalJson = """ + final String originalJsonStr = """ [{ "policyId": "default-trace-policy", "createdOn": "2024-07-17T16:15:14.12345678Z", @@ -108,10 +110,12 @@ void shouldMapFromStringUsingTypeReference() { ] }] """; + final String originalJsonBase64 = new String( + Base64.getEncoder().encode(originalJsonStr.getBytes(StandardCharsets.UTF_8))); // ACT // convert back andConstraints forth to facilitate comparison - final List listOfPolicies = StringMapper.mapFromString(originalJson, listOfPoliciesType); + final List listOfPolicies = StringMapper.mapFromBase64String(originalJsonBase64, listOfPoliciesType); final String backToString = StringMapper.mapToString(listOfPolicies); final List backToObj = StringMapper.mapFromString(backToString, listOfPoliciesType); diff --git a/irs-models/src/main/java/org/eclipse/tractusx/irs/data/StringMapper.java b/irs-models/src/main/java/org/eclipse/tractusx/irs/data/StringMapper.java index 65e2f2e19f..491a2d1179 100644 --- a/irs-models/src/main/java/org/eclipse/tractusx/irs/data/StringMapper.java +++ b/irs-models/src/main/java/org/eclipse/tractusx/irs/data/StringMapper.java @@ -23,6 +23,8 @@ ********************************************************************************/ package org.eclipse.tractusx.irs.data; +import java.util.Base64; + import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.databind.DeserializationFeature; @@ -33,6 +35,7 @@ import lombok.AccessLevel; import lombok.NoArgsConstructor; import lombok.extern.slf4j.Slf4j; +import org.apache.commons.lang3.StringUtils; /** * Maps objects to strings and vice-versa. @@ -65,6 +68,10 @@ public static T mapFromString(final String value, final Class clazz) { } } + public static T mapFromBase64String(final String value, final TypeReference typeReference) { + return mapFromString(new String(Base64.getDecoder().decode(StringUtils.trim(value))), typeReference); + } + public static T mapFromString(final String value, final TypeReference typeReference) { try { return MAPPER.readValue(value, typeReference); From 88abff19ca515385d4dbded9378bb985d07cb325 Mon Sep 17 00:00:00 2001 From: Matthias Fischer Date: Thu, 18 Jul 2024 03:07:12 +0200 Subject: [PATCH 03/11] feat(impl): [#542] add acceptedPoliciesJson to DefaultAcceptedPoliciesConfig --- .../policystore/config/DefaultAcceptedPoliciesConfig.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/irs-policy-store/src/main/java/org/eclipse/tractusx/irs/policystore/config/DefaultAcceptedPoliciesConfig.java b/irs-policy-store/src/main/java/org/eclipse/tractusx/irs/policystore/config/DefaultAcceptedPoliciesConfig.java index 68b69ee6c8..7e5a70db23 100644 --- a/irs-policy-store/src/main/java/org/eclipse/tractusx/irs/policystore/config/DefaultAcceptedPoliciesConfig.java +++ b/irs-policy-store/src/main/java/org/eclipse/tractusx/irs/policystore/config/DefaultAcceptedPoliciesConfig.java @@ -39,6 +39,11 @@ public class DefaultAcceptedPoliciesConfig { private List acceptedPolicies; + /** + * Accepted policies as JSON with Base64 encoding + */ + private String acceptedPoliciesJson; + /** * Accepted Policy for */ From e519a720b09883b8cd1de3769615559d93549806 Mon Sep 17 00:00:00 2001 From: Matthias Fischer Date: Thu, 18 Jul 2024 03:07:56 +0200 Subject: [PATCH 04/11] feat(impl): [#542] deprecate old field --- .../irs/policystore/config/DefaultAcceptedPoliciesConfig.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/irs-policy-store/src/main/java/org/eclipse/tractusx/irs/policystore/config/DefaultAcceptedPoliciesConfig.java b/irs-policy-store/src/main/java/org/eclipse/tractusx/irs/policystore/config/DefaultAcceptedPoliciesConfig.java index 7e5a70db23..71dc9c61ad 100644 --- a/irs-policy-store/src/main/java/org/eclipse/tractusx/irs/policystore/config/DefaultAcceptedPoliciesConfig.java +++ b/irs-policy-store/src/main/java/org/eclipse/tractusx/irs/policystore/config/DefaultAcceptedPoliciesConfig.java @@ -37,6 +37,8 @@ @ConfigurationProperties(prefix = "irs-edc-client.catalog") @Data public class DefaultAcceptedPoliciesConfig { + + @Deprecated private List acceptedPolicies; /** From cf0f2b37df90a0807575d6f2df58fd6ee35611c9 Mon Sep 17 00:00:00 2001 From: Matthias Fischer Date: Thu, 18 Jul 2024 03:11:03 +0200 Subject: [PATCH 05/11] feat(impl): [#542] init accepted policies either from old yaml config or from Base64 encoded JSON --- .../services/PolicyStoreService.java | 31 ++++++++++++++++--- 1 file changed, 26 insertions(+), 5 deletions(-) diff --git a/irs-policy-store/src/main/java/org/eclipse/tractusx/irs/policystore/services/PolicyStoreService.java b/irs-policy-store/src/main/java/org/eclipse/tractusx/irs/policystore/services/PolicyStoreService.java index d7dbe61d14..dbf7ecc37b 100644 --- a/irs-policy-store/src/main/java/org/eclipse/tractusx/irs/policystore/services/PolicyStoreService.java +++ b/irs-policy-store/src/main/java/org/eclipse/tractusx/irs/policystore/services/PolicyStoreService.java @@ -38,9 +38,12 @@ import java.util.stream.Collectors; import java.util.stream.Stream; +import com.fasterxml.jackson.core.type.TypeReference; import jakarta.json.JsonObject; import lombok.extern.slf4j.Slf4j; +import org.apache.commons.collections.CollectionUtils; import org.apache.commons.lang3.StringUtils; +import org.eclipse.tractusx.irs.data.StringMapper; import org.eclipse.tractusx.irs.edc.client.policy.AcceptedPoliciesProvider; import org.eclipse.tractusx.irs.edc.client.policy.AcceptedPolicy; import org.eclipse.tractusx.irs.edc.client.policy.Constraint; @@ -300,12 +303,25 @@ private AcceptedPolicy toAcceptedPolicy(final Policy policy) { private List createDefaultPolicyFromConfig( final DefaultAcceptedPoliciesConfig defaultAcceptedPoliciesConfig) { + // Implementation prior to issue #542, retained for backward compatibility; may be removed in the future + if (CollectionUtils.isNotEmpty(defaultAcceptedPoliciesConfig.getAcceptedPolicies())) { + final List acceptedPolicies = defaultAcceptedPoliciesConfig.getAcceptedPolicies(); + return createDefaultPolicyFromAcceptedPoliciesYaml(acceptedPolicies); + } + // New implementation from issue #542 using JSON compliant with the ODRL schema + else { + final String policiesString = defaultAcceptedPoliciesConfig.getAcceptedPoliciesJson(); + return createPoliciesFromConfigJsonString(policiesString); + } + } + + @Deprecated + private List createDefaultPolicyFromAcceptedPoliciesYaml( + final List acceptedPolicies) { + final List constraints = new ArrayList<>(); - defaultAcceptedPoliciesConfig.getAcceptedPolicies() - .forEach(acceptedPolicy -> constraints.add( - new Constraint(acceptedPolicy.getLeftOperand(), - new Operator(OperatorType.fromValue(acceptedPolicy.getOperator())), - acceptedPolicy.getRightOperand()))); + acceptedPolicies.forEach(acceptedPolicy -> constraints.add(new Constraint(acceptedPolicy.getLeftOperand(), + new Operator(OperatorType.fromValue(acceptedPolicy.getOperator())), acceptedPolicy.getRightOperand()))); final OffsetDateTime now = OffsetDateTime.now(clock); return List.of(Policy.builder() @@ -319,4 +335,9 @@ private List createDefaultPolicyFromConfig( .build()); } + public static List createPoliciesFromConfigJsonString(final String policiesString) { + return StringMapper.mapFromBase64String(policiesString, new TypeReference<>() { + }); + } + } From eeb5db1aff0aa3d2d6692408e3b4a1e2bba040b9 Mon Sep 17 00:00:00 2001 From: Matthias Fischer Date: Thu, 18 Jul 2024 12:23:18 +0200 Subject: [PATCH 06/11] feat(impl): [#542] change default policies config to JSON, cleanup old code, update documentation and changelog --- CHANGELOG.md | 3 ++ .../configmap-spring-app-config.yaml | 7 +-- charts/item-relationship-service/values.yaml | 44 +++++++++++---- irs-api/src/main/resources/application.yml | 15 +++--- .../config/DefaultAcceptedPoliciesConfig.java | 9 +--- .../services/PolicyStoreService.java | 54 +++---------------- irs-registry-client/README.md | 19 +++---- 7 files changed, 61 insertions(+), 90 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0769fa81a5..fef5c9a7b1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,9 @@ _**For better traceability add the corresponding GitHub issue number in each cha ## [Unreleased] +### Changed +- Default policies are now configured using JSON in accordance with the ODRL schema. #542 + ## [5.3.0] - 2024-07-15 ### Added diff --git a/charts/item-relationship-service/templates/configmap-spring-app-config.yaml b/charts/item-relationship-service/templates/configmap-spring-app-config.yaml index 92b09f6f6b..aefab9cf42 100644 --- a/charts/item-relationship-service/templates/configmap-spring-app-config.yaml +++ b/charts/item-relationship-service/templates/configmap-spring-app-config.yaml @@ -118,12 +118,7 @@ data: submodel-suffix: {{ tpl (.Values.edc.submodel.suffix | default "/$value") . | quote }} catalog: - acceptedPolicies: - {{- range .Values.edc.catalog.acceptedPolicies}} - - leftOperand: {{ .leftOperand | quote }} - operator: {{ .operator | quote }} - rightOperand: {{ .rightOperand | quote }} - {{- end }} + acceptedPolicies: {{ .Values.edc.catalog.acceptedPolicies | trim | b64enc | quote }} discoveryFinderClient: cacheTTL: {{ .Values.edc.discoveryFinderClient.cacheTTL | quote }} connectorEndpointService: diff --git a/charts/item-relationship-service/values.yaml b/charts/item-relationship-service/values.yaml index 4d828a8670..b3ddd4b5a7 100644 --- a/charts/item-relationship-service/values.yaml +++ b/charts/item-relationship-service/values.yaml @@ -187,15 +187,41 @@ edc: urnprefix: /urn suffix: /$value catalog: - # IRS will only negotiate contracts for offers with a policy as defined in the allowedNames list. - # If a requested asset does not provide one of these policies, a tombstone will be created and this node will not be processed. - acceptedPolicies: - - leftOperand: "cx-policy:FrameworkAgreement" - operator: "eq" - rightOperand: "traceability:1.0" - - leftOperand: "cx-policy:UsagePurpose" - operator: "eq" - rightOperand: "cx.core.industrycore:1" + # IRS will only negotiate contracts for offers with a policy as defined in the Policy Store. + # The following configuration value allows the definition of default policies to be used + # if no policy has been defined via the Policy Store API. + # If the policy check fails, a tombstone will be created and this node will not be processed. + # Configure the default policies as JSON array using multiline string here. + acceptedPolicies: > + [{ + "policyId": "default-trace-policy", + "createdOn": "2024-07-17T16:15:14.12345678Z", + "validUntil": "9999-01-01T00:00:00.00000000Z", + "permissions": [ + { + "action": "use", + "constraint": { + "and": [ + { + "leftOperand": "https://w3id.org/catenax/policy/FrameworkAgreement", + "operator": { + "@id": "eq" + }, + "rightOperand": "traceability:1.0" + }, + { + "leftOperand": "https://w3id.org/catenax/policy/UsagePurpose", + "operator": { + "@id": "eq" + }, + "rightOperand": "cx.core.industrycore:1" + } + ] + } + } + ] + }] + discoveryFinderClient: cacheTTL: PT24H # Time to live for DiscoveryFinderClient for findDiscoveryEndpoints method cache connectorEndpointService: diff --git a/irs-api/src/main/resources/application.yml b/irs-api/src/main/resources/application.yml index 93b9a76f7a..2f27428f42 100644 --- a/irs-api/src/main/resources/application.yml +++ b/irs-api/src/main/resources/application.yml @@ -154,15 +154,12 @@ irs-edc-client: connect: PT90S # HTTP connect timeout for the submodel client catalog: - # IRS will only negotiate contracts for offers with a policy as defined in the acceptedPolicies list. - # If a requested asset does not provide one of these policies, a tombstone will be created and this node will not be processed. - acceptedPolicies: - - leftOperand: "cx-policy:FrameworkAgreement" - operator: "eq" - rightOperand: "traceability:1.0" - - leftOperand: "cx-policy:UsagePurpose" - operator: "eq" - rightOperand: "cx.core.industrycore:1" + # IRS will only negotiate contracts for offers with a policy as defined in the Policy Store. + # The following configuration value allows the definition of default policies to be used + # if no policy has been defined via the Policy Store API. + # If the policy check fails, a tombstone will be created and this node will not be processed. + # The value must be Base64 encoded here. + acceptedPolicies: "W3sKICAgICJwb2xpY3lJZCI6ICJkZWZhdWx0LXRyYWNlLXBvbGljeSIsCiAgICAiY3JlYXRlZE9uIjogIjIwMjQtMDctMTdUMTY6MTU6MTQuMTIzNDU2NzhaIiwKICAgICJ2YWxpZFVudGlsIjogIjk5OTktMDEtMDFUMDA6MDA6MDAuMDAwMDAwMDBaIiwKICAgICJwZXJtaXNzaW9ucyI6IFsKICAgICAgICB7CiAgICAgICAgICAgICJhY3Rpb24iOiAidXNlIiwKICAgICAgICAgICAgImNvbnN0cmFpbnQiOiB7CiAgICAgICAgICAgICAgICAiYW5kIjogWwogICAgICAgICAgICAgICAgICAgIHsKICAgICAgICAgICAgICAgICAgICAgICAgImxlZnRPcGVyYW5kIjogImh0dHBzOi8vdzNpZC5vcmcvY2F0ZW5heC9wb2xpY3kvRnJhbWV3b3JrQWdyZWVtZW50IiwKICAgICAgICAgICAgICAgICAgICAgICAgIm9wZXJhdG9yIjogewogICAgICAgICAgICAgICAgICAgICAgICAgICAgIkBpZCI6ICJlcSIKICAgICAgICAgICAgICAgICAgICAgICAgfSwKICAgICAgICAgICAgICAgICAgICAgICAgInJpZ2h0T3BlcmFuZCI6ICJ0cmFjZWFiaWxpdHk6MS4wIgogICAgICAgICAgICAgICAgICAgIH0sCiAgICAgICAgICAgICAgICAgICAgewogICAgICAgICAgICAgICAgICAgICAgICAibGVmdE9wZXJhbmQiOiAiaHR0cHM6Ly93M2lkLm9yZy9jYXRlbmF4L3BvbGljeS9Vc2FnZVB1cnBvc2UiLAogICAgICAgICAgICAgICAgICAgICAgICAib3BlcmF0b3IiOiB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAiQGlkIjogImVxIgogICAgICAgICAgICAgICAgICAgICAgICB9LAogICAgICAgICAgICAgICAgICAgICAgICAicmlnaHRPcGVyYW5kIjogImN4LmNvcmUuaW5kdXN0cnljb3JlOjEiCiAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgXQogICAgICAgICAgICB9CiAgICAgICAgfQogICAgXQp9XQ==" discoveryFinderClient: cacheTTL: PT24H # Time to live for DiscoveryFinderClient for findDiscoveryEndpoints method cache connectorEndpointService: diff --git a/irs-policy-store/src/main/java/org/eclipse/tractusx/irs/policystore/config/DefaultAcceptedPoliciesConfig.java b/irs-policy-store/src/main/java/org/eclipse/tractusx/irs/policystore/config/DefaultAcceptedPoliciesConfig.java index 71dc9c61ad..8b511d7956 100644 --- a/irs-policy-store/src/main/java/org/eclipse/tractusx/irs/policystore/config/DefaultAcceptedPoliciesConfig.java +++ b/irs-policy-store/src/main/java/org/eclipse/tractusx/irs/policystore/config/DefaultAcceptedPoliciesConfig.java @@ -23,8 +23,6 @@ ********************************************************************************/ package org.eclipse.tractusx.irs.policystore.config; -import java.util.List; - import lombok.AllArgsConstructor; import lombok.Data; import org.springframework.boot.context.properties.ConfigurationProperties; @@ -38,13 +36,10 @@ @Data public class DefaultAcceptedPoliciesConfig { - @Deprecated - private List acceptedPolicies; - /** - * Accepted policies as JSON with Base64 encoding + * Accepted policies as a Base64 encoded string. */ - private String acceptedPoliciesJson; + private String acceptedPolicies; /** * Accepted Policy for diff --git a/irs-policy-store/src/main/java/org/eclipse/tractusx/irs/policystore/services/PolicyStoreService.java b/irs-policy-store/src/main/java/org/eclipse/tractusx/irs/policystore/services/PolicyStoreService.java index dbf7ecc37b..cf597eaa92 100644 --- a/irs-policy-store/src/main/java/org/eclipse/tractusx/irs/policystore/services/PolicyStoreService.java +++ b/irs-policy-store/src/main/java/org/eclipse/tractusx/irs/policystore/services/PolicyStoreService.java @@ -28,7 +28,6 @@ import java.time.Clock; import java.time.OffsetDateTime; import java.util.AbstractMap; -import java.util.ArrayList; import java.util.Comparator; import java.util.LinkedList; import java.util.List; @@ -41,18 +40,11 @@ import com.fasterxml.jackson.core.type.TypeReference; import jakarta.json.JsonObject; import lombok.extern.slf4j.Slf4j; -import org.apache.commons.collections.CollectionUtils; import org.apache.commons.lang3.StringUtils; import org.eclipse.tractusx.irs.data.StringMapper; import org.eclipse.tractusx.irs.edc.client.policy.AcceptedPoliciesProvider; import org.eclipse.tractusx.irs.edc.client.policy.AcceptedPolicy; -import org.eclipse.tractusx.irs.edc.client.policy.Constraint; -import org.eclipse.tractusx.irs.edc.client.policy.Constraints; -import org.eclipse.tractusx.irs.edc.client.policy.Operator; -import org.eclipse.tractusx.irs.edc.client.policy.OperatorType; -import org.eclipse.tractusx.irs.edc.client.policy.Permission; import org.eclipse.tractusx.irs.edc.client.policy.Policy; -import org.eclipse.tractusx.irs.edc.client.policy.PolicyType; import org.eclipse.tractusx.irs.edc.client.transformer.EdcTransformer; import org.eclipse.tractusx.irs.policystore.config.DefaultAcceptedPoliciesConfig; import org.eclipse.tractusx.irs.policystore.exceptions.PolicyStoreException; @@ -74,6 +66,9 @@ }) public class PolicyStoreService implements AcceptedPoliciesProvider { + private static final TypeReference> LIST_OF_POLICIES_TYPE = new TypeReference<>() { + }; + private final List allowedPoliciesFromConfig; private final PolicyPersistence persistence; @@ -203,7 +198,8 @@ public void deletePolicy(final String policyId) { throw new ResponseStatusException(HttpStatus.NOT_FOUND, "Policy with id '%s' not found".formatted(policyId)); } else if (bpnsContainingPolicyId.stream().noneMatch(StringUtils::isNotEmpty)) { - throw new ResponseStatusException(HttpStatus.BAD_REQUEST, "A configured default policy cannot be deleted. " + throw new ResponseStatusException(HttpStatus.BAD_REQUEST, // + "A configured default policy cannot be deleted. " + "It can be overridden by defining a default policy via the API instead."); } else { try { @@ -300,44 +296,8 @@ private AcceptedPolicy toAcceptedPolicy(final Policy policy) { return new AcceptedPolicy(policy, policy.getValidUntil()); } - private List createDefaultPolicyFromConfig( - final DefaultAcceptedPoliciesConfig defaultAcceptedPoliciesConfig) { - - // Implementation prior to issue #542, retained for backward compatibility; may be removed in the future - if (CollectionUtils.isNotEmpty(defaultAcceptedPoliciesConfig.getAcceptedPolicies())) { - final List acceptedPolicies = defaultAcceptedPoliciesConfig.getAcceptedPolicies(); - return createDefaultPolicyFromAcceptedPoliciesYaml(acceptedPolicies); - } - // New implementation from issue #542 using JSON compliant with the ODRL schema - else { - final String policiesString = defaultAcceptedPoliciesConfig.getAcceptedPoliciesJson(); - return createPoliciesFromConfigJsonString(policiesString); - } - } - - @Deprecated - private List createDefaultPolicyFromAcceptedPoliciesYaml( - final List acceptedPolicies) { - - final List constraints = new ArrayList<>(); - acceptedPolicies.forEach(acceptedPolicy -> constraints.add(new Constraint(acceptedPolicy.getLeftOperand(), - new Operator(OperatorType.fromValue(acceptedPolicy.getOperator())), acceptedPolicy.getRightOperand()))); - - final OffsetDateTime now = OffsetDateTime.now(clock); - return List.of(Policy.builder() - .policyId(ConfiguredDefaultPolicy.DEFAULT_POLICY_ID) - .createdOn(now) - .validUntil(now.plusYears(ConfiguredDefaultPolicy.DEFAULT_POLICY_LIFETIME_YEARS)) - .permissions(List.of(Permission.builder() - .action(PolicyType.USE) - .constraint(new Constraints(constraints, constraints)) - .build())) - .build()); - } - - public static List createPoliciesFromConfigJsonString(final String policiesString) { - return StringMapper.mapFromBase64String(policiesString, new TypeReference<>() { - }); + private List createDefaultPolicyFromConfig(final DefaultAcceptedPoliciesConfig defaultPoliciesConfig) { + return StringMapper.mapFromBase64String(defaultPoliciesConfig.getAcceptedPolicies(), LIST_OF_POLICIES_TYPE); } } diff --git a/irs-registry-client/README.md b/irs-registry-client/README.md index 15778aba25..af30297c27 100644 --- a/irs-registry-client/README.md +++ b/irs-registry-client/README.md @@ -64,18 +64,13 @@ irs-edc-client: catalog: - # IRS will only negotiate contracts for offers with a policy as defined in the acceptedPolicies list. - # If a requested asset does not provide one of these policies, a tombstone will be created and this node will not be processed. - acceptedPolicies: - - leftOperand: "PURPOSE" - operator: "eq" - rightOperand: "ID 3.1 Trace" - - leftOperand: "FrameworkAgreement.traceability" - operator: "eq" - rightOperand: "active" - - leftOperand: "Membership" - operator: "eq" - rightOperand: "active" + # IRS will only negotiate contracts for offers with a policy as defined in the Policy Store. + # The following configuration value allows the definition of default policies to be used + # if no policy has been defined via the Policy Store API. + # If the policy check fails, a tombstone will be created and this node will not be processed. + # The value must be Base64 encoded here. + acceptedPolicies: "W3sKICAgICJwb2xpY3lJZCI6ICJkZWZhdWx0LXRyYWNlLXBvbGljeSIsCiAgICAiY3JlYXRlZE9uIjogIjIwMjQtMDctMTdUMTY6MTU6MTQuMTIzNDU2NzhaIiwKICAgICJ2YWxpZFVudGlsIjogIjk5OTktMDEtMDFUMDA6MDA6MDAuMDAwMDAwMDBaIiwKICAgICJwZXJtaXNzaW9ucyI6IFsKICAgICAgICB7CiAgICAgICAgICAgICJhY3Rpb24iOiAidXNlIiwKICAgICAgICAgICAgImNvbnN0cmFpbnQiOiB7CiAgICAgICAgICAgICAgICAiYW5kIjogWwogICAgICAgICAgICAgICAgICAgIHsKICAgICAgICAgICAgICAgICAgICAgICAgImxlZnRPcGVyYW5kIjogImh0dHBzOi8vdzNpZC5vcmcvY2F0ZW5heC9wb2xpY3kvRnJhbWV3b3JrQWdyZWVtZW50IiwKICAgICAgICAgICAgICAgICAgICAgICAgIm9wZXJhdG9yIjogewogICAgICAgICAgICAgICAgICAgICAgICAgICAgIkBpZCI6ICJlcSIKICAgICAgICAgICAgICAgICAgICAgICAgfSwKICAgICAgICAgICAgICAgICAgICAgICAgInJpZ2h0T3BlcmFuZCI6ICJ0cmFjZWFiaWxpdHk6MS4wIgogICAgICAgICAgICAgICAgICAgIH0sCiAgICAgICAgICAgICAgICAgICAgewogICAgICAgICAgICAgICAgICAgICAgICAibGVmdE9wZXJhbmQiOiAiaHR0cHM6Ly93M2lkLm9yZy9jYXRlbmF4L3BvbGljeS9Vc2FnZVB1cnBvc2UiLAogICAgICAgICAgICAgICAgICAgICAgICAib3BlcmF0b3IiOiB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAiQGlkIjogImVxIgogICAgICAgICAgICAgICAgICAgICAgICB9LAogICAgICAgICAgICAgICAgICAgICAgICAicmlnaHRPcGVyYW5kIjogImN4LmNvcmUuaW5kdXN0cnljb3JlOjEiCiAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgXQogICAgICAgICAgICB9CiAgICAgICAgfQogICAgXQp9XQ==" + ``` From cd4ef599fdc5d7b384c968c481e8579f3dab9ca4 Mon Sep 17 00:00:00 2001 From: Matthias Fischer Date: Thu, 18 Jul 2024 16:22:31 +0200 Subject: [PATCH 07/11] chore(documentation): [#542] fix number of included lines from values.yaml --- docs/src/docs/administration/configuration.adoc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/src/docs/administration/configuration.adoc b/docs/src/docs/administration/configuration.adoc index 5921895f1f..6f9dbb509c 100644 --- a/docs/src/docs/administration/configuration.adoc +++ b/docs/src/docs/administration/configuration.adoc @@ -14,7 +14,7 @@ include::irs-spring-config.adoc[leveloffset=+1] [source,yaml] ---- -include::../../../../charts/item-relationship-service/values.yaml[lines=104..302] +include::../../../../charts/item-relationship-service/values.yaml[lines=104..338] ---- <1> Use this to enable or disable the monitoring components From 8df0d56689109e662a8ed135fa0c074fce0b7a1d Mon Sep 17 00:00:00 2001 From: Matthias Fischer Date: Thu, 18 Jul 2024 16:34:45 +0200 Subject: [PATCH 08/11] feat(impl): [#542] improvements --- .../tractusx/irs/data/StringMapper.java | 28 +++++++++++++++---- 1 file changed, 23 insertions(+), 5 deletions(-) diff --git a/irs-models/src/main/java/org/eclipse/tractusx/irs/data/StringMapper.java b/irs-models/src/main/java/org/eclipse/tractusx/irs/data/StringMapper.java index 491a2d1179..7ca34c08c0 100644 --- a/irs-models/src/main/java/org/eclipse/tractusx/irs/data/StringMapper.java +++ b/irs-models/src/main/java/org/eclipse/tractusx/irs/data/StringMapper.java @@ -23,7 +23,10 @@ ********************************************************************************/ package org.eclipse.tractusx.irs.data; +import java.nio.charset.Charset; +import java.nio.charset.StandardCharsets; import java.util.Base64; +import java.util.Objects; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.core.type.TypeReference; @@ -35,7 +38,6 @@ import lombok.AccessLevel; import lombok.NoArgsConstructor; import lombok.extern.slf4j.Slf4j; -import org.apache.commons.lang3.StringUtils; /** * Maps objects to strings and vice-versa. @@ -43,6 +45,9 @@ @Slf4j @NoArgsConstructor(access = AccessLevel.PRIVATE) public class StringMapper { + + private static final Charset CHARSET = StandardCharsets.UTF_8; + private static final ObjectMapper MAPPER = new ObjectMapper(); static { @@ -60,6 +65,13 @@ public static String mapToString(final Object value) { } } + public static T mapFromBase64String(final String value, final TypeReference typeReference) { + if (value == null) { + return null; + } + return mapFromString(fromBase64(value), typeReference); + } + public static T mapFromString(final String value, final Class clazz) { try { return MAPPER.readValue(value, clazz); @@ -68,10 +80,6 @@ public static T mapFromString(final String value, final Class clazz) { } } - public static T mapFromBase64String(final String value, final TypeReference typeReference) { - return mapFromString(new String(Base64.getDecoder().decode(StringUtils.trim(value))), typeReference); - } - public static T mapFromString(final String value, final TypeReference typeReference) { try { return MAPPER.readValue(value, typeReference); @@ -80,4 +88,14 @@ public static T mapFromString(final String value, final TypeReference typ } } + public static String toBase64(final String str) { + Objects.requireNonNull(str); + return new String(Base64.getEncoder().encode(str.trim().getBytes(CHARSET))); + } + + public static String fromBase64(final String value) { + Objects.requireNonNull(value); + return new String(Base64.getDecoder().decode(value.trim()), CHARSET); + } + } From ad6cc56c4c8b06c3a0be043ff29841f2d544e472 Mon Sep 17 00:00:00 2001 From: Matthias Fischer Date: Thu, 18 Jul 2024 16:36:16 +0200 Subject: [PATCH 09/11] fix(test): [#542] fixed test --- .../services/PolicyStoreServiceTest.java | 65 ++++++++++++++----- 1 file changed, 49 insertions(+), 16 deletions(-) diff --git a/irs-policy-store/src/test/java/org/eclipse/tractusx/irs/policystore/services/PolicyStoreServiceTest.java b/irs-policy-store/src/test/java/org/eclipse/tractusx/irs/policystore/services/PolicyStoreServiceTest.java index 27857d9483..a5a95bb4a2 100644 --- a/irs-policy-store/src/test/java/org/eclipse/tractusx/irs/policystore/services/PolicyStoreServiceTest.java +++ b/irs-policy-store/src/test/java/org/eclipse/tractusx/irs/policystore/services/PolicyStoreServiceTest.java @@ -47,7 +47,9 @@ import org.eclipse.edc.core.transform.TypeTransformerRegistryImpl; import org.eclipse.edc.jsonld.TitaniumJsonLd; import org.eclipse.edc.spi.monitor.ConsoleMonitor; +import org.eclipse.tractusx.irs.data.StringMapper; import org.eclipse.tractusx.irs.edc.client.policy.AcceptedPolicy; +import org.eclipse.tractusx.irs.edc.client.policy.Constraint; import org.eclipse.tractusx.irs.edc.client.policy.ConstraintConstants; import org.eclipse.tractusx.irs.edc.client.policy.Constraints; import org.eclipse.tractusx.irs.edc.client.policy.Permission; @@ -76,8 +78,6 @@ class PolicyStoreServiceTest { private static final String BPN = "testBpn"; - private static final String EXAMPLE_ALLOWED_NAME = "ID 3.1 Trace"; - private static final String EXAMPLE_ACCEPTED_LEFT_OPERAND = "PURPOSE"; private static final String REGISTER_POLICY_EXAMPLE_PAYLOAD = PolicyStoreControllerTest.REGISTER_POLICY_EXAMPLE_PAYLOAD; private final Clock clock = Clock.systemUTC(); @@ -100,7 +100,46 @@ class PolicyStoreServiceTest { @BeforeEach void setUp() { final DefaultAcceptedPoliciesConfig defaultAcceptedPoliciesConfig = new DefaultAcceptedPoliciesConfig(); - defaultAcceptedPoliciesConfig.setAcceptedPolicies(List.of()); + final String defaultPoliciesStr = """ + [{ + "policyId": "default-policy", + "createdOn": "2024-07-17T16:15:14.12345678Z", + "validUntil": "9999-01-01T00:00:00.00000000Z", + "permissions": [ + { + "action": "use", + "constraint": { + "and": [ + { + "leftOperand": "https://w3id.org/catenax/policy/FrameworkAgreement", + "operator": { + "@id": "eq" + }, + "rightOperand": "traceability:1.0" + }, + { + "leftOperand": "https://w3id.org/catenax/policy/UsagePurpose", + "operator": { + "@id": "eq" + }, + "rightOperand": "cx.core.industrycore:1" + } + ], + "or": [ + { + "leftOperand": "https://w3id.org/catenax/policy/SomethingElse", + "operator": { + "@id": "eq" + }, + "rightOperand": "somethingElse:1.0" + } + ] + } + } + ] + }] + """; + defaultAcceptedPoliciesConfig.setAcceptedPolicies(StringMapper.toBase64(defaultPoliciesStr)); testee = new PolicyStoreService(defaultAcceptedPoliciesConfig, persistenceMock, edcTransformer, clock); } @@ -279,18 +318,6 @@ void getStoredPolicies_shouldReturnAllPoliciesStoredForTheBpn() { @Test void getStoredPolicies_whenNoPoliciesForBpn_shouldReturnTheConfiguredDefaultPolicies() { - - // ARRANGE - - // default policy configuration - final DefaultAcceptedPoliciesConfig.AcceptedPolicy acceptedPolicy1 = new DefaultAcceptedPoliciesConfig.AcceptedPolicy( - EXAMPLE_ACCEPTED_LEFT_OPERAND, "eq", EXAMPLE_ALLOWED_NAME); - final DefaultAcceptedPoliciesConfig.AcceptedPolicy acceptedPolicy2 = new DefaultAcceptedPoliciesConfig.AcceptedPolicy( - EXAMPLE_ACCEPTED_LEFT_OPERAND, "eq", EXAMPLE_ALLOWED_NAME); - final DefaultAcceptedPoliciesConfig defaultAcceptedPoliciesConfig = new DefaultAcceptedPoliciesConfig(); - defaultAcceptedPoliciesConfig.setAcceptedPolicies(List.of(acceptedPolicy1, acceptedPolicy2)); - testee = new PolicyStoreService(defaultAcceptedPoliciesConfig, persistenceMock, edcTransformer, clock); - // ACT final var defaultPolicies = testee.getStoredPolicies(List.of(BPN)); @@ -301,8 +328,14 @@ void getStoredPolicies_whenNoPoliciesForBpn_shouldReturnTheConfiguredDefaultPoli assertThat(permissionList).hasSize(1); final Constraints constraints = permissionList.get(0).getConstraint(); - assertThat(constraints.getOr()).hasSize(2); + assertThat(constraints.getOr()).hasSize(1); + assertThat(constraints.getOr().get(0).getLeftOperand()).isEqualTo( + "https://w3id.org/catenax/policy/SomethingElse"); + assertThat(constraints.getAnd()).hasSize(2); + assertThat(constraints.getAnd().stream().map(Constraint::getLeftOperand)).containsExactlyInAnyOrder( + "https://w3id.org/catenax/policy/FrameworkAgreement", + "https://w3id.org/catenax/policy/UsagePurpose"); } } From 6f885cba878a9c3cded17b7ab6003db2152ab2c8 Mon Sep 17 00:00:00 2001 From: Matthias Fischer Date: Thu, 18 Jul 2024 17:21:01 +0200 Subject: [PATCH 10/11] fix(test): [#542] adapt default policy name, fix wiremock test --- charts/item-relationship-service/values.yaml | 2 +- irs-api/src/main/resources/application.yml | 4 ++-- .../org/eclipse/tractusx/irs/IrsWireMockIntegrationTest.java | 3 +-- 3 files changed, 4 insertions(+), 5 deletions(-) diff --git a/charts/item-relationship-service/values.yaml b/charts/item-relationship-service/values.yaml index 51e8d3ecd8..fa818ec8f6 100644 --- a/charts/item-relationship-service/values.yaml +++ b/charts/item-relationship-service/values.yaml @@ -194,7 +194,7 @@ edc: # Configure the default policies as JSON array using multiline string here. acceptedPolicies: > [{ - "policyId": "default-trace-policy", + "policyId": "default-policy", "createdOn": "2024-07-17T16:15:14.12345678Z", "validUntil": "9999-01-01T00:00:00.00000000Z", "permissions": [ diff --git a/irs-api/src/main/resources/application.yml b/irs-api/src/main/resources/application.yml index 2f27428f42..c4a22509a5 100644 --- a/irs-api/src/main/resources/application.yml +++ b/irs-api/src/main/resources/application.yml @@ -158,8 +158,8 @@ irs-edc-client: # The following configuration value allows the definition of default policies to be used # if no policy has been defined via the Policy Store API. # If the policy check fails, a tombstone will be created and this node will not be processed. - # The value must be Base64 encoded here. - acceptedPolicies: "W3sKICAgICJwb2xpY3lJZCI6ICJkZWZhdWx0LXRyYWNlLXBvbGljeSIsCiAgICAiY3JlYXRlZE9uIjogIjIwMjQtMDctMTdUMTY6MTU6MTQuMTIzNDU2NzhaIiwKICAgICJ2YWxpZFVudGlsIjogIjk5OTktMDEtMDFUMDA6MDA6MDAuMDAwMDAwMDBaIiwKICAgICJwZXJtaXNzaW9ucyI6IFsKICAgICAgICB7CiAgICAgICAgICAgICJhY3Rpb24iOiAidXNlIiwKICAgICAgICAgICAgImNvbnN0cmFpbnQiOiB7CiAgICAgICAgICAgICAgICAiYW5kIjogWwogICAgICAgICAgICAgICAgICAgIHsKICAgICAgICAgICAgICAgICAgICAgICAgImxlZnRPcGVyYW5kIjogImh0dHBzOi8vdzNpZC5vcmcvY2F0ZW5heC9wb2xpY3kvRnJhbWV3b3JrQWdyZWVtZW50IiwKICAgICAgICAgICAgICAgICAgICAgICAgIm9wZXJhdG9yIjogewogICAgICAgICAgICAgICAgICAgICAgICAgICAgIkBpZCI6ICJlcSIKICAgICAgICAgICAgICAgICAgICAgICAgfSwKICAgICAgICAgICAgICAgICAgICAgICAgInJpZ2h0T3BlcmFuZCI6ICJ0cmFjZWFiaWxpdHk6MS4wIgogICAgICAgICAgICAgICAgICAgIH0sCiAgICAgICAgICAgICAgICAgICAgewogICAgICAgICAgICAgICAgICAgICAgICAibGVmdE9wZXJhbmQiOiAiaHR0cHM6Ly93M2lkLm9yZy9jYXRlbmF4L3BvbGljeS9Vc2FnZVB1cnBvc2UiLAogICAgICAgICAgICAgICAgICAgICAgICAib3BlcmF0b3IiOiB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAiQGlkIjogImVxIgogICAgICAgICAgICAgICAgICAgICAgICB9LAogICAgICAgICAgICAgICAgICAgICAgICAicmlnaHRPcGVyYW5kIjogImN4LmNvcmUuaW5kdXN0cnljb3JlOjEiCiAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgXQogICAgICAgICAgICB9CiAgICAgICAgfQogICAgXQp9XQ==" + # The value must be Base64 encoded here. See decoded value in charts/item-relationship-service/values.yaml. + acceptedPolicies: "W3sKICAgICJwb2xpY3lJZCI6ICJkZWZhdWx0LXBvbGljeSIsCiAgICAiY3JlYXRlZE9uIjogIjIwMjQtMDctMTdUMTY6MTU6MTQuMTIzNDU2NzhaIiwKICAgICJ2YWxpZFVudGlsIjogIjk5OTktMDEtMDFUMDA6MDA6MDAuMDAwMDAwMDBaIiwKICAgICJwZXJtaXNzaW9ucyI6IFsKICAgICAgICB7CiAgICAgICAgICAgICJhY3Rpb24iOiAidXNlIiwKICAgICAgICAgICAgImNvbnN0cmFpbnQiOiB7CiAgICAgICAgICAgICAgICAiYW5kIjogWwogICAgICAgICAgICAgICAgICAgIHsKICAgICAgICAgICAgICAgICAgICAgICAgImxlZnRPcGVyYW5kIjogImh0dHBzOi8vdzNpZC5vcmcvY2F0ZW5heC9wb2xpY3kvRnJhbWV3b3JrQWdyZWVtZW50IiwKICAgICAgICAgICAgICAgICAgICAgICAgIm9wZXJhdG9yIjogewogICAgICAgICAgICAgICAgICAgICAgICAgICAgIkBpZCI6ICJlcSIKICAgICAgICAgICAgICAgICAgICAgICAgfSwKICAgICAgICAgICAgICAgICAgICAgICAgInJpZ2h0T3BlcmFuZCI6ICJ0cmFjZWFiaWxpdHk6MS4wIgogICAgICAgICAgICAgICAgICAgIH0sCiAgICAgICAgICAgICAgICAgICAgewogICAgICAgICAgICAgICAgICAgICAgICAibGVmdE9wZXJhbmQiOiAiaHR0cHM6Ly93M2lkLm9yZy9jYXRlbmF4L3BvbGljeS9Vc2FnZVB1cnBvc2UiLAogICAgICAgICAgICAgICAgICAgICAgICAib3BlcmF0b3IiOiB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAiQGlkIjogImVxIgogICAgICAgICAgICAgICAgICAgICAgICB9LAogICAgICAgICAgICAgICAgICAgICAgICAicmlnaHRPcGVyYW5kIjogImN4LmNvcmUuaW5kdXN0cnljb3JlOjEiCiAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgXQogICAgICAgICAgICB9CiAgICAgICAgfQogICAgXQp9XQ==" discoveryFinderClient: cacheTTL: PT24H # Time to live for DiscoveryFinderClient for findDiscoveryEndpoints method cache connectorEndpointService: diff --git a/irs-api/src/test/java/org/eclipse/tractusx/irs/IrsWireMockIntegrationTest.java b/irs-api/src/test/java/org/eclipse/tractusx/irs/IrsWireMockIntegrationTest.java index 67c1efa978..4f70fb6c7b 100644 --- a/irs-api/src/test/java/org/eclipse/tractusx/irs/IrsWireMockIntegrationTest.java +++ b/irs-api/src/test/java/org/eclipse/tractusx/irs/IrsWireMockIntegrationTest.java @@ -337,8 +337,7 @@ void shouldCreateDetailedTombstoneForEdcErrors() { assertThat(jobForJobId.getTombstones()).hasSize(1); final Tombstone actualTombstone = jobForJobId.getTombstones().get(0); assertThat(actualTombstone.getProcessingError().getRootCauses()).hasSize(1); - assertThat(actualTombstone.getProcessingError().getRootCauses().get(0)).contains( - "502 Bad Gateway"); + assertThat(actualTombstone.getProcessingError().getRootCauses().get(0)).contains("502 Bad Gateway"); } @Test From 2e4dc2565d8fdd26a502838a967bd896bcb27194 Mon Sep 17 00:00:00 2001 From: Matthias Fischer Date: Thu, 18 Jul 2024 17:28:24 +0200 Subject: [PATCH 11/11] chore(tests): [#794] update default policy namespace in wiremock test --- .../SubmodelFacadeWiremockSupport.java | 21 ++++++++----------- 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/irs-testing/src/main/java/org/eclipse/tractusx/irs/testing/wiremock/SubmodelFacadeWiremockSupport.java b/irs-testing/src/main/java/org/eclipse/tractusx/irs/testing/wiremock/SubmodelFacadeWiremockSupport.java index a245cb29af..ffbd23bd3b 100644 --- a/irs-testing/src/main/java/org/eclipse/tractusx/irs/testing/wiremock/SubmodelFacadeWiremockSupport.java +++ b/irs-testing/src/main/java/org/eclipse/tractusx/irs/testing/wiremock/SubmodelFacadeWiremockSupport.java @@ -52,9 +52,9 @@ public final class SubmodelFacadeWiremockSupport { public static final String IRS_INTERNAL_CALLBACK_URL = "https://irs.test/internal/endpoint-data-reference"; public static final String EDC_PROVIDER_BPN = "BPNL00000000TEST"; public static final int STATUS_CODE_OK = 200; - public static final String CX_POLICY_FRAMEWORK_AGREEMENT = "cx-policy:FrameworkAgreement"; + public static final String CX_POLICY_FRAMEWORK_AGREEMENT = "https://w3id.org/catenax/policy/FrameworkAgreement"; public static final String TRACEABILITY_1_0 = "traceability:1.0"; - public static final String CX_POLICY_USAGE_PURPOSE = "cx-policy:UsagePurpose"; + public static final String CX_POLICY_USAGE_PURPOSE = "https://w3id.org/catenax/policy/UsagePurpose"; public static final String CX_CORE_INDUSTRYCORE_1 = "cx.core.industrycore:1"; public static final String PERMISSION_TYPE = "use"; public static final int STATUS_CODE_BAD_GATEWAY = 502; @@ -76,8 +76,7 @@ public static void prepareNegotiation(final String negotiationId, final String t stubFor(post(urlPathEqualTo(PATH_CATALOG)).willReturn(WireMockConfig.responseWithStatus(STATUS_CODE_OK) .withBody(getCatalogResponse(edcAssetId, contractAgreementId, - PERMISSION_TYPE, - EDC_PROVIDER_BPN, + PERMISSION_TYPE, EDC_PROVIDER_BPN, createConstraints())))); stubFor(post(urlPathEqualTo(PATH_NEGOTIATE)).willReturn( @@ -113,14 +112,13 @@ public static void prepareMissmatchPolicyCatalog(final String edcAssetId, final stubFor(post(urlPathEqualTo(PATH_CATALOG)).willReturn(WireMockConfig.responseWithStatus(STATUS_CODE_OK) .withBody(getCatalogResponse(edcAssetId, contractAgreementId, - PERMISSION_TYPE, - EDC_PROVIDER_BPN, + PERMISSION_TYPE, EDC_PROVIDER_BPN, createNotAcceptedConstraints())))); } public static void prepareFailingCatalog() { - stubFor(post(urlPathEqualTo(PATH_CATALOG)).willReturn(WireMockConfig.responseWithStatus(STATUS_CODE_BAD_GATEWAY) - .withBody(""))); + stubFor(post(urlPathEqualTo(PATH_CATALOG)).willReturn( + WireMockConfig.responseWithStatus(STATUS_CODE_BAD_GATEWAY).withBody(""))); } private static String startTransferProcessResponse(final String transferProcessId) { @@ -253,8 +251,8 @@ public static String getCatalogResponse(final String edcAssetId, final String of "dspace:participantId": "%s", "@context": %s } - """.formatted(edcAssetId, offerId, permissionType, constraints, EDC_PROVIDER_DUMMY_URL, - edcAssetId, EDC_PROVIDER_DUMMY_URL, edcProviderBpn, edcProviderBpn, CONTEXT); + """.formatted(edcAssetId, offerId, permissionType, constraints, EDC_PROVIDER_DUMMY_URL, edcAssetId, + EDC_PROVIDER_DUMMY_URL, edcProviderBpn, edcProviderBpn, CONTEXT); } private static String createConstraints() { @@ -270,8 +268,7 @@ private static String createConstraints() { } private static String createNotAcceptedConstraints() { - final List atomitConstraints = List.of( - createAtomicConstraint("test", "test")); + final List atomitConstraints = List.of(createAtomicConstraint("test", "test")); return """ { "odrl:and": [