title: how to add more claims to a jwt token in a custom authentication filter
body: <p>I want to send more than just the username and roles using the authentication filter in springboot,
  I'm using the user type inherited from userDetails from springboot security  whenever I try to manually get the name and add it as a claim I get a null exception. even though the method I use are tested and work outside of the filter.</p>
  <p>code:</p>
  <pre><code>public class CustomAuthenticationFilter extends UsernamePasswordAuthenticationFilter {
  
  @Autowired
  UserService userService;
  
  @Autowired
  AuthenticationManager authenticationManager;
  
  public CustomAuthenticationFilter(AuthenticationManager authenticationManager){
  
      this.authenticationManager = authenticationManager;
  }
  String name;
  @Override
  public Authentication attemptAuthentication(HttpServletRequest request,HttpServletResponse response ) throws AuthenticationException{
  
      String username = request.getParameter(&quot;username&quot;);
      String password = request.getParameter(&quot;password&quot;);
  
  
      UsernamePasswordAuthenticationToken authenticationToken = new UsernamePasswordAuthenticationToken(username,password);
      return authenticationManager.authenticate(authenticationToken);
  }
  
  @Override 
  protected void successfulAuthentication(HttpServletRequest request, HttpServletResponse response, FilterChain chain, Authentication authentication) throws IOException,ServletException{
  
  User user = (User) authentication.getPrincipal();
  String name=userService.getName(user.getUsername()); //this method is tested and works but never here
  Algorithm algorithm = Algorithm.HMAC256(&quot;key&quot;.getBytes());
  String access_token = JWT.create()
  .withSubject(user.getUsername())
  .withExpiresAt(new Date(System.currentTimeMillis()+ 6 * 60*60*1000))
  .withIssuer(request.getRequestURI().toString())
  .withClaim(&quot;name&quot;, name)
  .withClaim(&quot;roles&quot;, user.getAuthorities().stream().map(GrantedAuthority::getAuthority).collect(Collectors.toList()))
  .sign(algorithm);
  
  String refresh_token = JWT.create()
  .withSubject(user.getUsername())
  .withExpiresAt(new Date(System.currentTimeMillis()+ 8 * 60*60*1000))
  .withIssuer(request.getRequestURI().toString())
  .sign(algorithm);
  
  
  Map&lt;String, String&gt; tokens = new HashMap&lt;&gt;();
  tokens.put(&quot;access_token&quot;, access_token);
  tokens.put(&quot;refresh_token&quot;, refresh_token);
  response.setContentType(APPLICATION_JSON_VALUE);
  new ObjectMapper().writeValue(response.getOutputStream(), tokens);
      }
  }
  </code></pre>