Remember me
Implementing the remember me option
<http auto-config="true" use-expressions="true" access-decisionmanager-
ref="affirmativeBased">
…
<remember-me key="jbcpPetStore"/>
<logout invalidate-session="true" logout-success-url="/" logouturl="/
logout"/>
</http>
Edit the login.jsp file to add a checkbox similar to the following:
<input id="_spring_security_remember_me" name="_spring_security_
remember_me" type="checkbox" value="true"/>
<label for="_spring_security_remember_me">Remember Me?</label>
<br />
How remember me works
The remember me feature sets a cookie on the user's browser containing a Base64 encoded string with the following pieces:
The user's username
An expiration date/time
An MD5 hash of the expiration date/time, username, and password
The application key defined in the key attribute of the <remember-me> element
MD5 is one of several well-known cryptographic hash algorithms. Cryptographic hash algorithms compute a compact and unique text representation of input data with arbitrary length, called a digest. This digest can be used at other times to verify that unknown input precisely matches the input used to generate the hash, without requiring the availability of the original input. The following diagram illustrates how this works:
Although it is impossible to decode the encrypted data, MD5 is vulnerable to several types of attacks, including the exploit of weaknesses in the algorithm itself and rainbow table attacks. Rainbow tables typically contain the pre-computed hashes of millions of input values. This allows attackers to look for the hash value in the rainbow table and determine the actual (unhashed) value. We'll see a method of combating this in Chapter 4, Securing Credential Storage, when we review password security.
虽然我们不可能解码数据,但是MD5也是有弱点的,比如暴露简单的算法和打表攻击。打表法就是包括非常多的输入值,然后对比结果。
In the case of the remember me cookie, the o.s.s.web.authentication. rememberme.RememberMeAuthenticationFilter inserted into the filter chain by the <remember-me> configuration directive will review the contents of the cookie and use it to authenticate the user if it seems to be an authentic remember me cookie (see the Is remember me secure? section later in this chapter for reasons why this is done).
The following diagram illustrates the different components involved in the process of validating a remember me cookie:
The RememberMeAuthenticationFilter is inserted into the filter chain just after the SecurityContextHolderAwareRequestFilter, and just before the AnonymousProcessingFilter. Just as the other filters in the chain do, the RememberMeAuthenticationFilter will also inspect the request, and if it is of interest, action is taken.
Remember me and the user lifecycle
it can be helpful to be aware of the points in time when remember me services are informed of lifecycle functions:
Remember me configuration directives
Two configuration changes are commonly made to alter the default behavior of the remember me functionality:
As you may infer from the discussion of how the cookie contents are hashed, the key attribute is critical to security of the remember me feature. Make sure that the key you choose is likely to be unique to your application, and long enough so that it can't be easily guessed.
Configuration of remember me session cookies
If token-validity-seconds is set to -1, the login cookie will be set to a session cookie, which does not persist after the user closes their browser. The token will be valid (assuming the user doesn't close their browser) for a non-configurable length of 2 weeks. Don't confuse this with the cookie that stores your user's session ID—they're two different things with similar names!
Is remember me secure?
Any feature related to security that has been added for user convenience has the potential to expose a security risk to our carefully protected site. The remember me feature, in its default form, runs the risk of the user's cookie being intercepted and reused by a malicious user. The following diagram illustrates how this might happen:
Use of SSL (covered in Chapter 4) and other network security techniques can mitigate this type of attack, but be aware that there are other techniques such as cross-site scripting (XSS) that could steal or compromise a remembered user session. While convenient for the user, we don't want to risk financial or other personal information being inadvertently changed or possibly stolen if the remembered session is misused..
Building an IP-aware remember me service
The basic approach for this implementation is to extend the o.s.s.web. authentication.rememberme.TokenBasedRememberMeServices base class and extend it to allow for the addition of the requestor's IP address to both the cookie itself, and to the MD5 hash of the other remember me factors.
Extending the base class will involve overriding two key methods, and overriding or implementing some very minor helper methods. One other twist is that we'll have to temporarily store the HttpServletRequest (which we use to get the user's IP address) into a ThreadLocal, as some of the base class methods don't take HttpServletRequest as a parameter.
Extending TokenBasedRememberMeServices
- 大小: 32.2 KB
- 大小: 44.3 KB
- 大小: 18.6 KB
- 大小: 23.5 KB
- 大小: 21.3 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...
3. **局部增强**:根据连通组件分析的结果,在每个子区域内应用不同的增强策略,如局部直方图均衡化等。 4. **全局增强**:在整个图像范围内进行全局直方图均衡化,确保整体对比度的一致性和平衡。 5. **结果融合**...
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...
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 ...
You have helped many people before me to create comprehensive plans for website projects for the purpose of enhancing user experience and meeting business goals. Your task is now to teach me how to ...
根据提供的文件内容,本文档是一篇关于在多目标进化算法中增强倒置PBI标量化方法鲁棒性的研究论文。在这篇论文中,作者通过研究和改进多目标进化算法中的一个特定变体,即MOEA/D(多目标进化算法/分解),来提高其在...
The two appendices provide additional resources and a commentary on the guide itself, enhancing the learning experience and encouraging exploration beyond the textbook. In conclusion, the "MATLAB ...
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 ...
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 ...
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...
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 ...
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 ...