-
Notifications
You must be signed in to change notification settings - Fork 6k
Replace stream with cycles #7182
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
Replace stream with cycles #7182
Conversation
1f12771
to
d9eadfb
Compare
...ava/org/springframework/security/oauth2/client/DelegatingOAuth2AuthorizedClientProvider.java
Outdated
Show resolved
Hide resolved
8d0c823
to
00d3d7b
Compare
Hello, @rwinch I think, it's ready for review. Now, you may review it. |
I updated changes from master. |
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.
@kostya05983 Thanks for the earlier updates!
I've added some additional inline feedback.
...ork/security/config/annotation/authentication/configuration/AuthenticationConfiguration.java
Outdated
Show resolved
Hide resolved
core/src/main/java/org/springframework/security/converter/RsaKeyConverters.java
Outdated
Show resolved
Hide resolved
...ava/org/springframework/security/oauth2/client/DelegatingOAuth2AuthorizedClientProvider.java
Outdated
Show resolved
Hide resolved
...ava/org/springframework/security/oauth2/client/DelegatingOAuth2AuthorizedClientProvider.java
Outdated
Show resolved
Hide resolved
...ava/org/springframework/security/oauth2/client/oidc/authentication/OidcIdTokenValidator.java
Outdated
Show resolved
Hide resolved
private static Map<String, ClientRegistration> toUnmodifiableConcurrentMap(List<ClientRegistration> registrations) { | ||
final ConcurrentHashMap<String, ClientRegistration> result = new ConcurrentHashMap<>(); | ||
for (ClientRegistration registration : registrations) { | ||
if (result.containsKey(registration.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.
Why is this check necessary?
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.
@jzheaux
When we use toConcurrentMap from Collectors, it uses uniqKeysMapAccumulator
/**
* {@code BiConsumer<Map, T>} that accumulates (key, value) pairs
* extracted from elements into the map, throwing {@code IllegalStateException}
* if duplicate keys are encountered.
*
* @param keyMapper a function that maps an element into a key
* @param valueMapper a function that maps an element into a value
* @param <T> type of elements
* @param <K> type of map keys
* @param <V> type of map values
* @return an accumulating consumer
*/
private static <T, K, V>
BiConsumer<Map<K, V>, T> uniqKeysMapAccumulator(Function<? super T, ? extends K> keyMapper,
Function<? super T, ? extends V> valueMapper) {
return (map, element) -> {
K k = keyMapper.apply(element);
V v = Objects.requireNonNull(valueMapper.apply(element));
V u = map.putIfAbsent(k, v);
if (u != null) throw duplicateKeyException(k, u, v);
};
}
I also add check to save logic with throwing an exception, if we find duplicate key. Maybe, I understand something wrong and logic with client Registration can just rewrite value, how do you think? Can we break something?
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.
Collisions aren't a concern in this case but thank you for keeping an eye on this.
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.
So, let's go ahead and remove this extra check and exception. Collisions aren't a concern here, @kostya05983
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.
Oks, also I need a remove test for it, because there is a test which checks duplicates.
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.
Removed
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.
@kostya05983 for some reason I'd missed that there is a test that relies on this functionality. I apologize, but because of that, we should add the duplicate checks as well as the test back in. My mistake.
...uth2-core/src/main/java/org/springframework/security/oauth2/core/user/DefaultOAuth2User.java
Outdated
Show resolved
Hide resolved
...springframework/security/oauth2/server/resource/web/BearerTokenAuthenticationEntryPoint.java
Outdated
Show resolved
Hide resolved
.../main/java/org/springframework/security/oauth2/core/endpoint/OAuth2AuthorizationRequest.java
Outdated
Show resolved
Hide resolved
fb07d3a
to
a0bf098
Compare
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, @kostya05983. I've left some additional feedback inline.
...c/main/java/org/springframework/security/core/userdetails/MapReactiveUserDetailsService.java
Outdated
Show resolved
Hide resolved
...c/main/java/org/springframework/security/core/userdetails/MapReactiveUserDetailsService.java
Outdated
Show resolved
Hide resolved
private static Map<String, ClientRegistration> toUnmodifiableConcurrentMap(List<ClientRegistration> registrations) { | ||
final ConcurrentHashMap<String, ClientRegistration> result = new ConcurrentHashMap<>(); | ||
for (ClientRegistration registration : registrations) { | ||
if (result.containsKey(registration.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.
Collisions aren't a concern in this case but thank you for keeping an eye on this.
...pringframework/security/oauth2/client/registration/InMemoryClientRegistrationRepository.java
Outdated
Show resolved
Hide resolved
...mework/security/oauth2/client/registration/InMemoryReactiveClientRegistrationRepository.java
Outdated
Show resolved
Hide resolved
...uth2-core/src/main/java/org/springframework/security/oauth2/core/user/DefaultOAuth2User.java
Show resolved
Hide resolved
...in/java/org/springframework/security/web/server/header/CompositeServerHttpHeadersWriter.java
Show resolved
Hide resolved
...ava/org/springframework/security/web/server/header/ClearSiteDataServerHttpHeadersWriter.java
Outdated
Show resolved
Hide resolved
...ava/org/springframework/security/oauth2/client/DelegatingOAuth2AuthorizedClientProvider.java
Outdated
Show resolved
Hide resolved
...ava/org/springframework/security/oauth2/client/oidc/authentication/OidcIdTokenValidator.java
Outdated
Show resolved
Hide resolved
43eee30
to
da6f25c
Compare
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.
@kostya05983, thanks for how responsive you've been in this PR. You're nearly there!
I've left just a bit more feedback inline. Note that there are still a couple of open conversations from past reviews, too.
Once you believe everything is resolved, please squash your commits into one, in perparation for merging.
.../security/oauth2/server/resource/web/access/server/BearerTokenServerAccessDeniedHandler.java
Outdated
Show resolved
Hide resolved
@jzheaux Thanks for guidance. I think it's ready, but I tried to rebase and squash my nearest commits into one,in such groups: [Replace stream, First version of replacing streams, fix wwAuthentication and code style] and other similar group with other dates. But I got a big diff on test branch. Can you tell me how I can squash into one my commits which between others commits and not to danger history. I tried with interactive git rebase. |
To rebase, you can do something like (assuming that you've called Spring Security's upstream
You will likely have some conflicts to resolve, but at that point, the commits on your feature branch should be at the end of the chain. Once you've resolved the conflicts, then do (assuming your fork is called
|
7477224
to
203abbf
Compare
First version of replacing streams fix wwwAuthenticate and codestyle fix errors in implementation to pass tests Fix review notes Remove uneccessary final to align with cb Short circuit way to authorize Simplify error message, make code readably Return error while duplicate key found Delete check for duplicate, checkstyle issues Return duplicate error
203abbf
to
a47053a
Compare
@jzheaux , I squashed commits, it's ready for merge |
@kostya05983 - thank you for your careful work on this. This is now merged into I edited the commit message in order to align with the contributor guidelines. |
Work in progress, change streams to for loops. Please see #7154