-
Notifications
You must be signed in to change notification settings - Fork 6k
Allow in-memory authorized client services to be constructed with a map #5994
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
Allow in-memory authorized client services to be constructed with a map #5994
Conversation
...n/java/org/springframework/security/oauth2/client/InMemoryOAuth2AuthorizedClientService.java
Outdated
Show resolved
Hide resolved
3b16c5e
to
32557ff
Compare
I've updated this PR with a commit that that adds Please take a quick look before I get any further with this. The thing is that the only consumer of |
32557ff
to
68800e7
Compare
@vpavic While I'm open to considering updating the APIs to use Thoughts? |
I agree it's better to handle that separately. I'm going to update this PR with that in mind, and open a new one to consider API changes once this (i.e. |
68800e7
to
143a6d9
Compare
I've updated the PR. |
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.
Thanks for the updates. I have commented inline.
...rg/springframework/security/oauth2/client/InMemoryReactiveOAuth2AuthorizedClientService.java
Show resolved
Hide resolved
* @param clientRegistrationRepository the repository of client registrations | ||
*/ | ||
public InMemoryOAuth2AuthorizedClientService(ClientRegistrationRepository clientRegistrationRepository) { | ||
public InMemoryOAuth2AuthorizedClientService( | ||
Map<OAuth2AuthorizedClientId, OAuth2AuthorizedClient> authorizedClients, |
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.
Given Map is an optional parameter, I'd prefer it to be exposed via a setter. I understand that means it is mutable object, but this is the typical pattern Spring uses.
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 agree with @rwinch that we should expose via setter instead - Map
should be optional. Also, this object is mutable anyway given saveAuthorizedClient
and removeAuthorizedClient
.
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.
@vpavic Apologies for back-tracking my previous comment but what are your thoughts on removing the setter and adding a 2nd constructor for both ClientRegistrationRepository
and the Map
?
*/ | ||
public static OAuth2AuthorizedClientId create(ClientRegistration clientRegistration, | ||
String principalName) { | ||
return new OAuth2AuthorizedClientId(clientRegistration.getRegistrationId(), |
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.
We should Assert.notNull
on clientRegistration
and Assert.hasText
on principalName
. Applying this update would than make Assert.notNull
redundant in OAuth2AuthorizedClientId
constructor.
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 think the parameter ClientRegistration clientRegistration
should be changed to String clientRegistrationId
, which aligns with OAuth2AuthorizedClientService.loadAuthorizedClient(String clientRegistrationId, String principalName)
.
I'm also curious on why this factory method is needed? Alternatively, we can make the constructor public
. What are your throughts?
public int hashCode() { | ||
return Objects.hash(this.clientRegistrationId, this.principalName); | ||
} | ||
|
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.
It might be useful to implement toString
as well?
} | ||
|
||
@Test | ||
public void equalsWhenDifferentRegistrationIdAndSamePrincipalThenShouldReturnTrue() { |
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.
This method name should be changed to equalsWhenDifferentRegistrationIdAndSamePrincipalThenShouldReturnFalse
} | ||
|
||
@Test | ||
public void equalsWhenSameRegistrationIdAndDifferentPrincipalThenShouldReturnTrue() { |
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.
This method name should be changed to equalsWhenSameRegistrationIdAndDifferentPrincipalThenShouldReturnFalse
} | ||
|
||
@Test | ||
public void hashCodeWhenDifferentRegistrationIdAndSamePrincipalThenShouldReturnTrue() { |
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.
This method name should be changed to hashCodeWhenDifferentRegistrationIdAndSamePrincipalThenNotEqual
} | ||
|
||
@Test | ||
public void hashCodeWhenSameRegistrationIdAndDifferentPrincipalThenShouldReturnTrue() { |
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.
This method name should be changed to hashCodeWhenSameRegistrationIdAndDifferentPrincipalThenNotEqual
|
||
/** | ||
* Factory method for creating new {@link OAuth2AuthorizedClientId} using | ||
* {@link ClientRegistration} and {@link Authentication}. |
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.
{@link Authentication}
should be -> the principal name
143a6d9
to
699347d
Compare
699347d
to
09d07ae
Compare
Since RC1 is around the corner, heads-up that reactive bits of #5918 need to get reverted. Or maybe all of it, if this PR doesn't make the cut. |
@vpavic Assuming we merge this PR and revert the reactive bits in #5918, this will allow a What are your thoughts on this? This will ultimately introduce inconsistent implementations between the two which I'm not sure at this point is the right way to go. Given that you raised this issue to allow for a distributed |
I'm afraid I won't have time to revisit this and the #5918 partial revert as I'm quite occupied by stuff for next Spring Session release so feel free to do what you feel is the best. Generally I'm interested primarily in Servlet side of the things (and have included reactive bits for completeness sake) so that inconsistency is fine with me. I also don't think inconsistency should be the reason for not providing something that's supporting a perfectly valid (and IMO needed) use case for Servlet based implementation. Also I'll express a concern that I've already express in other places, which I believe is important and is the motivation for this and other related PRs - all the store-like interfaces in new Spring Security OAuth 2.0 are only supported by in-memory implementations, and that's IMO something that you typically don't want to be running in production. |
@vpavic No worries if you don't have the time...totally understand. I'll take care of the remaining work.
Ok I don't see any issues on merging the changes for Servlet.
Totally agreed and yes the in-memory implementations are meant for development only. It's up to the user to define Thanks again for the reminder on this ticket and #5918...it almost slipped through the cracks. |
This is the equivalent of #5918 only this time for
InMemoryOAuth2AuthorizedClientService
and its reactive counterpart.