Skip to content

Commit

Permalink
Add token length logging
Browse files Browse the repository at this point in the history
  • Loading branch information
ThomasAFink authored Sep 14, 2023
1 parent 08f6134 commit 99a1f30
Showing 1 changed file with 7 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,17 +41,24 @@ public final User getCurrentUser() {

private User readUserFromToken(Authentication authentication) {
if (authentication instanceof JwtAuthenticationToken) {
log.info("Authentication instance of JwtAuthenticationToken");
final JwtAuthenticationToken jwtToken = (JwtAuthenticationToken) authentication;

// Logging the length of the token here
log.info("Token length: {}", jwtToken.getToken().getTokenValue().length());

Map<String, Object> tokenAttributes = jwtToken.getTokenAttributes();
try {
return new User(
getUserMail(tokenAttributes),
getDepartment(jwtToken.getToken().getTokenValue()),
getRoles(tokenAttributes));
} catch (JsonProcessingException e) {
log.error("Error processing token attributes: {}", e.getMessage());
throw new RuntimeException(e);
}
} else {
log.error("Authentication not via token, throwing RuntimeException");
throw new RuntimeException("Only authentication via token is allowed!");
}
}
Expand Down

0 comments on commit 99a1f30

Please sign in to comment.