-
Notifications
You must be signed in to change notification settings - Fork 6.2k
Use more specific GrantedAuthority for mapped roles #5941
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
Conversation
|
Thanks for the PR! I'm sorry but after looking at this PR I think I have steered you in the wrong direction. There is a lot of code duplication and it doesn't solve the problem for NestedLdapAuthoritiesProvider which leads me to think we need a better solution. I'm wondering if the existing DefaultLdapAuthoritiesProvider could have a ContextMapper (or something similar) injected into it that determines the type that is extracted out. I haven't been able to look into this extensively, but I feel like that might be the best (and most flexible) approach. Thoughts? |
|
Yeah, I agree we need a better solution. One might be introducing a mapper as you said in var populator = new DefaultLdapAuthoritiesPopulator();
populator.setAuthorityMapper(record -> {
var roleDn = record.get(SpringSecurityLdapTemplate.DN_KEY).get(0);
var role = record.get(this.groupRoleAttribute).get(0);
return new LdapAuthority(role, roleDn);
});In either case When time comes for a breaking change then, the default mapper could be changed to return the more correct |
|
This seems more reasonable. Would you mind cleaning the PR to include tests and that there aren't unnecessary formatting changes introduced? |
|
I don't think I've introduced formatting changes (I just added a couple of missing blank lines). About tests, the existing test already covers the default mapping function, or am I missing something? |
My mistake on that. There was code changes there too. Please ignore.
Yes they do. However, it would be good to add a test to ensure that if a custom authority mapper is set, then the behavior changes (i.e. add a test for your specific use case of returning an LdapAuthority). Also add a test for setting a null mapper to ensure an exception is thrown. |
|
Test added! |
|
Thanks for the test! It appears the checkstyle is failing. Could you please run |
|
Fixed! It was a couple of unused imports, not sure how they ended up in a file I didn't modify in the latest push (and the previous passed the checks)! |
|
@rwinch not sure if anything is pending here from my side! |
|
@heruan thanks for the PR! The one test The other test Let me know if you can update the tests and we can get this PR merged. |
eleftherias
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have left a few comments on the tests.
...java/org/springframework/security/ldap/userdetails/DefaultLdapAuthoritiesPopulatorTests.java
Outdated
Show resolved
Hide resolved
...java/org/springframework/security/ldap/userdetails/DefaultLdapAuthoritiesPopulatorTests.java
Outdated
Show resolved
Hide resolved
|
Thank you @eleftherias for the hints, I'll fix the tests: let's see if they pass! |
|
@heruan The tests look good now, thank you. One last request, could you please squash your 2 commits into one. That will make the commit history clearer when this is merged. |
|
Done! I was confident they were going to be squashed on merge 🙂 |
|
Thanks for the PR @heruan! This is now merged into master. |
As discussed in #5929 this adds an implementation of
LdapAuthoritiesPopulatorwhich usesLdapAuthorityinstead or the genericSimpleGrantedAuthority.The new implementation shares the same code as the original so that the old one can be deprecated and then removed.
Keep in mind that
NestedLdapAuthoritiesProviderstill extendsDefaultLdapAuthoritiesProvider.Alternative
Change
DefaultLdapAuthoritiesPopulatorimplementation to useLdapAuthorityinstead ofSimpleGrantedAuthority: this would be a "breaking" change if and only if an existing logic is based on the fact that authorities from the populator are instances ofSimpleGrantedAuthorityand I can't figure out any case where this would make sense. Of course this will wait a next major, but would not introduce an additional implementation that might create confusion and introduce duplicated code.Fixes #5929