I need to write my custom Security Spring filter to validate a JWT token.
I have my custom JWT validator. When the token is valid I have to authorise the user.
I implemented this like some others example that are presents online:
UsernamePasswordAuthenticationToken usernamePasswordAuthenticationToken = new UsernamePasswordAuthenticationToken(user_id, null, null);
usernamePasswordAuthenticationToken.setDetails(new WebAuthenticationDetailsSource().buildDetails(request));
SecurityContextHolder.getContext().setAuthentication(usernamePasswordAuthenticationToken);
This works fine but my question is this: Is there a dedicated AuthenticationToken for JWT validation without to use UsernamePasswordAuthenticationToken?
I don't like to use UsernamePasswordAuthenticationToken... it's a good practice?