Skip to content

Commit 95f600a

Browse files
committed
Issue spring-projects#6182 Solved temporarily using try-catch
1 parent 63f2b60 commit 95f600a

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

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

+8
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,14 @@ public class WebClientReactiveAuthorizationCodeTokenResponseClient implements Re
4848
private WebClient webClient = WebClient.builder()
4949
.build();
5050

51+
/**
52+
* @param webClient the webClient to set
53+
*/
54+
public void setWebClient(WebClient webClient) {
55+
this.webClient = webClient;
56+
}
57+
58+
5159
@Override
5260
public Mono<OAuth2AccessTokenResponse> getTokenResponse(OAuth2AuthorizationCodeGrantRequest authorizationGrantRequest) {
5361
return Mono.defer(() -> {

oauth2/oauth2-client/src/test/java/org/springframework/security/oauth2/client/endpoint/WebClientReactiveAuthorizationCodeTokenResponseClientTests.java

+19
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,13 @@
3232
import org.springframework.security.oauth2.core.endpoint.OAuth2AuthorizationExchange;
3333
import org.springframework.security.oauth2.core.endpoint.OAuth2AuthorizationRequest;
3434
import org.springframework.security.oauth2.core.endpoint.OAuth2AuthorizationResponse;
35+
import org.springframework.web.reactive.function.client.WebClient;
3536

3637
import java.time.Instant;
3738

3839
import static org.assertj.core.api.Assertions.assertThat;
3940
import static org.assertj.core.api.Assertions.assertThatThrownBy;
41+
import static org.mockito.Mockito.*;
4042

4143
/**
4244
* @author Rob Winch
@@ -259,4 +261,21 @@ private MockResponse jsonResponse(String json) {
259261
.setHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE)
260262
.setBody(json);
261263
}
264+
265+
@Test
266+
public void setWebClientNullThenIllegalArgumentException(){
267+
tokenResponseClient.setWebClient(null);
268+
}
269+
270+
@Test
271+
public void setCustomWebClientThenCustomWebClientIsUsed() {
272+
WebClient customClient = mock(WebClient.class);
273+
tokenResponseClient.setWebClient(customClient);
274+
try {
275+
OAuth2AccessTokenResponse response = this.tokenResponseClient.getTokenResponse(authorizationCodeGrantRequest()).block();
276+
} catch(Exception e) {
277+
// Do Nothing!
278+
}
279+
verify(customClient, atLeastOnce()).post();
280+
}
262281
}

0 commit comments

Comments
 (0)