@Autowired
public Filter authenticationFilter(AuthenticationManager authenticationManager, RequestCache requestCache) {
UsernamePasswordAuthenticationFilter authenticationFilter = new UsernamePasswordAuthenticationFilter();
authenticationFilter.setFilterProcessesUrl(applicationUrl("/j_spring_security_check"));
authenticationFilter.setAuthenticationManager(authenticationManager);
SavedRequestAwareAuthenticationSuccessHandler successHandler = new SavedRequestAwareAuthenticationSuccessHandler();
successHandler.setRequestCache(requestCache);
authenticationFilter.setAuthenticationSuccessHandler(successHandler);
authenticationFilter.setAuthenticationFailureHandler(new SimpleUrlAuthenticationFailureHandler(applicationUrl("/login?login_error=1")));
return authenticationFilter;
}