Understanding logout functionality
Adding a Log Out link to the site header
The signature URL for logging the user out is /j_spring_security_logout. Adding a logout link is really as simple as putting an anchor tag with the appropriate href in the header.jsp file:
<c:url value="/j_spring_security_logout" var="logoutUrl"/>
<li><a href="${logoutUrl}">Log Out</a></li>
How logout works
Remember that every request for a URL goes through the entire Spring Security filter chain, before being resolved to a servlet request. So, although the URL request for /j_spring_security_logout doesn't correspond to a JSP in our system, it doesn't have to be a real JSP or Spring MVC destination in order to be handled. These types of URLs are often referred to as
virtual URLs.
The URL request for
/j_spring_security_logout is intercepted by the o.s.s.web.authentication.logout.LogoutFilter. One of the many filters in the default Spring Security filter chain, the LogoutFilter looks for this particular virtual URL and takes action.
Let's quickly examine the configuration that the security namespace provides us with regards to
default logout functionality:
<http auto-config="true" use-expressions="true">
<logout invalidate-session="true"
logout-success-url="/"
logout-url="/j_spring_security_logout"/>
</http>
This baseline configuration will look for the logout URL specified in the logout url attribute and log the user out.
Logging the user out involves the following 3 steps:
1. Invalidating the HTTP session (if invalidate-session is set to true).
2. Clearing the SecurityContext (effectively logging the user out).
3. Redirecting to the URL specified in logout-success-url.
o.s.s.web.authentication.logout.LogoutHandler is an interface whose implementation classes can
be invoked upon user logout by the LogoutFilter. It is possible (although complex) to implement your own LogoutHandler that will be tied into the LogoutFilter lifecycle. The default set of LogoutHandlers that are configured with the LogoutFilter are responsible for clearing the session and cleaning up the remember me feature so that the user's session is now operating with no remaining authentication associated. Finally, the redirection to a URL after logout is performed by a default implementation of the interface o.s.s.web. authentication.logout.LogoutSuccessHandler. This default implementation simply redirects to the success URL configured (the default is /), but can be updated to perform anything else that your application needs to be done after the user is logged out. It is important to note that logout handlers should not throw exceptions, as it's important for all of them to execute to avoid potential inconsistency in the user's secured session. Take care that exceptions are properly handled and logged when implementing your own logout handlers.
Changing the logout URL
Let's test overriding the default logout URL to provide a simple example of modifying the automatically configured behavior. We'll change the logout URL to /logout.
<http auto-config="true" use-expressions="true">
...
..<logout invalidate-session="true"
logout-success-url="/"
logout-url="/logout"/>
</http>
Restart the application and try it out! You'll observe that instead of /j_spring_ security_logout, the /logout URL will be used to log the user out. You may also notice that if you try /j_spring_security_logout, you'll get a Page not Found (404) error, because the URL doesn't correspond to an actual servlet resource and is no longer handled by a request filter.
Logout configuration directives
- 大小: 43.3 KB
- 大小: 46.1 KB
分享到:
相关推荐
Enhancing the Integrity of the ICT OT Supply Chain
3. **双流CNN结构**:采用双流CNN,分别提取可见域和热域的行人特征,每个流学习特定模态的信息。随后,通过共享层将两种模态的特征融合到一个公共空间,使得模型能够理解多模态信息并生成共享特征。 【实验验证与...
优化后的Memcached应用展示了显著的线性扩展能力,与开源版本相比,在16核服务器上测试时,吞吐量提升了6倍,能效比提高了3倍以上,同时保持了服务质量协议的履行。基于核心数量扩展的结果,可以预见,优化后的...
Enhancing the Development Life Cycle benefited greatly from contributions and critiques by participants in the Software Assurance Forum. The Software Assurance Forum was established jointly by the DHS...
These kinds of effects provide ways of enhancing the user experience of the application through more attractive GUIs, dynamic effects that give your application a pulse, and animated transitions that...
3. **局部增强**:根据连通组件分析的结果,在每个子区域内应用不同的增强策略,如局部直方图均衡化等。 4. **全局增强**:在整个图像范围内进行全局直方图均衡化,确保整体对比度的一致性和平衡。 5. **结果融合**...
Enhancing the User Interface with Ajax CHAPTER 12. Extend Your Website with RSS and Facebook CHAPTER 13. Monitor Traffic and Manage Ads with Google CHAPTER 14. Accepting Online Payments with ...
In this paper, we describe an approach for enhancing the structural properties of similarity matrices based on two concepts: first, we introduce a new class of robust and scalable audio features ...
根据提供的文件内容,本文档是一篇关于在多目标进化算法中增强倒置PBI标量化方法鲁棒性的研究论文。在这篇论文中,作者通过研究和改进多目标进化算法中的一个特定变体,即MOEA/D(多目标进化算法/分解),来提高其在...
It explores the game's background, design principles, implementation, and the use of advanced graphical techniques to elevate the user experience. Through this project, the author demonstrates the ...
This could include improving the accuracy of the AI models, enhancing the user interface, or exploring new technologies like voice recognition. ### Overall, the document serves as a comprehensive ...
而今天我们要探讨的是一个能够进一步提升其效能的插件——Obsidian Enhancing Mindmap,它为用户提供了丰富的思维导图功能,让复杂的思考过程变得井然有序。 Obsidian Enhancing Mindmap是专为Obsidian设计的一款...
- The benefits of Ajax for enhancing user experience. - How Ajax can be used to create more responsive and interactive interfaces. **Chapter 2: First Steps with Ajax** - **Description**: This ...
The display settings allow users to adjust screen brightness and resolution, enhancing the viewing experience. Audio settings provide options for adjusting volume levels and equalizer settings. For TV...
5. **User Interface**: A user-friendly interface allows users to search, filter, and browse multimedia resources efficiently, enhancing the overall user experience. 6. **Security Measures**: The ...
By integrating with popular payment gateways, the system enables smooth and secure online payments, enhancing the customer experience. The system's requirements analysis focuses on understanding the...
The platform streamlines management processes, improves user experience, and adapts to the evolving demands of online shopping. Its implementation showcases the power of modern software engineering ...
- Improving the user experience for non-technical users. #### Processchaindetails (RSPCCHAIN) **Purpose:** This table provides detailed information about process chains, including the steps involved...
在当前的可再生能源领域,风能的利用已成为全球关注的焦点,而双馈感应发电机(DFIG)在风力发电系统中的应用尤为广泛。DFIG因其控制灵活性和效率优势,被大量采用在风力发电机组中。然而,DFIG对电网电压波动非常...