-1

The requirement is that when the JSP page is submitted with action as "test/login",then below method will call and it check the validity and if it success, it must redirect to CustomSuccess hanlder, but it is not working.

Controller:

@RequestMapping("test/login")
public String login(Map<String, Object> model, HttpServletRequest request) {
    String userName = (String) request.getParameter("username");
    String password = (String) request.getParameter("password");
    Authentication authentication =authenticationProvider.authenticate(new UsernamePasswordAuthenticationToken(userName, password));
}

Configuration:

 protected void configure(HttpSecurity http) throws Exception {
     .authorizeRequests()
     .antMatchers("/test/**"))
     .permitAll()
     .and()
     .formLogin()
        .loginPage("/login")
        .failureHandler(mainSuccessHandler)
        .permitAll()    
}

Handler:

     @Bean(name = "mainSuccessHandler")
     public AuthenticationSuccessHandler mainSuccessHandler(
     @Qualifier("defaultSuccessHandler") AuthenticationSuccessHandler   defaultSuccessHandler
     CustomAuthenticationSuccessHandler result = new     CustomAuthenticationSuccessHandler();
     result.addAuthenticationFailureHandler(anyRefererRequestMather(), defaultSuccessHandler);
        return result;
    }
Slava Semushin
  • 14,904
  • 7
  • 53
  • 69
Dileep
  • 1
  • 1
  • 3
    Possible duplicate of [AuthenticationSuccessHandler in spring mvc java based configuration](http://stackoverflow.com/questions/28923281/authenticationsuccesshandler-in-spring-mvc-java-based-configuration) – Andrei Epure May 19 '17 at 11:36

1 Answers1

0

You're using the success handler as failure handler. Try

.successHandler(mainSuccessHandler) 
Andrei Epure
  • 1,746
  • 1
  • 21
  • 30