title: Spring Security custom authentication failure handler redirect with parameter
body: <p>I have a problem with Spring Security authentication failure handler redirect with parameter. </p>
  
  <p>In security config when I use </p>
  
  <pre class="lang-java prettyprint-override"><code>failureUrl("/login.html?error=true")
  </code></pre>
  
  <p>it works. But when I use custom authentication failure handler (as shown below), it always returns: <code>url/login.html</code></p>
  
  <pre class="lang-java prettyprint-override"><code>getRedirectStrategy().sendRedirect(request, response, "/login.html?error=true");
  </code></pre>
  
  <p>or </p>
  
  <pre class="lang-java prettyprint-override"><code>response.sendRedirect(request.getContextPath() + "/login.html?error=true");
  </code></pre>
  
  <p>I don't know whats wrong. Why does it not show the parameter <code>?error=true</code>?</p>
  
  <p>Info: I am using Spring + JSF + Hibernate + Spring Security</p>
  
  <pre class="lang-java prettyprint-override"><code>@Override
  protected void configure(HttpSecurity http) throws Exception {
  
      http
          .authorizeRequests()
              .anyRequest().authenticated()
              .and()
          .formLogin()
              .loginPage("/login.html")
              .usernameParameter("j_username")
              .passwordParameter("j_password")
              .loginProcessingUrl("/j_spring_security_check")
              .failureHandler(customAuthenticationFailureHandler)// .failureUrl("/login.html?error=true")//.successHandler(authSuccsessHandler)
              .defaultSuccessUrl("/dashboard.html")
              .permitAll()
              .and()
          .logout()
              .invalidateHttpSession(true)
              .logoutSuccessUrl("/")
              .permitAll()
              .and()
          .exceptionHandling()
              .accessDeniedPage("/access.html")
              .and()
          .headers()
              .defaultsDisabled()
              .frameOptions()
              .sameOrigin()
              .cacheControl();
  
      http
          .csrf().disable();
  }
  </code></pre>
  
  <p>This is custom authentication failure handler:</p>
  
  <pre class="lang-java prettyprint-override"><code>@Component
  public class CustomAuthFailureHandler extends SimpleUrlAuthenticationFailureHandler {
  
      @Override
      public void onAuthenticationFailure(HttpServletRequest request, HttpServletResponse response,
              AuthenticationException exception) throws IOException, ServletException {
          getRedirectStrategy().sendRedirect(request, response, "/login.html?error=true");
  
      }
  }
  </code></pre>
  
  <p>I will change parameter for some cases.</p>