3131import okhttp3 .mockwebserver .MockWebServer ;
3232import org .junit .jupiter .api .AfterEach ;
3333import org .junit .jupiter .api .Test ;
34+ import reactor .core .publisher .Mono ;
3435
3536import org .springframework .boot .autoconfigure .AutoConfigurations ;
3637import org .springframework .boot .test .context .FilteredClassLoader ;
5253import org .springframework .security .oauth2 .jwt .JwtIssuerValidator ;
5354import org .springframework .security .oauth2 .jwt .NimbusReactiveJwtDecoder ;
5455import org .springframework .security .oauth2 .jwt .ReactiveJwtDecoder ;
56+ import org .springframework .security .oauth2 .jwt .SupplierReactiveJwtDecoder ;
5557import org .springframework .security .oauth2 .server .resource .BearerTokenAuthenticationToken ;
5658import org .springframework .security .oauth2 .server .resource .authentication .JwtReactiveAuthenticationManager ;
5759import org .springframework .security .oauth2 .server .resource .authentication .OpaqueTokenReactiveAuthenticationManager ;
@@ -129,6 +131,7 @@ void autoConfigurationUsingPublicKeyValueShouldConfigureResourceServerUsingJwsAl
129131 }
130132
131133 @ Test
134+ @ SuppressWarnings ("unchecked" )
132135 void autoConfigurationShouldConfigureResourceServerUsingOidcIssuerUri () throws IOException {
133136 this .server = new MockWebServer ();
134137 this .server .start ();
@@ -138,15 +141,21 @@ void autoConfigurationShouldConfigureResourceServerUsingOidcIssuerUri() throws I
138141 setupMockResponse (cleanIssuerPath );
139142 this .contextRunner .withPropertyValues ("spring.security.oauth2.resourceserver.jwt.issuer-uri=http://"
140143 + this .server .getHostName () + ":" + this .server .getPort () + "/" + path ).run ((context ) -> {
141- assertThat (context ).hasSingleBean (NimbusReactiveJwtDecoder .class );
144+ assertThat (context ).hasSingleBean (SupplierReactiveJwtDecoder .class );
142145 assertFilterConfiguredWithJwtAuthenticationManager (context );
143146 assertThat (context .containsBean ("jwtDecoderByIssuerUri" )).isTrue ();
147+ SupplierReactiveJwtDecoder supplierReactiveJwtDecoder = context
148+ .getBean (SupplierReactiveJwtDecoder .class );
149+ Mono <ReactiveJwtDecoder > reactiveJwtDecoderSupplier = (Mono <ReactiveJwtDecoder >) ReflectionTestUtils
150+ .getField (supplierReactiveJwtDecoder , "jwtDecoderMono" );
151+ ReactiveJwtDecoder reactiveJwtDecoder = reactiveJwtDecoderSupplier .block ();
144152 });
145153 // The last request is to the JWK Set endpoint to look up the algorithm
146- assertThat (this .server .getRequestCount ()).isEqualTo (2 );
154+ assertThat (this .server .getRequestCount ()).isEqualTo (1 );
147155 }
148156
149157 @ Test
158+ @ SuppressWarnings ("unchecked" )
150159 void autoConfigurationShouldConfigureResourceServerUsingOidcRfc8414IssuerUri () throws Exception {
151160 this .server = new MockWebServer ();
152161 this .server .start ();
@@ -155,15 +164,21 @@ void autoConfigurationShouldConfigureResourceServerUsingOidcRfc8414IssuerUri() t
155164 setupMockResponsesWithErrors (cleanIssuerPath , 1 );
156165 this .contextRunner .withPropertyValues ("spring.security.oauth2.resourceserver.jwt.issuer-uri=http://"
157166 + this .server .getHostName () + ":" + this .server .getPort ()).run ((context ) -> {
158- assertThat (context ).hasSingleBean (NimbusReactiveJwtDecoder .class );
167+ assertThat (context ).hasSingleBean (SupplierReactiveJwtDecoder .class );
159168 assertFilterConfiguredWithJwtAuthenticationManager (context );
160169 assertThat (context .containsBean ("jwtDecoderByIssuerUri" )).isTrue ();
170+ SupplierReactiveJwtDecoder supplierReactiveJwtDecoder = context
171+ .getBean (SupplierReactiveJwtDecoder .class );
172+ Mono <ReactiveJwtDecoder > reactiveJwtDecoderSupplier = (Mono <ReactiveJwtDecoder >) ReflectionTestUtils
173+ .getField (supplierReactiveJwtDecoder , "jwtDecoderMono" );
174+ ReactiveJwtDecoder reactiveJwtDecoder = reactiveJwtDecoderSupplier .block ();
161175 });
162176 // The last request is to the JWK Set endpoint to look up the algorithm
163- assertThat (this .server .getRequestCount ()).isEqualTo (3 );
177+ assertThat (this .server .getRequestCount ()).isEqualTo (2 );
164178 }
165179
166180 @ Test
181+ @ SuppressWarnings ("unchecked" )
167182 void autoConfigurationShouldConfigureResourceServerUsingOAuthIssuerUri () throws Exception {
168183 this .server = new MockWebServer ();
169184 this .server .start ();
@@ -172,12 +187,17 @@ void autoConfigurationShouldConfigureResourceServerUsingOAuthIssuerUri() throws
172187 setupMockResponsesWithErrors (cleanIssuerPath , 2 );
173188 this .contextRunner .withPropertyValues ("spring.security.oauth2.resourceserver.jwt.issuer-uri=http://"
174189 + this .server .getHostName () + ":" + this .server .getPort ()).run ((context ) -> {
175- assertThat (context ).hasSingleBean (NimbusReactiveJwtDecoder .class );
190+ assertThat (context ).hasSingleBean (SupplierReactiveJwtDecoder .class );
176191 assertFilterConfiguredWithJwtAuthenticationManager (context );
177192 assertThat (context .containsBean ("jwtDecoderByIssuerUri" )).isTrue ();
193+ SupplierReactiveJwtDecoder supplierReactiveJwtDecoder = context
194+ .getBean (SupplierReactiveJwtDecoder .class );
195+ Mono <ReactiveJwtDecoder > reactiveJwtDecoderSupplier = (Mono <ReactiveJwtDecoder >) ReflectionTestUtils
196+ .getField (supplierReactiveJwtDecoder , "jwtDecoderMono" );
197+ ReactiveJwtDecoder reactiveJwtDecoder = reactiveJwtDecoderSupplier .block ();
178198 });
179199 // The last request is to the JWK Set endpoint to look up the algorithm
180- assertThat (this .server .getRequestCount ()).isEqualTo (4 );
200+ assertThat (this .server .getRequestCount ()).isEqualTo (3 );
181201 }
182202
183203 @ Test
@@ -228,7 +248,7 @@ void autoConfigurationWhenKeyLocationAndIssuerUriPresentShouldUseIssuerUri() thr
228248 + this .server .getPort (),
229249 "spring.security.oauth2.resourceserver.jwt.public-key-location=classpath:public-key-location" )
230250 .run ((context ) -> {
231- assertThat (context ).hasSingleBean (NimbusReactiveJwtDecoder .class );
251+ assertThat (context ).hasSingleBean (SupplierReactiveJwtDecoder .class );
232252 assertFilterConfiguredWithJwtAuthenticationManager (context );
233253 assertThat (context .containsBean ("jwtDecoderByIssuerUri" )).isTrue ();
234254 });
0 commit comments