jquery - Ajax call to HTTPS failing -
i trying call spring-mvc controller responsible go ahead login/authorization mechanism using spring security.
here requirements
- spring security need have request https else throw error.
i followed following tutorial accomplish /implementing_ajax_authentication_using_jquery.
here piece of jquery code
jquery("#loginform").submit(function(e) { e.preventdefault(); jquery.ajax({ url: "https://localhost:9002/myapp/springsecurity/login.json", beforesend: function(xhr) { xhr.withcredentials = true; }, type: "post", data: jquery("#loginform").serialize(), datatype: 'application/json', success: function(data, status) { if (data.loggedin) { // location.href = gethost() + '${ctx}/users'; //login_pannel alert("jai ho"); } else { loginfailed(data); } }, error: loginfailed }); });
in order handle cross domain problem have created filter , placed in web.xml following entries
response.setheader("access-control-allow-origin", "http://" + req.getservername()); response.setheader("access-control-allow-methods", "get,post"); response.setheader("access-control-max-age", "360"); response.setheader("access-control-allow-headers", "x-requested-with"); response.setheader("access-control-allow-credentials", "true");
spring controller
@requestmapping(method = requestmethod.post) @responsebody public springsecurityloginstatus login(@requestparam("j_username") final string username, @requestparam("j_password") final string password, final httpservletrequest request, final httpservletresponse response) { log.info("starting login process"); return springsecurityloginservice.login(username, password, request, response); }
but undergoing strange problem, when hitting submit button, browser sending request secure url https://localhost:9002/myapp/springsecurity/login.json
controller method never getting called , in fact error saw in mozilla error console
after looking @ console seems browser calling again method seems redirect.
i not sure why happening , why browser doing redirect https http using request silently
here output mozila net pannel
response headersview source
access-control-allow-cred... true access-control-allow-head... x-requested-with access-control-allow-meth... get,post access-control-allow-orig... https://localhost access-control-max-age 360 content-length 0 date thu, 14 jun 2012 11:12:36 gmt location http://localhost:9001/myapp/springsecurity/login.json server apache-coyote/1.1 set-cookie _system.tenantid_=""; expires=thu, 01-jan-1970 00:00:10 gmt; path=/ request headersview source accept text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8 accept-encoding gzip, deflate accept-language en-us,en;q=0.5 connection keep-alive cookie jsessionid=26beeb7dc056d2a5f08d107e3d4bcddb; __atuvc=4|22; secureguid=60be684d748027c1f567eadead08f28771ab7d25; jsessionid=4e2300220697c799af4539abcb9108dd host localhost:9002 referer http://localhost:9001/myapp/ user-agent mozilla/5.0 (windows nt 6.1; wow64; rv:12.0) gecko/20100101 firefox/12.0
response headers cache
access-control-allow-cred... true access-control-allow-head... x-requested-with access-control-allow-meth... get,post access-control-allow-orig... https://localhost access-control-max-age 360 content-length 0 date thu, 14 jun 2012 11:12:36 gmt location http://localhost:9001/myapp/springsecurity/login.json server apache-coyote/1.1 set-cookie _system.tenantid_=""; expires=thu, 01-jan-1970 00:00:10 gmt; path=/
on side note if change url http://localhost:9001/myapp/springsecurity/login.json
i.e http protocol, able call controller.
respone class
public class springsecurityloginstatus { private final boolean loggedin; private final string username; public springsecurityloginstatus(final boolean loggedin, final string username) { this.loggedin = loggedin; this.username = username; } public boolean isloggedin() { return loggedin; } public string getusername() { return username; }
it looks haven't implemented 'get' method url 'login.json'.
if @ controller implements post
request method, request type get
why getting error.
can share return value of login
method?
it looks returning 302 moved temporarily
status login method.
Comments
Post a Comment