Skip to content

SEC-1925: Access/check Spring Security hierarchical roles programmatically #2152

@spring-projects-issues

Description

@spring-projects-issues

Benjamin Muschko (Migrated from SEC-1925) said:

In my project I defined multiple hierarchical roles e.g. ROLE_USER > SOME_OTHER_ROLE. When securing controller methods using the @Secured annotation it works just fine. However, I also would like to check the role programmatically in my code for one use case. Using the following approach I always get a false even though the user inherits the role through hierarchical role definition:

SecurityContextHolderAwareRequestWrapper#isUserInRole(String)

Also getting the roles via SecurityContextHolder.getContext().getAuthentication().getAuthorities() doesn't give me the hierarchical roles. I'd expect them to be retrieved as well.

This might be a bug in SecurityContextHolderAwareRequestWrapper. Right now I am using this method to make it work:

RoleVoter#extractAuthorities(Authentication)

Metadata

Metadata

Assignees

Labels

in: coreAn issue in spring-security-corestatus: invalidAn issue that we don't feel is validtype: bugA general bugtype: 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