From bb0aee15200ea9fde188fc8c8ec2287ce69d8905 Mon Sep 17 00:00:00 2001 From: Bas Huisman Date: Thu, 28 Nov 2024 09:51:59 +0100 Subject: [PATCH] use LocalDateTime --- src/main/java/nl/ictu/Token.java | 7 ++----- src/main/java/nl/ictu/controller/v1/ExchangeToken.java | 8 +++++++- src/main/java/nl/ictu/controller/v1/GetToken.java | 4 ++-- 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/src/main/java/nl/ictu/Token.java b/src/main/java/nl/ictu/Token.java index 95d7c45..314622f 100644 --- a/src/main/java/nl/ictu/Token.java +++ b/src/main/java/nl/ictu/Token.java @@ -1,10 +1,9 @@ package nl.ictu; -import com.fasterxml.jackson.annotation.JsonFormat; import lombok.Getter; import lombok.Setter; -import java.util.Date; +import java.time.LocalDateTime; @Getter @@ -15,8 +14,6 @@ public final class Token { private String version = "v1"; private String bsn; private String recipientOIN; + private LocalDateTime creationDate; - @JsonFormat - (shape = JsonFormat.Shape.STRING, pattern = "dd-MM-yyyy hh:mm:ss") - private Date creationDate; } diff --git a/src/main/java/nl/ictu/controller/v1/ExchangeToken.java b/src/main/java/nl/ictu/controller/v1/ExchangeToken.java index 52d8929..f9eeec6 100644 --- a/src/main/java/nl/ictu/controller/v1/ExchangeToken.java +++ b/src/main/java/nl/ictu/controller/v1/ExchangeToken.java @@ -11,6 +11,8 @@ import nl.ictu.pseudoniemenservice.generated.server.model.WsIdentifier; import nl.ictu.service.Cryptographer; import nl.ictu.service.TokenConverter; +import org.springframework.core.env.Environment; +import org.springframework.core.env.Profiles; import org.springframework.http.ResponseEntity; import org.springframework.util.StringUtils; import org.springframework.web.bind.annotation.RestController; @@ -28,6 +30,8 @@ public final class ExchangeToken implements ExchangeTokenApi, VersionOneControll private final ObjectMapper objectMapper; + private final Environment environment; + @Override @SneakyThrows public ResponseEntity exchangeTokenForIdentifier(final String callerOIN, final WsExchangeTokenForIdentifierRequest wsExchangeTokenForIdentifierRequest) { @@ -36,7 +40,9 @@ public ResponseEntity exchangeTokenForI final Token token = tokenConverter.decode(encodedToken); - //log.info("Received token: {}", objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(token)); + if (environment.acceptsProfiles(Profiles.of("test"))) { + log.info("Received token: {}", objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(token)); + } if (!callerOIN.equals(token.getRecipientOIN())) { throw new RuntimeException("Sink OIN not the same"); diff --git a/src/main/java/nl/ictu/controller/v1/GetToken.java b/src/main/java/nl/ictu/controller/v1/GetToken.java index 3229043..9ed9509 100644 --- a/src/main/java/nl/ictu/controller/v1/GetToken.java +++ b/src/main/java/nl/ictu/controller/v1/GetToken.java @@ -12,7 +12,7 @@ import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.RestController; -import java.util.Date; +import java.time.LocalDateTime; @RestController @RequiredArgsConstructor @@ -32,7 +32,7 @@ public ResponseEntity getToken(final String callerOIN, fi final Token token = new Token(); - token.setCreationDate(new Date(System.currentTimeMillis())); + token.setCreationDate(LocalDateTime.now()); token.setRecipientOIN(wsGetTokenRequest.getRecipientOIN()); if (wsGetTokenRequest.getIdentifier() != null) {