From 6b8e0db4f486beaa055757499e0fe75718e07119 Mon Sep 17 00:00:00 2001 From: Pawel Sosnowski Date: Wed, 6 Dec 2023 11:26:06 +0100 Subject: [PATCH] feat(irs-api):[#256] spotbug fix --- .../irs/edc/client/ContractNegotiationService.java | 6 +++--- .../edc/client/util/EndpointDataReferenceCacheService.java | 7 ++++--- 2 files changed, 7 insertions(+), 6 deletions(-) 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 26adfe26ad..b4665d6676 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 @@ -91,11 +91,11 @@ public NegotiationResponse negotiate(final String providerConnectorUrl, final Ca contractAgreementId = negotiationResponse.getContractAgreementId(); } case EXPIRED -> { - if (endpointDataReferenceStatus.endpointDataReference().getAuthKey() == null) { + final String authKey = endpointDataReferenceStatus.endpointDataReference().getAuthKey(); + if (authKey == null) { throw new IllegalStateException("Missing information about AuthKey."); } - contractAgreementId = EDRAuthCode.fromAuthCodeToken( - endpointDataReferenceStatus.endpointDataReference().getAuthKey()).getCid(); + contractAgreementId = EDRAuthCode.fromAuthCodeToken(authKey).getCid(); log.info( "Cached endpoint data reference has expired token. Refreshing token without new contract negotiation for contractAgreementId: {}", Masker.mask(contractAgreementId)); diff --git a/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/util/EndpointDataReferenceCacheService.java b/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/util/EndpointDataReferenceCacheService.java index 1abe0b14b8..4f742bd666 100644 --- a/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/util/EndpointDataReferenceCacheService.java +++ b/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/util/EndpointDataReferenceCacheService.java @@ -31,6 +31,7 @@ import org.eclipse.edc.spi.types.domain.edr.EndpointDataReference; import org.eclipse.tractusx.irs.edc.client.EndpointDataReferenceStorage; import org.eclipse.tractusx.irs.edc.client.model.EDRAuthCode; +import org.jetbrains.annotations.NotNull; import org.springframework.stereotype.Service; /** @@ -60,7 +61,7 @@ public EndpointDataReferenceStatus getEndpointDataReference(final String assetId if (endpointDataReferenceOptional.isPresent() && endpointDataReferenceOptional.get().getAuthCode() != null) { final EndpointDataReference endpointDataReference = endpointDataReferenceOptional.get(); - if (isTokenExpired(endpointDataReference)) { + if (isTokenExpired(endpointDataReferenceOptional.get().getAuthCode())) { log.info("Endpoint data reference with expired token and id: {} for assetId: {} found in storage.", endpointDataReference.getId(), assetId); return new EndpointDataReferenceStatus(endpointDataReference, @@ -82,8 +83,8 @@ private Optional retrieveEndpointEndpointReferenceByAsset return endpointDataReferenceStorage.get(assetId); } - private static boolean isTokenExpired(final EndpointDataReference endpointDataReference) { - final Instant tokenExpirationInstant = extractTokenExpiration(endpointDataReference.getAuthCode()); + private static boolean isTokenExpired(final @NotNull String authCode) { + final Instant tokenExpirationInstant = extractTokenExpiration(authCode); return Instant.now().isAfter(tokenExpirationInstant); }