Roles and authorities are being overridden in GrantedAuthority and are not accessible within the AuthenticationManager. #17001
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
User Builder Class Authority Override Issue
Problem Description
The
User.builder()
class has an issue where data gets overridden depending on the order of method calls. Specifically, there's a conflict between the.authorities()
and.roles()
methods.Issue Demonstration
Scenario 1: Authorities Added First, Then Roles
java
Result:
authorities = ["ROLE_USER"]
Scenario 2: Roles Added First, Then Authorities
java
Result:
authorities = ["read", "item:view"]
Explanation
The issue occurs because both
.roles()
and.authorities()
methods modify the same underlying collection of authorities:.roles("USER")
is called, it converts the role to"ROLE_USER"
and sets it as the sole authority, overwriting any previous authorities..authorities("read", "item:view")
is called, it sets these values as the authorities, overwriting any previous authorities including those set by.roles()
.This behavior can lead to unexpected security configurations where permissions are accidentally overridden based on the order of builder method calls.