0

I am trying the following ajax call to login to spring

$.ajax({

url: "http://localhost:8080/context/j_spring_security_check",    

      data: { j_username: 'user_name' , j_password: 'user_pass' }, 
      type: "POST",
      beforeSend: function (xhr) {
         xhr.setRequestHeader("X-Ajax-call", "true");
      },
      success: function(result) {       
      // ..


},
error: function(XMLHttpRequest, textStatus, errorThrown){
    $("#ajax_login_error_" ).html("Bad user/password") ;
    return false; 
}
});

This is doesn't work, because the username and password are not passed to the UsernamePasswordAuthenticationFilter. When I debug the request they are both null. In other cases when I login, I can see my user name and password in this filter.

Nabil Sham
  • 2,185
  • 4
  • 24
  • 37

2 Answers2

0

give exception for path (j_spring_security_check) in security filter as

final String contextName = ((HttpServletRequest) request).getContextPath();
final String requestURI = ((HttpServletRequest) request).getRequestURI();
if (requestURI.equals(contextName+"/j_spring_security_check"){
           chain.doFilter(request, response);
}

That means you should give exception for login url

JESTIN6699
  • 49
  • 4
0

You need to override SimpleUrlAuthenticationSuccessHandler. See similar questions here

Community
  • 1
  • 1
  • The execution doesn't get to SimpleUrlAuthenticationSuccessHandler, since we do not have username/password in UsernamePasswordAuthenticationFilter at attemptAuthentication – Nabil Sham Apr 21 '15 at 15:25