title: Spring referer is null in login and won't redirect
body: <p>I have a Spring-boot app that use security. What I want is to redirect to the original URL requested. I needed to implement a custom SimpleUrlAuthenticationSuccessHandler so I have this code:</p>
  
  <pre><code>public class MySavedRequestAwareAuthenticationSuccessHandler extends SimpleUrlAuthenticationSuccessHandler {
  
  public MySavedRequestAwareAuthenticationSuccessHandler() {
      setUseReferer(true);
  }
  
  @Override
  public void onAuthenticationSuccess(HttpServletRequest request, HttpServletResponse response, Authentication authentication) {
  
  // do my stuff
  
              logger.info(getTargetUrlParameter()); // this is = '/'
              //logger.info(getDefaultTargetUrl()); // this is null
              redirectStrategy.sendRedirect(request, response, "/");
  }
  }
  </code></pre>
  
  <p>The problem is that after login is never redirecting to the referer. I had to add the <strong>redirectStrategy.sendRedirect(request, response, "/");</strong> part.</p>
  
  <p>In the LoginController, "Referer" in the header is always null when is redirected from spring security. If I put in the url "xxxx/login" the value is set. Not very useful:</p>
  
  <pre><code>@RequestMapping(value = {"/login"}, method = RequestMethod.GET)
  public ModelAndView login(HttpServletRequest request) {       
  
      String referer = request.getHeader("Referer");
      modelAndView.addObject ("referer", referer); // this is NULL
      //
      modelAndView.setViewName("login");
      return modelAndView;
  }
  </code></pre>
  
  <p>This is my security config:</p>
  
  <pre><code>http.authorizeRequests()
                  .antMatchers("/login").permitAll()
                  .antMatchers("/").authenticated()               
                  .and()
                  .csrf().disable()
                  .formLogin()
                  .loginPage("/login")
                  .failureHandler(customAuthenticationFailureHandler)
                  .usernameParameter("email")
                  .passwordParameter("password")
                  .successHandler(authenticationSuccessHandler)
                  .and()
                  .logout()
                  .logoutUrl("/logout")
                  .logoutSuccessUrl("/login?logged-out")
                  .and()
                  .exceptionHandling()
                  .accessDeniedPage("/access-denied")
  </code></pre>