Skip to content

Add PrincipalIdentifierStrategy to SessionRegistryImpl for custom principal matching#18794

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

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
Copy Markdown

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
@jgrandja
Copy link
Copy Markdown
Contributor

jgrandja commented Apr 2, 2026

@98001yash Thanks for the PR, however, gh-18622 requires a bug fix in DefaultOidcUser.

Closing this in favour of eefbb4d

@jgrandja jgrandja closed this Apr 2, 2026
@jgrandja jgrandja self-assigned this Apr 2, 2026
@jgrandja jgrandja added status: declined A suggestion or change that we don't feel we should currently apply in: oauth2 An issue in OAuth2 modules (oauth2-core, oauth2-client, oauth2-resource-server, oauth2-jose) and removed status: waiting-for-triage An issue we've not yet triaged labels Apr 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

in: oauth2 An issue in OAuth2 modules (oauth2-core, oauth2-client, oauth2-resource-server, oauth2-jose) status: declined A suggestion or change that we don't feel we should currently apply

Projects

None yet

Development

Successfully merging this pull request may close these issues.

OAuth2 client sessionManagement ineffective with DefaultOidcUser

3 participants