Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
<maven.compiler.version>3.11.0</maven.compiler.version>

<!-- DVSA Internal Libraries -->
<active-support.version>2.12.0</active-support.version>
<active-support.version>2.14.2</active-support.version>
<uri-constructor.version>2.4.0</uri-constructor.version>

<!-- Testing & API Libraries -->
Expand Down
29 changes: 22 additions & 7 deletions src/main/java/apiCalls/Utils/generic/BaseAPI.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,30 @@ public synchronized String adminJWT() throws HttpException {

private boolean isTokenExpired(String token) {
try {
var decodedJWT = Jwts.parser()
.unsecured()
.build()
.parseUnsecuredClaims(token)
.getPayload();

String[] chunks = token.split("\\.");
if (chunks.length != 3) {
LOGGER.error("Invalid JWT format - expected 3 parts but got {}", chunks.length);
return true;
}

String payload = new String(java.util.Base64.getUrlDecoder().decode(chunks[1]));

com.fasterxml.jackson.databind.ObjectMapper mapper = new com.fasterxml.jackson.databind.ObjectMapper();
com.fasterxml.jackson.databind.JsonNode claims = mapper.readTree(payload);

return decodedJWT.getExpiration().before(new Date());
if (claims.has("exp")) {
long expTime = claims.get("exp").asLong() * 1000; // Convert from seconds to milliseconds
boolean expired = expTime < System.currentTimeMillis();
LOGGER.debug("Token expiration check: exp={}, current={}, expired={}",
new Date(expTime), new Date(), expired);
return expired;
} else {
LOGGER.warn("Token has no expiration claim, treating as expired");
return true;
}
} catch (Exception e) {
LOGGER.error("Error decoding token: {}", e.getMessage());
LOGGER.error("Error checking token expiration: {}", e.getMessage());
return true;
}
}
Expand Down