title: Spring boot + JWT Authorization header is not persisting to provide to subsequent requests
body: <p>I'm developing an application with Spring boot and implemented authentication with JWT. When I test the API with postman I can see it creates the Authorization header and when manually post it to header subsequent rest calls work without any issue. But when I do the rest calls from my JavaFX application, I can see the token created by the login rest call but subsequent rest calls fail with 403 forbidden status code. When I debug, The issue is when the JWTAuthFilter(which was implemented by extending GenericFilterBean) tries to get the Authorization header to pass that to subsequent rest calls, it returns null.</p>
  
  <pre><code>String token = request.getHeader(HEADER_STRING);
  </code></pre>
  
  <p>request.getHeader(HEADER_STRING) always returns null.</p>
  
  <pre><code>/**
  * WebSecurityConfig
  */
  class WebSecurityConfig extends WebSecurityConfigurerAdapter {
  
      @Autowired
      UserRepository userRepository;
  
      @Override
      protected void configure(HttpSecurity http) throws Exception {
          http.csrf().disable().authorizeRequests()
                  .antMatchers("/").permitAll()
                  .antMatchers(HttpMethod.POST, "/rest/login").permitAll()
                  .anyRequest().authenticated()
                  .and()
                  // We filter the rest/login requests
                  .addFilterBefore(new JWTLoginFilter("/rest/login", authenticationManager()),
                          UsernamePasswordAuthenticationFilter.class)
                  // And filter other requests to check the presence of JWT in header
                  .addFilterBefore(new JWTAuthFilter(),
                          UsernamePasswordAuthenticationFilter.class);
      }
  
  
  /**
  * JWTAuthFilter
  */
  public class JWTAuthFilter extends GenericFilterBean {
      @Override
      public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
          Authentication authentication = TokenAuthenticationService.getAuthentication((HttpServletRequest) request);
          SecurityContextHolder.getContext().setAuthentication(authentication);
          chain.doFilter(request, response);
      }
  }
  
  /**
  * TokenAuthenticationService
  */
  public class TokenAuthenticationService {
  
      static final long EXPIRATIONTIME = 864_000_000; // 10 days
      static final String SECRET = "ThisIsASecret";
      static final String TOKEN_PREFIX = "Bearer";
      static final String HEADER_STRING = "Authorization";
  
      static void addAuthentication(HttpServletResponse res, String username) {
          String JWT = Jwts.builder()
                  .setSubject(username)
                  .setExpiration(new Date(System.currentTimeMillis() + EXPIRATIONTIME))
                  .signWith(SignatureAlgorithm.HS512, SECRET)
                  .compact();
          res.addHeader(HEADER_STRING, TOKEN_PREFIX + " " + JWT);
      }
  
      static Authentication getAuthentication(HttpServletRequest request) {
          String token = request.getHeader(HEADER_STRING);
          if (token != null) {
              // parse the token.
              String user = Jwts.parser()
                      .setSigningKey(SECRET)
                      .parseClaimsJws(token.replace(TOKEN_PREFIX, ""))
                      .getBody()
                      .getSubject();
  
              return user != null ?
                      new UsernamePasswordAuthenticationToken(user, null, emptyList()) :
                      null;
          }
          return null;
      }
  }
  </code></pre>