Skip to content

SEC-1667: Consider adding a method to SecurityContextHolderStrategy that returns the current state of the SecurityContext without creating a new one #1890

Closed
@spring-projects-issues

Description

@spring-projects-issues

Kyrill Alyoshin (Migrated from SEC-1667) said:

We do have scenarios when we have to call SecurityContextHolder#getContext outside of web requests. (Obviously, the context will not be populated in such cases.) What will happen though is a new empty SecurityContext will be created and put on a ThreadLocal without being cleared by the servlet filter (as is the case during web requests). This will, of course, lead to class loader based memory leaks on hot redeploys.

It sure would be nice to add, say, getExistingContext() method to SecurityContextHolderStrategy, which would not create a context if it is not available, and just return an existing one or null otherwise. Then we can call SecurityContextHolder.getContextHolderStrategy().getExistingContext() and
we're safe.

What do you think?

Metadata

Metadata

Assignees

Labels

in: coreAn issue in spring-security-corestatus: declinedA suggestion or change that we don't feel we should currently applytype: enhancementA general enhancementtype: jiraAn issue that was migrated from JIRA

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions