Skip to content

Commit dcee575

Browse files
author
Rajeev Kumar Singh
committed
Added comment
1 parent e8944b7 commit dcee575

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

polling-app-server/src/main/java/com/example/polls/security/JwtAuthenticationFilter.java

+5
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,11 @@ protected void doFilterInternal(HttpServletRequest request, HttpServletResponse
3737
if (StringUtils.hasText(jwt) && tokenProvider.validateToken(jwt)) {
3838
Long userId = tokenProvider.getUserIdFromJWT(jwt);
3939

40+
/*
41+
Note that you could also encode the user's username and roles inside JWT claims
42+
and create the UserDetails object by parsing those claims from the JWT.
43+
That would avoid the following database hit. It's completely up to you.
44+
*/
4045
UserDetails userDetails = customUserDetailsService.loadUserById(userId);
4146
UsernamePasswordAuthenticationToken authentication = new UsernamePasswordAuthenticationToken(userDetails, null, userDetails.getAuthorities());
4247
authentication.setDetails(new WebAuthenticationDetailsSource().buildDetails(request));

0 commit comments

Comments
 (0)