mirror of
https://github.com/spring-projects/spring-security.git
synced 2025-03-09 06:50:05 +00:00
Make saveAuthorizedClient save the authorized client
Previously, saveAuthorizedClient never actually saved the authorized client, because it ignored the Mono<Void> returned from authorizedClientRepository.saveAuthorizedClient. Now, it does not ignore the Mono<Void> returned from authorizedClientRepository.saveAuthorizedClient, and includes it in the stream, and therefore it will properly save the authorized client. Fixes gh-7546
This commit is contained in:
parent
d26f40f062
commit
8584b12c8d
@ -105,10 +105,8 @@ public final class DefaultReactiveOAuth2AuthorizedClientManager implements React
|
||||
private Mono<OAuth2AuthorizedClient> saveAuthorizedClient(OAuth2AuthorizedClient authorizedClient, Authentication principal, ServerWebExchange serverWebExchange) {
|
||||
return Mono.justOrEmpty(serverWebExchange)
|
||||
.switchIfEmpty(Mono.defer(() -> currentServerWebExchange()))
|
||||
.map(exchange -> {
|
||||
this.authorizedClientRepository.saveAuthorizedClient(authorizedClient, principal, exchange);
|
||||
return authorizedClient;
|
||||
})
|
||||
.flatMap(exchange -> this.authorizedClientRepository.saveAuthorizedClient(authorizedClient, principal, exchange)
|
||||
.thenReturn(authorizedClient))
|
||||
.defaultIfEmpty(authorizedClient);
|
||||
}
|
||||
|
||||
|
@ -36,6 +36,7 @@ import org.springframework.security.oauth2.core.TestOAuth2RefreshTokens;
|
||||
import org.springframework.security.oauth2.core.endpoint.OAuth2ParameterNames;
|
||||
import org.springframework.web.server.ServerWebExchange;
|
||||
import reactor.core.publisher.Mono;
|
||||
import reactor.test.publisher.PublisherProbe;
|
||||
import reactor.util.context.Context;
|
||||
|
||||
import java.util.Collections;
|
||||
@ -64,6 +65,7 @@ public class DefaultReactiveOAuth2AuthorizedClientManagerTests {
|
||||
private MockServerWebExchange serverWebExchange;
|
||||
private Context context;
|
||||
private ArgumentCaptor<OAuth2AuthorizationContext> authorizationContextCaptor;
|
||||
private PublisherProbe<Void> saveAuthorizedClientProbe;
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Before
|
||||
@ -74,8 +76,9 @@ public class DefaultReactiveOAuth2AuthorizedClientManagerTests {
|
||||
this.authorizedClientRepository = mock(ServerOAuth2AuthorizedClientRepository.class);
|
||||
when(this.authorizedClientRepository.loadAuthorizedClient(
|
||||
anyString(), any(Authentication.class), any(ServerWebExchange.class))).thenReturn(Mono.empty());
|
||||
this.saveAuthorizedClientProbe = PublisherProbe.empty();
|
||||
when(this.authorizedClientRepository.saveAuthorizedClient(
|
||||
any(OAuth2AuthorizedClient.class), any(Authentication.class), any(ServerWebExchange.class))).thenReturn(Mono.empty());
|
||||
any(OAuth2AuthorizedClient.class), any(Authentication.class), any(ServerWebExchange.class))).thenReturn(this.saveAuthorizedClientProbe.mono());
|
||||
this.authorizedClientProvider = mock(ReactiveOAuth2AuthorizedClientProvider.class);
|
||||
when(this.authorizedClientProvider.authorize(any(OAuth2AuthorizationContext.class))).thenReturn(Mono.empty());
|
||||
this.contextAttributesMapper = mock(Function.class);
|
||||
@ -187,6 +190,7 @@ public class DefaultReactiveOAuth2AuthorizedClientManagerTests {
|
||||
assertThat(authorizedClient).isSameAs(this.authorizedClient);
|
||||
verify(this.authorizedClientRepository).saveAuthorizedClient(
|
||||
eq(this.authorizedClient), eq(this.principal), eq(this.serverWebExchange));
|
||||
this.saveAuthorizedClientProbe.assertWasSubscribed();
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -245,6 +249,7 @@ public class DefaultReactiveOAuth2AuthorizedClientManagerTests {
|
||||
assertThat(authorizedClient).isSameAs(reauthorizedClient);
|
||||
verify(this.authorizedClientRepository).saveAuthorizedClient(
|
||||
eq(reauthorizedClient), eq(this.principal), eq(this.serverWebExchange));
|
||||
this.saveAuthorizedClientProbe.assertWasSubscribed();
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -337,6 +342,7 @@ public class DefaultReactiveOAuth2AuthorizedClientManagerTests {
|
||||
assertThat(authorizedClient).isSameAs(reauthorizedClient);
|
||||
verify(this.authorizedClientRepository).saveAuthorizedClient(
|
||||
eq(reauthorizedClient), eq(this.principal), eq(this.serverWebExchange));
|
||||
this.saveAuthorizedClientProbe.assertWasSubscribed();
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -140,6 +140,7 @@ public class ServerOAuth2AuthorizedClientExchangeFilterFunctionTests {
|
||||
this.clientRegistrationRepository, this.authorizedClientRepository);
|
||||
this.authorizedClientManager.setAuthorizedClientProvider(authorizedClientProvider);
|
||||
this.function = new ServerOAuth2AuthorizedClientExchangeFilterFunction(authorizedClientManager);
|
||||
when(this.authorizedClientRepository.saveAuthorizedClient(any(), any(), any())).thenReturn(Mono.empty());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
Loading…
x
Reference in New Issue
Block a user