Skip to content

Add PrincipalIdentifierStrategy to SessionRegistryImpl for custom principal matching#18794

Open
98001yash wants to merge 1 commit intospring-projects:mainfrom
98001yash:gh-18622-principal-identifier-strategy
Open

Add PrincipalIdentifierStrategy to SessionRegistryImpl for custom principal matching#18794
98001yash wants to merge 1 commit intospring-projects:mainfrom
98001yash:gh-18622-principal-identifier-strategy

Conversation

@98001yash
Copy link

This change introduces a pluggable PrincipalIdentifierStrategy
to SessionRegistryImpl to allow custom principal matching logic.

Currently, SessionRegistryImpl relies on equals() when determining
whether two principals represent the same user. In OAuth2/OIDC
scenarios, principal instances (e.g. DefaultOidcUser) may differ
across authentications due to varying attributes, causing
session management (such as maximumSessions) to treat the same
logical user as distinct principals.

This enhancement allows applications to provide a custom
PrincipalIdentifierStrategy to define logical identity matching,
while preserving the existing equals()-based behavior by default
for backward compatibility.

Tests have been added to verify:

  • Default behavior remains unchanged
  • Custom strategy correctly matches principals by logical identity

Fixes gh-18622

Signed-off-by: 98001yash <yashchauhan.gaya@gmail.com>
@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Feb 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

status: waiting-for-triage An issue we've not yet triaged

Projects

None yet

Development

Successfully merging this pull request may close these issues.

OAuth2 client sessionManagement ineffective with DefaultOidcUser

2 participants