code: @Override
      public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
          HttpServletRequest httpRequest = (HttpServletRequest) request;
  
          String authToken = getAuthTokenFromRequest(httpRequest);
          String userName = TokenUtils.getUserNameFromToken(authToken);
  
          if (userName != null) {
              UserDetails userDetails = userService.loadUserByUsername(userName);
  
              if (TokenUtils.validateToken(authToken, userDetails)) {
                  UsernamePasswordAuthenticationToken authentication = new UsernamePasswordAuthenticationToken(userDetails, null, userDetails.getAuthorities());
                  authentication.setDetails(new WebAuthenticationDetailsSource().buildDetails(httpRequest));
                  SecurityContextHolder.getContext().setAuthentication(authentication);
              }
          }
  
          chain.doFilter(request, response);
      }
docs: Retrieves the authorization token from the request and validates it against the {@code UserService}.
  
  @param request  servlet request.
  @param response servlet response.
  @param chain    filter chain.
  @throws IOException
  @throws ServletException