Skip to content

Replace SecurityContextHolder#addListener with SecurityContextHolder#setSecurityContextHolderStrategy #10226

@jzheaux

Description

@jzheaux

Since listening for security context changes happens at the strategy level, SecurityContextHolder#addListener leaks that abstraction.

Instead, let's replace addListener with setSecurityContextHolderStrategy and make ListeningSecurityContextHolderStrategy public. This will allow the listening support to remain with the strategy.

ListeningSecurityContextHolderStrategy should not need to peek the SecurityContext since the semantic difference between a null SecurityContext and one with a null Authentication is negligible.

An additional benefit to setSecurityContextHolderStrategy over addListener is that it simplifies removing a custom strategy that has references to objects that need garbage collecting.

Metadata

Metadata

Assignees

Labels

in: coreAn issue in spring-security-coretype: enhancementA general enhancement

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions