-
Notifications
You must be signed in to change notification settings - Fork 5.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
AnonymousConfigurer.authorities only accepts GrantedAuthorities but no subtypes of GrantedAuthorities #14435
Comments
@tobias-lippert thanks for reaching out! It looks like this has been an issue for some time. However, the use of It appears that
I'd argue that this should compile, but it does not. However, this does compile:
As a workaround, I recommend the use of
Alternatively, you can cast the entire stream like this:
In terms of a fix, we will need to check that changing the method signature does not break backwards compability. My initial instict right now is that such a change would be a breaking change, and as such would need to wait for the next major release. If you have any thoughts, please let me know. |
Thanks, @sjohnr, for your quick reply. I agree with you. I didn't know that breaking changes require a major release. I thought a minor release was sufficient, but since it's not critical but rather a nice-to-have improvement, I'm fine with waiting till a major release. Once you conclude if it's breaking or not and which release should be targeted, I'm happy to contribute a PR, so please keep me updated. |
Thanks @tobias-lippert.
That is a good point. However, the Anyway, I digress. 😃 Thanks for the reply! |
Expected Behavior
I expected the builder method of
AnonymousConfigurer.authorities(authorities)
to take aList<? extends GrantedAuthority> authorities
as parameterCurrent Behavior
AnonymousConfigurer.authorities(authorities)
takes aList<GrantedAuthority>
as parameterContext
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 aCollection<? 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
. UsingStream.toList()
to convert this stream of objects into an unmodifiable list results in aList<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
The text was updated successfully, but these errors were encountered: