Skip to content

AnonymousConfigurer.authorities only accepts GrantedAuthorities but no subtypes of GrantedAuthorities #14435

Open
@tobias-lippert

Description

@tobias-lippert

Expected Behavior

I expected the builder method of AnonymousConfigurer.authorities(authorities) to take a List<? extends GrantedAuthority> authorities as parameter

Current Behavior

AnonymousConfigurer.authorities(authorities) takes a List<GrantedAuthority> as parameter

Context
As of now, I cannot think of a reason to not allow subtypes of GrantedAuthorities.
E.g., when creating a new User, one can specify a Collection<? extends GrantedAuthority>

How has this issue affected you?
We converted a list of Strings to GrantedAuthorities but since this is an interface type, we created objects of type SimpleGrantedAuthority. Using Stream.toList() to convert this stream of objects into an unmodifiable list results in a List<SimpleGrantedAuthority>.

What are you trying to accomplish?
Directly using a List<SimpleGrantedAuthority> to avoid any casting.

What other alternatives have you considered?
Cast the list elements, so the list elements have the correct type.

Are you aware of any workarounds?
See above

I'm happy to contribute a PR if this is accepted

Metadata

Metadata

Assignees

Labels

in: configAn issue in spring-security-configtype: enhancementA general enhancement

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions