-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Open
Description
When using JWT authentication, SecurityContextHolder.getContext().getAuthentication().getCredentials() does not return a String but an instance of Jwt.
Overview of the issue
SecurityUtils.getCurrentUserJWT() always returns an empty Optional.
Suggest a Fix
public static Optional<String> getCurrentUserJWT() {
SecurityContext securityContext = SecurityContextHolder.getContext();
return Optional.ofNullable(securityContext.getAuthentication())
.filter(authentication -> authentication.getCredentials() instanceof Jwt)
.map(authentication -> ((Jwt) authentication.getCredentials()).getTokenValue());
}
JHipster Version(s)
Latest from main.
Reactions are currently unavailable