简体   繁体   English

会话注销/超时

[英]Session logout/ timeout

To make it short, here is the scenario: 简而言之,这里是场景:

  • The browser back button must be functional (I'm using JSF 2.0, so this is working) 浏览器的后退按钮必须正常工作(我使用的是JSF 2.0,因此可以正常工作)

  • After logout, if a user clicks the back button, the app must redirect him/her to the login page (not working, the user is able to view protected pages, although expired. I can´t include the meta tags to disable browser caching because the back button stops working) 注销后,如果用户单击“后退”按钮,则应用程序必须将他/她重定向到登录页面(无法使用,尽管过期,该用户仍可以查看受保护的页面。我无法包含用于禁止浏览器缓存的meta标签。因为后退按钮停止工作)

  • If the user invokes an action, by clicking a button, on one of the expired pages it should redirect him/her to the login or error page (not working, the app throws an error and shows a blank page. My ExceptionHandlerWrapper implementation detects the exception and it is using a NavigationHandler to change the viewId and render the response ("facesException" mapping on faces-config that points to login.jsf), but the app is not behaving as expected) 如果用户通过单击一个按钮在过期页面之一上调用操作,则应将他/她重定向到登录页面或错误页面(不起作用,该应用会引发错误并显示空白页面。我的ExceptionHandlerWrapper实现检测到异常,它正在使用NavigationHandler更改viewId并呈现响应(faces-config上指向“ login.jsf”的“ facesException”映射),但该应用程序的行为不符合预期)

Can someone please help me to solve this problem? 有人可以帮我解决这个问题吗?

  • The browser back button must be functional (I'm using JSF 2.0, so this is working) 浏览器的后退按钮必须正常工作(我使用的是JSF 2.0,因此可以正常工作)

  • After logout, if a user clicks the back button, the app must redirect him/her to the login page (not working, the user is able to view protected pages, although expired. I can´t include the meta tags to disable browser caching because the back button stops working) 注销后,如果用户单击“后退”按钮,则应用程序必须将他/她重定向到登录页面(无法使用,尽管过期,该用户仍可以查看受保护的页面。我无法包含用于禁止浏览器缓存的meta标签。因为后退按钮停止工作)

Two steps to solve this problem. 解决此问题的两个步骤。

  1. Disable browser cache by setting response headers accordingly. 通过相应地设置响应头来禁用浏览器缓存。 You can do this in a Filter which is mapped on the FacesServlet . 您可以在FacesServlet上映射的Filter执行此操作。

     HttpServletResponse hsr = (HttpServletResponse) response; hsr.setHeader("Cache-Control", "no-cache, no-store, must-revalidate"); // HTTP 1.1. hsr.setHeader("Pragma", "no-cache"); // HTTP 1.0. hsr.setDateHeader("Expires", 0); // Proxies. chain.doFilter(request, response); 
  2. Do not use HTTP POST for page-to-page navigation. 不要使用HTTP POST进行页面间导航。 Always use HTTP GET for page-to-page navigation. 始终使用HTTP GET进行页面间导航。 If you need to submit a form, let it submit to self (ie let action method return null or void ) and use h:messages or h:somecomponent rendered="#{success}" to display results in the same page conditionally. 如果您需要提交表单,请将其提交给self(即,让action方法返回nullvoid ),然后使用h:messagesh:somecomponent rendered="#{success}"在条件下在同一页面中显示结果。


  • If the user invokes an action, by clicking a button, on one of the expired pages it should redirect him/her to the login or error page (not working, the app throws an error and shows a blank page. My ExceptionHandlerWrapper implementation detects the exception and it is using a NavigationHandler to change the viewId and render the response ("facesException" mapping on faces-config that points to login.jsf), but the app is not behaving as expected) 如果用户通过单击一个按钮在过期页面之一上调用操作,则应将他/她重定向到登录页面或错误页面(不起作用,该应用会引发错误并显示空白页面。我的ExceptionHandlerWrapper实现检测到异常,它正在使用NavigationHandler更改viewId并呈现响应(faces-config上指向“ login.jsf”的“ facesException”映射),但该应用程序的行为不符合预期)

An <error-page> on javax.faces.webapp.ViewExpiredException was been enough. javax.faces.webapp.ViewExpiredException上使用<error-page>就足够了。 See also this answer . 另请参阅此答案

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM