1818import java .util .Arrays ;
1919import java .util .function .Supplier ;
2020
21+ import javax .net .ssl .KeyManagerFactory ;
22+ import javax .net .ssl .TrustManagerFactory ;
23+
24+ import io .netty .handler .ssl .SslContext ;
25+ import io .netty .handler .ssl .SslContextBuilder ;
26+ import reactor .netty .http .client .HttpClient ;
27+ import reactor .netty .tcp .SslProvider ;
2128import sample .authorization .DeviceCodeOAuth2AuthorizedClientProvider ;
2229
2330import org .springframework .beans .factory .annotation .Qualifier ;
31+ import org .springframework .boot .ssl .SslBundle ;
32+ import org .springframework .boot .ssl .SslBundles ;
2433import org .springframework .boot .web .client .RestTemplateBuilder ;
2534import org .springframework .context .annotation .Bean ;
2635import org .springframework .context .annotation .Configuration ;
2736import org .springframework .http .client .ClientHttpRequestFactory ;
37+ import org .springframework .http .client .reactive .ClientHttpConnector ;
38+ import org .springframework .http .client .reactive .ReactorClientHttpConnector ;
2839import org .springframework .http .converter .FormHttpMessageConverter ;
2940import org .springframework .security .oauth2 .client .OAuth2AuthorizedClientManager ;
3041import org .springframework .security .oauth2 .client .OAuth2AuthorizedClientProvider ;
5465public class WebClientConfig {
5566
5667 @ Bean ("default-client-web-client" )
57- public WebClient defaultClientWebClient (OAuth2AuthorizedClientManager authorizedClientManager ) {
68+ public WebClient defaultClientWebClient (
69+ OAuth2AuthorizedClientManager authorizedClientManager ,
70+ SslBundles sslBundles ) throws Exception {
71+
5872 ServletOAuth2AuthorizedClientExchangeFilterFunction oauth2Client =
5973 new ServletOAuth2AuthorizedClientExchangeFilterFunction (authorizedClientManager );
6074 // @formatter:off
6175 return WebClient .builder ()
76+ .clientConnector (createClientConnector (sslBundles .getBundle ("demo-client" )))
6277 .apply (oauth2Client .oauth2Configuration ())
6378 .build ();
6479 // @formatter:on
@@ -69,7 +84,8 @@ public WebClient selfSignedDemoClientWebClient(
6984 ClientRegistrationRepository clientRegistrationRepository ,
7085 OAuth2AuthorizedClientRepository authorizedClientRepository ,
7186 RestTemplateBuilder restTemplateBuilder ,
72- @ Qualifier ("self-signed-demo-client-http-request-factory" ) Supplier <ClientHttpRequestFactory > clientHttpRequestFactory ) {
87+ @ Qualifier ("self-signed-demo-client-http-request-factory" ) Supplier <ClientHttpRequestFactory > clientHttpRequestFactory ,
88+ SslBundles sslBundles ) throws Exception {
7389
7490 // @formatter:off
7591 RestTemplate restTemplate = restTemplateBuilder
@@ -98,6 +114,7 @@ public WebClient selfSignedDemoClientWebClient(
98114 new ServletOAuth2AuthorizedClientExchangeFilterFunction (authorizedClientManager );
99115 // @formatter:off
100116 return WebClient .builder ()
117+ .clientConnector (createClientConnector (sslBundles .getBundle ("self-signed-demo-client" )))
101118 .apply (oauth2Client .oauth2Configuration ())
102119 .build ();
103120 // @formatter:on
@@ -143,6 +160,22 @@ public OAuth2AuthorizedClientManager authorizedClientManager(
143160 return authorizedClientManager ;
144161 }
145162
163+ private static ClientHttpConnector createClientConnector (SslBundle sslBundle ) throws Exception {
164+ KeyManagerFactory keyManagerFactory = sslBundle .getManagers ().getKeyManagerFactory ();
165+ TrustManagerFactory trustManagerFactory = sslBundle .getManagers ().getTrustManagerFactory ();
166+
167+ // @formatter:off
168+ SslContext sslContext = SslContextBuilder .forClient ()
169+ .keyManager (keyManagerFactory )
170+ .trustManager (trustManagerFactory )
171+ .build ();
172+ // @formatter:on
173+
174+ SslProvider sslProvider = SslProvider .builder ().sslContext (sslContext ).build ();
175+ HttpClient httpClient = HttpClient .create ().secure (sslProvider );
176+ return new ReactorClientHttpConnector (httpClient );
177+ }
178+
146179 private static OAuth2AccessTokenResponseClient <OAuth2ClientCredentialsGrantRequest > createClientCredentialsTokenResponseClient (
147180 RestTemplate restTemplate ) {
148181 DefaultClientCredentialsTokenResponseClient clientCredentialsTokenResponseClient =
0 commit comments