Locally 401 Working, Staging Server getting a 302 instead

半世苍凉 提交于 2019-12-06 06:42:17

问题


I'm probably not going to get all the required info needed to help the first stab but I'll do the best I can and edit this as we go along.

I've got a Grails 1.3.7 application using Spring-Security-Core plugin. I'm working on code that deals with session timeouts and ajax requests. In the LoginController, I have the following:

def authAjax = {
    session.SPRING_SECURITY_SAVED_REQUEST_KEY = null
    response.sendError HttpServletResponse.SC_UNAUTHORIZED
}

In a global JavaScript file, I have the following:

$.ajaxSetup({
     error: function(xhr, status, err) {
       if (xhr.status == 401) {
         $('#login-dialog').dialog({ // show ajax login });
       }
     }
});

When I run this locally everything works as expected. When my session timesout, I see a 401 in FireBug console and I get the Login dialog. When I deploy this to our staging server, I'm only getting the 302 and never getting into authAjax therefor never getting the 401.

The main difference between local dev and staging is that I'm using mod_proxy with apache httpd to proxy the requests back and forth to Tomcat. My assumption is this is why I'm getting a 302 and not the 401 but I'm not 100% sure.

My question(s)

  1. Is the mod_proxy causing the 302
  2. How can I resolve this so that it works like it does locally, but still using mod_proxy.

UPDATE:

Per the recent comments, locally, when I get the 401 I am seeing this:

POST https://localhost:8080/admin/bookProject/edit 302 Moved Temporarily
GET http://localhost:8080/login/authAjax 401 Unauthorized

And I am seeing debug from the authAjax method

On the staging server I am getting:

POST https://server.com/admin/bookProject/edit 302 Moved Temporarily

And I am not seeing any debug from authAjax, so I'm not even getting there.


回答1:


Code for your Ajax call:

statusCode: {
    401: function(){
        // redirect code to login page
    }
}


来源:https://stackoverflow.com/questions/7017756/locally-401-working-staging-server-getting-a-302-instead

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!