Skip to content

Commit eecd7d9

Browse files
committed
Update Deprecated Reactor Usage
1 parent 834370d commit eecd7d9

File tree

3 files changed

+8
-7
lines changed

3 files changed

+8
-7
lines changed

oauth2/oauth2-client/src/main/java/org/springframework/security/oauth2/client/endpoint/AbstractWebClientReactiveOAuth2AccessTokenResponseClient.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,9 +84,7 @@ public Mono<OAuth2AccessTokenResponse> getTokenResponse(T grantRequest) {
8484
Assert.notNull(grantRequest, "grantRequest cannot be null");
8585
// @formatter:off
8686
return Mono.defer(() -> this.requestEntityConverter.convert(grantRequest)
87-
.exchange()
88-
.flatMap((response) -> response.body(this.bodyExtractor))
89-
);
87+
.exchangeToMono((response) -> response.body(this.bodyExtractor)));
9088
// @formatter:on
9189
}
9290

oauth2/oauth2-resource-server/src/main/java/org/springframework/security/oauth2/server/resource/introspection/SpringReactiveOpaqueTokenIntrospector.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -105,21 +105,20 @@ public Mono<OAuth2AuthenticatedPrincipal> introspect(String token) {
105105
// @formatter:off
106106
return Mono.just(token)
107107
.flatMap(this::makeRequest)
108-
.flatMap(this::adaptToNimbusResponse)
109108
.map(this::convertClaimsSet)
110109
.flatMap(this.authenticationConverter::convert)
111110
.cast(OAuth2AuthenticatedPrincipal.class)
112111
.onErrorMap((e) -> !(e instanceof OAuth2IntrospectionException), this::onError);
113112
// @formatter:on
114113
}
115114

116-
private Mono<ClientResponse> makeRequest(String token) {
115+
private Mono<Map<String, Object>> makeRequest(String token) {
117116
// @formatter:off
118117
return this.webClient.post()
119118
.uri(this.introspectionUri)
120119
.header(HttpHeaders.ACCEPT, MediaType.APPLICATION_JSON_VALUE)
121120
.body(BodyInserters.fromFormData("token", token))
122-
.exchange();
121+
.exchangeToMono(this::adaptToNimbusResponse);
123122
// @formatter:on
124123
}
125124

oauth2/oauth2-resource-server/src/test/java/org/springframework/security/oauth2/server/resource/introspection/SpringReactiveOpaqueTokenIntrospectorTests.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import java.util.HashMap;
2525
import java.util.Map;
2626
import java.util.Optional;
27+
import java.util.function.Function;
2728

2829
import com.fasterxml.jackson.databind.ObjectMapper;
2930
import okhttp3.mockwebserver.Dispatcher;
@@ -322,7 +323,10 @@ private WebClient mockResponse(Map<String, Object> response) {
322323
ClientResponse.Headers headers = mock(ClientResponse.Headers.class);
323324
given(headers.contentType()).willReturn(Optional.of(MediaType.APPLICATION_JSON));
324325
given(clientResponse.headers()).willReturn(headers);
325-
given(spec.exchange()).willReturn(Mono.just(clientResponse));
326+
given(spec.exchangeToMono(any())).willAnswer((invocation) -> {
327+
Function<ClientResponse, Mono<ClientResponse>> fun = invocation.getArgument(0);
328+
return fun.apply(clientResponse);
329+
});
326330
return webClient;
327331
}
328332

0 commit comments

Comments
 (0)