Skip to content

Commit

Permalink
feat(irs-api):[#256] spotbug fix
Browse files Browse the repository at this point in the history
  • Loading branch information
ds-psosnowski committed Dec 6, 2023
1 parent 9654457 commit 6b8e0db
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand Down Expand Up @@ -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,
Expand All @@ -82,8 +83,8 @@ private Optional<EndpointDataReference> 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);
}

Expand Down

0 comments on commit 6b8e0db

Please sign in to comment.