mirror of
https://github.com/spring-projects/spring-security.git
synced 2025-05-30 16:52:13 +00:00
Advise Overriding equals() and hashCode() in UserDetails Implementations
This commit adds a documentation note explaining the importance of overriding equals() and hashCode() in custom UserDetails implementations. The default SessionRegistryImpl in Spring Security uses an in-memory ConcurrentMap<Object, Set<String>>, Map<String,SessionInformation> to associate principals with sessions. If a custom UserDetails class does not properly override equals() and hashCode(), user sessions may not be tracked or matched correctly. I believe this helps developers avoid subtle session management issues when implementing custom authentication logic. Signed-off-by: Gurunathan <129361658+Gurunathan16@users.noreply.github.com>
This commit is contained in:
parent
5da31ab8a8
commit
a4cd6f4278
@ -534,6 +534,13 @@ public class MaximumSessionsPreventLoginTests {
|
||||
If you are using a customized authentication filter for form-based login, then you have to configure concurrent session control support explicitly.
|
||||
You can try it using the {gh-samples-url}/servlet/spring-boot/java/session-management/maximum-sessions-prevent-login[Maximum Sessions Prevent Login sample].
|
||||
|
||||
[NOTE]
|
||||
=====
|
||||
If you are using a custom implementation of `UserDetails`, ensure you override the **equals()** and **hashCode()** methods.
|
||||
The default `SessionRegistry` implementation in Spring Security relies on an in-memory Map that uses these methods to correctly identify and manage user sessions.
|
||||
Failing to override them may lead to issues where session tracking and user comparison behave unexpectedly.
|
||||
=====
|
||||
|
||||
== Detecting Timeouts
|
||||
|
||||
Sessions expire on their own, and there is nothing that needs to be done to ensure that a security context gets removed.
|
||||
|
Loading…
x
Reference in New Issue
Block a user