31
31
import okhttp3 .mockwebserver .MockWebServer ;
32
32
import org .junit .jupiter .api .AfterEach ;
33
33
import org .junit .jupiter .api .Test ;
34
+ import reactor .core .publisher .Mono ;
34
35
35
36
import org .springframework .boot .autoconfigure .AutoConfigurations ;
36
37
import org .springframework .boot .test .context .FilteredClassLoader ;
52
53
import org .springframework .security .oauth2 .jwt .JwtIssuerValidator ;
53
54
import org .springframework .security .oauth2 .jwt .NimbusReactiveJwtDecoder ;
54
55
import org .springframework .security .oauth2 .jwt .ReactiveJwtDecoder ;
56
+ import org .springframework .security .oauth2 .jwt .SupplierReactiveJwtDecoder ;
55
57
import org .springframework .security .oauth2 .server .resource .BearerTokenAuthenticationToken ;
56
58
import org .springframework .security .oauth2 .server .resource .authentication .JwtReactiveAuthenticationManager ;
57
59
import org .springframework .security .oauth2 .server .resource .authentication .OpaqueTokenReactiveAuthenticationManager ;
@@ -129,6 +131,7 @@ void autoConfigurationUsingPublicKeyValueShouldConfigureResourceServerUsingJwsAl
129
131
}
130
132
131
133
@ Test
134
+ @ SuppressWarnings ("unchecked" )
132
135
void autoConfigurationShouldConfigureResourceServerUsingOidcIssuerUri () throws IOException {
133
136
this .server = new MockWebServer ();
134
137
this .server .start ();
@@ -138,15 +141,21 @@ void autoConfigurationShouldConfigureResourceServerUsingOidcIssuerUri() throws I
138
141
setupMockResponse (cleanIssuerPath );
139
142
this .contextRunner .withPropertyValues ("spring.security.oauth2.resourceserver.jwt.issuer-uri=http://"
140
143
+ this .server .getHostName () + ":" + this .server .getPort () + "/" + path ).run ((context ) -> {
141
- assertThat (context ).hasSingleBean (NimbusReactiveJwtDecoder .class );
144
+ assertThat (context ).hasSingleBean (SupplierReactiveJwtDecoder .class );
142
145
assertFilterConfiguredWithJwtAuthenticationManager (context );
143
146
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 ();
144
152
});
145
153
// 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 );
147
155
}
148
156
149
157
@ Test
158
+ @ SuppressWarnings ("unchecked" )
150
159
void autoConfigurationShouldConfigureResourceServerUsingOidcRfc8414IssuerUri () throws Exception {
151
160
this .server = new MockWebServer ();
152
161
this .server .start ();
@@ -155,15 +164,21 @@ void autoConfigurationShouldConfigureResourceServerUsingOidcRfc8414IssuerUri() t
155
164
setupMockResponsesWithErrors (cleanIssuerPath , 1 );
156
165
this .contextRunner .withPropertyValues ("spring.security.oauth2.resourceserver.jwt.issuer-uri=http://"
157
166
+ this .server .getHostName () + ":" + this .server .getPort ()).run ((context ) -> {
158
- assertThat (context ).hasSingleBean (NimbusReactiveJwtDecoder .class );
167
+ assertThat (context ).hasSingleBean (SupplierReactiveJwtDecoder .class );
159
168
assertFilterConfiguredWithJwtAuthenticationManager (context );
160
169
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 ();
161
175
});
162
176
// 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 );
164
178
}
165
179
166
180
@ Test
181
+ @ SuppressWarnings ("unchecked" )
167
182
void autoConfigurationShouldConfigureResourceServerUsingOAuthIssuerUri () throws Exception {
168
183
this .server = new MockWebServer ();
169
184
this .server .start ();
@@ -172,12 +187,17 @@ void autoConfigurationShouldConfigureResourceServerUsingOAuthIssuerUri() throws
172
187
setupMockResponsesWithErrors (cleanIssuerPath , 2 );
173
188
this .contextRunner .withPropertyValues ("spring.security.oauth2.resourceserver.jwt.issuer-uri=http://"
174
189
+ this .server .getHostName () + ":" + this .server .getPort ()).run ((context ) -> {
175
- assertThat (context ).hasSingleBean (NimbusReactiveJwtDecoder .class );
190
+ assertThat (context ).hasSingleBean (SupplierReactiveJwtDecoder .class );
176
191
assertFilterConfiguredWithJwtAuthenticationManager (context );
177
192
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 ();
178
198
});
179
199
// 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 );
181
201
}
182
202
183
203
@ Test
@@ -228,7 +248,7 @@ void autoConfigurationWhenKeyLocationAndIssuerUriPresentShouldUseIssuerUri() thr
228
248
+ this .server .getPort (),
229
249
"spring.security.oauth2.resourceserver.jwt.public-key-location=classpath:public-key-location" )
230
250
.run ((context ) -> {
231
- assertThat (context ).hasSingleBean (NimbusReactiveJwtDecoder .class );
251
+ assertThat (context ).hasSingleBean (SupplierReactiveJwtDecoder .class );
232
252
assertFilterConfiguredWithJwtAuthenticationManager (context );
233
253
assertThat (context .containsBean ("jwtDecoderByIssuerUri" )).isTrue ();
234
254
});
0 commit comments