diff --git a/irs-api/src/test/java/org/eclipse/tractusx/irs/aaswrapper/job/delegate/RelationshipDelegateTest.java b/irs-api/src/test/java/org/eclipse/tractusx/irs/aaswrapper/job/delegate/RelationshipDelegateTest.java index b6dea229fa..bc9a42531c 100644 --- a/irs-api/src/test/java/org/eclipse/tractusx/irs/aaswrapper/job/delegate/RelationshipDelegateTest.java +++ b/irs-api/src/test/java/org/eclipse/tractusx/irs/aaswrapper/job/delegate/RelationshipDelegateTest.java @@ -391,7 +391,7 @@ void shouldCatchUsagePolicyExceptionAndPutTombstone() throws EdcClientException // when when(submodelFacade.getSubmodelPayload(any(), any(), any(), any())).thenThrow( - new UsagePolicyPermissionException("itemId", null, businessPartnerNumber)); + new UsagePolicyPermissionException(List.of(), null, businessPartnerNumber)); when(connectorEndpointsService.fetchConnectorEndpoints(any())).thenReturn(List.of("connector.endpoint.nl")); final ItemContainer result = relationshipDelegate.process(itemContainerWithShell, jobParameter(), new AASTransferProcess(), createKey()); diff --git a/irs-api/src/test/java/org/eclipse/tractusx/irs/aaswrapper/job/delegate/SubmodelDelegateTest.java b/irs-api/src/test/java/org/eclipse/tractusx/irs/aaswrapper/job/delegate/SubmodelDelegateTest.java index ab98d6123e..f6a98013c4 100644 --- a/irs-api/src/test/java/org/eclipse/tractusx/irs/aaswrapper/job/delegate/SubmodelDelegateTest.java +++ b/irs-api/src/test/java/org/eclipse/tractusx/irs/aaswrapper/job/delegate/SubmodelDelegateTest.java @@ -153,7 +153,7 @@ void shouldCatchUsagePolicyExceptionAndPutTombstone() throws EdcClientException // when when(submodelFacade.getSubmodelPayload(any(), any(), any(), any())).thenThrow( - new UsagePolicyPermissionException("itemId", null, businessPartnerNumber)); + new UsagePolicyPermissionException(List.of(), null, businessPartnerNumber)); when(connectorEndpointsService.fetchConnectorEndpoints(any())).thenReturn(List.of("connector.endpoint.nl")); final ItemContainer result = submodelDelegate.process(itemContainerShellWithTwoSubmodels, jobParameterCollectAspects(), new AASTransferProcess(), createKey()); diff --git a/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/ContractNegotiationService.java b/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/ContractNegotiationService.java index d45e24dac5..45a58bcb0e 100644 --- a/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/ContractNegotiationService.java +++ b/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/ContractNegotiationService.java @@ -127,13 +127,13 @@ private CompletableFuture startNewNegotiation(final String if (!policyCheckerService.isValid(catalogItem.getPolicy(), bpn)) { log.warn("Policy was not allowed, canceling negotiation."); - throw new UsagePolicyPermissionException(catalogItem.getItemId(), catalogItem.getPolicy(), + throw new UsagePolicyPermissionException(policyCheckerService.getValidStoredPolicies(catalogItem.getConnectorId()), catalogItem.getPolicy(), catalogItem.getConnectorId()); } if (policyCheckerService.isExpired(catalogItem.getPolicy(), bpn)) { log.warn("Policy is expired, canceling negotiation."); - throw new UsagePolicyExpiredException(catalogItem.getItemId(), catalogItem.getPolicy(), + throw new UsagePolicyExpiredException(catalogItem.getPolicy(), catalogItem.getConnectorId()); } diff --git a/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/exceptions/UsagePolicyExpiredException.java b/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/exceptions/UsagePolicyExpiredException.java index e9c4e44fa7..097ed1c92a 100644 --- a/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/exceptions/UsagePolicyExpiredException.java +++ b/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/exceptions/UsagePolicyExpiredException.java @@ -31,10 +31,10 @@ public class UsagePolicyExpiredException extends EdcClientException { private final transient Policy policy; private final String businessPartnerNumber; - public UsagePolicyExpiredException(final String itemId, final Policy policy, final String businessPartnerNumber) { - super("Consumption of asset '" + itemId - + "' is not permitted as the required catalog offer policies are expired."); + public UsagePolicyExpiredException(final Policy policy, final String businessPartnerNumber) { + super("Policy from " + businessPartnerNumber + " has expired."); this.policy = policy; this.businessPartnerNumber = businessPartnerNumber; } + } diff --git a/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/exceptions/UsagePolicyPermissionException.java b/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/exceptions/UsagePolicyPermissionException.java index c289672f12..3e2f1c797f 100644 --- a/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/exceptions/UsagePolicyPermissionException.java +++ b/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/exceptions/UsagePolicyPermissionException.java @@ -23,8 +23,11 @@ ********************************************************************************/ package org.eclipse.tractusx.irs.edc.client.exceptions; +import java.util.List; + import lombok.Getter; import org.eclipse.edc.policy.model.Policy; +import org.eclipse.tractusx.irs.edc.client.policy.AcceptedPolicy; /** * Usage Policy Permission Exception errors in the contract negotiation. @@ -35,11 +38,15 @@ public class UsagePolicyPermissionException extends EdcClientException { private final transient Policy policy; private final String businessPartnerNumber; - public UsagePolicyPermissionException(final String itemId, final Policy policy, - final String businessPartnerNumber) { - super("Consumption of asset '" + itemId - + "' is not permitted as the required catalog offer policies do not comply with defined policies."); - this.policy = policy; + public UsagePolicyPermissionException(final List acceptedPolicies, + final Policy providedCatalogItemPolicy, final String businessPartnerNumber) { + super("Policies " + + acceptedPolicies.stream().map(policy -> policy.policy().getPolicyId()).toList() + + " did not match with policy from " + businessPartnerNumber + "."); + + this.policy = providedCatalogItemPolicy; this.businessPartnerNumber = businessPartnerNumber; + } + } diff --git a/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/policy/PolicyCheckerService.java b/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/policy/PolicyCheckerService.java index daa34c81d6..b4e052e914 100644 --- a/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/policy/PolicyCheckerService.java +++ b/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/policy/PolicyCheckerService.java @@ -70,7 +70,7 @@ private boolean hasExpiredConstraint(final Permission permission, final List acceptedPolicy.validUntil().isBefore(OffsetDateTime.now())); } - private List getValidStoredPolicies(final String bpn) { + public List getValidStoredPolicies(final String bpn) { return policyStore.getAcceptedPolicies(bpn).stream().toList(); } diff --git a/irs-edc-client/src/test/java/org/eclipse/tractusx/irs/edc/client/SubmodelFacadeWiremockTest.java b/irs-edc-client/src/test/java/org/eclipse/tractusx/irs/edc/client/SubmodelFacadeWiremockTest.java index 135fd74842..ca71a2e2bf 100644 --- a/irs-edc-client/src/test/java/org/eclipse/tractusx/irs/edc/client/SubmodelFacadeWiremockTest.java +++ b/irs-edc-client/src/test/java/org/eclipse/tractusx/irs/edc/client/SubmodelFacadeWiremockTest.java @@ -37,6 +37,7 @@ import static org.eclipse.tractusx.irs.testing.wiremock.SubmodelFacadeWiremockSupport.TRACEABILITY_1_0; import static org.eclipse.tractusx.irs.testing.wiremock.WireMockConfig.responseWithStatus; import static org.eclipse.tractusx.irs.testing.wiremock.WireMockConfig.restTemplateProxy; +import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; @@ -235,13 +236,13 @@ void shouldThrowExceptionWhenPoliciesAreNotAccepted() { final AcceptedPolicy acceptedPolicy = new AcceptedPolicy(policy("IRS Policy", List.of(permission)), OffsetDateTime.now().plusYears(1)); - when(acceptedPoliciesProvider.getAcceptedPolicies("bpn")).thenReturn(List.of(acceptedPolicy)); + when(acceptedPoliciesProvider.getAcceptedPolicies(anyString())).thenReturn(List.of(acceptedPolicy)); prepareNegotiation(); givenThat(get(urlPathEqualTo(SUBMODEL_DATAPLANE_PATH)).willReturn(responseWithStatus(200).withBody("test"))); // Act & Assert - final String errorMessage = "Consumption of asset '5a7ab616-989f-46ae-bdf2-32027b9f6ee6-31b614f5-ec14-4ed2-a509-e7b7780083e7' is not permitted as the required catalog offer policies do not comply with defined policies."; + final String errorMessage = "Policies [IRS Policy] did not match with policy from BPNL00000000TEST."; assertThatExceptionOfType(UsagePolicyPermissionException.class).isThrownBy( () -> edcSubmodelClient.getSubmodelPayload(CONNECTOR_ENDPOINT_URL, SUBMODEL_DATAPLANE_URL, ASSET_ID, "bpn") .get()).withMessageEndingWith(errorMessage);