-
Notifications
You must be signed in to change notification settings - Fork 3
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
Please remove OAuth2AuthoritiesPopulator #7
Comments
@rwinch I provided similar feedback on this but unfortunately my feedback comments (in the commit) is gone since a forced rebase happened after the fact. Either way, we do need a way to extract authority information from the token and map it to 1 or more
Although, I'm not sure if I totally like the |
Why is this OAuth specific (the class name and type boundary)? More importantly, why do we even need the API? For now we should encapsulate the logic and extract it if/when necessary making sure to do so in a way that is not OAuth specific so it introducing the API has more meaning and flexibility. |
Yes, the type boundary. This can be
Give this use case, where a token has authority information in the attribute/claim called
The user wants to be able to map these authorities to How do you propose the user would do this if they don't have this |
A better wording is probably...why would this API need to be OAuth Specific? Is it possible/likely that we would want to extract authorities from other types of tokens (i.e. SAML, CAS)? If so, a generic type and bounds on the consuming class make a lot more sense.
This is suppose to be an absolute minimum PR. So I should emphasize my statement:
|
Of course it is. However, CAS has already been implemented and so has SAML. Are you proposing we standardize on a base class for I'm just not sure if this makes sense to me by opening things up to be more generic and re-useable. I don't see any issue with CAS, SAML and OAuth having their own base class for Token.
So what are the authorities going to look like on the |
Even if APIs have been written it doesn't mean that they wouldn't benefit from enhancements that can be done passively. This sort of change would be very easy to be passive. SAML is under a rewrite too. However, it could easily be bound by Authentication or a specific token type too. The most important thing is that this PR is suppose to be absolute minimal. I'm not saying we don't add this functionality ever. What I'm saying is that we can provide the MVP with the code encapsulated. So my suggestion is to put this off until later. |
As far as this comment goes:
What will be the |
The result JwtAuthentication (and authorities) will be the same as they are today. We will just avoid exposing a new interface/implementation and instead encapsulate the logic. |
I don't agree that this should be excluded from the initial PR. Providing an easy way for a user to hook into custom authorities extracting/mapping is needed. And having them implement an I can agree to leave this out of the 1st PR. However, I'm assuming we will provide this capability in 5.1. Is this your expectation as well? |
Yes. I think leaving it out will help a lot. I think there is going to be a lot of back and forth on this API (there already has) so I'd like a PR focused on that. |
Ok makes sense. I'll add that to the list of PR's |
Just adding a few comments that I hadn't seen posted yet. @jgrandja already referred to the general circumstance, where we need to derive authorities in a custom way. Specifically, this is the result of research around Keycloak's use cases. Note a related ticket from the sandbox: jzheaux/spring-security-oauth2-resource-server#37 The Authorities Populator is simply a renaming in order to accommodate the extended contract advocated therein. In that issue, @rwinch, I believe I understood you when you said:
Derived from this comment, we have Originally, the name was In the 2 implementations of this class that I did ( Regarding your point about when to introduce this. I suppose it comes down to a growing clarity of what this particular PR is about. In the five PRs we discussed, I don't see one where this feature would be added, and yet it is, indeed, necessary in order to support Keycloak's use case. For that reason, I've included it in this PR, though I don't mind deferring it. There is a minor problem with embedding it in the AuthenticationProvider, and that is scope attribute name configuration. For us to correctly transform scopes into authorities, we need to know the name of the scope attribute. Originally, the AuthenticationProvider held the property for scope attribute name, and thus a setter. Now, with Authorities Populator, the scope attribute name is configured there instead. So, if we first place it in AuthenticationProvider, then we now have a public setter (scope attribute name) in AuthenticationProvider that we cannot remove, even though we know (accepting my premise from above) that is not where it will land. There are two options for how we could avoid this, as I see it:
So, long story short, I am asking two questions and proposing one thing: Q: @rwinch, can you clarify what you meant in jzheaux/spring-security-oauth2-resource-server#37? Do you still advocate a EDIT: disregard my second question as I missed the tail-end comments about adding a PR. |
Summary
I see a few problems with
OAuth2AuthoritiesPopulator
I believe we should remove
OAuth2AuthoritiesPopulator
. We do not need this yet. It should be encapsulated withinAuthenticationProvider
. In the end this API is probably not necessary. The current API takes an Authentication and returns an Authentication which means this could be accomplished using theAuthenticationProvider
interface and delegating to anotherAuthenticationProvider
and then modifying theAuthentication
. This is also more flexible since it would work with anyAuthenticationProvider
API vs justJwtAuthenticationProvider
.The method name
populateAuthorities
does not lend to be very flexible. The method accepts anAuthentication
and returns anAuthentication
which means it could totally transform theAuthentication
type. With the input/output of Authentication, the interface and method name should be named to AuthenticationMapper or something like that.As stated above
OAuth2AuthoritiesPopulator
is a bit limiting. Why is this an OAuth specific API?The current implementation of OAuth2AuthoritiesPopulator just transforms the roles and provides new roles. This means we could leverage
GrantedAuthoritiesMapper
. Alternatively, (preferred for first iteration) I would encapsulate the logic inside theJwtAuthenticationProvider
and we can extract it out later.The text was updated successfully, but these errors were encountered: