weixin_33674976 2012-11-16 22:27 采纳率: 0%
浏览 44

Ajax和表单认证

I am trying to implement form authentication in my ajax application. The problem I have is that when the session expires I get 302 code which redirects me to a login page I specified in web.xml (and it messes everything up refreshing the whole app to login page).

What I want to do is to get a "not authenticated" (401) code, then display the login form in a popup window and when the login is successful continue with what I was doing.

here is a picture of what is going on: http://docs.oracle.com/javaee/1.4/tutorial/doc/images/security-formBasedLogin.gif

and the docs http://docs.oracle.com/javaee/1.4/tutorial/doc/Security5.html

basically, I want to display the popup instead of redirect to login page and then don't do the redirect to the resource but do my update in AJAX way. From what I understand it couldn't be done only on the client side since the redirect can't be avoided (see here: redirect info), I would need to write some kind of logic on the server to prevent redirect, see here for detail about doing it in IIS: IIS implementation

P.S. So far this: http://www.oracle.com/technetwork/articles/entarch/session-lifecycle-096133.html looks like the most promising way to implement it. The class is deprecated, but I can't find the new one and think it's the only way to do it for Weblogic.

  • 写回答

5条回答 默认 最新

  • 喵-见缝插针 2012-11-21 13:15
    关注

    This is not an easy way but still it works

    You have a form in your page which is filled by the user.

    User clicks submit button.

    An ajax request is sent to the server.

    The server side implementation can check whether session exists or not. and accordingly you can send a response code 401..(response.setStatus());

    This 401 can be checked in client side using ajax --- xhr.status

    If response is 401 you can show the login form and hide the current form. using js and css.

    User fills in the login details and clicks submit..

    You can do the same server side check and client side check for the status of that login request.

    if login is successful then you can you can submit the first form using ajax or js..

    评论

报告相同问题?

悬赏问题

  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料