3939import okhttp3 .mockwebserver .MockWebServer ;
4040import org .assertj .core .api .InstanceOfAssertFactories ;
4141import org .assertj .core .api .ThrowingConsumer ;
42+ import org .jspecify .annotations .Nullable ;
4243import org .junit .jupiter .api .AfterEach ;
4344import org .junit .jupiter .api .Test ;
4445import org .junit .jupiter .params .ParameterizedTest ;
8788import org .springframework .security .web .server .SecurityWebFilterChain ;
8889import org .springframework .security .web .server .authentication .AuthenticationWebFilter ;
8990import org .springframework .test .util .ReflectionTestUtils ;
91+ import org .springframework .web .server .ServerWebExchange ;
9092import org .springframework .web .server .WebFilter ;
9193
9294import static org .assertj .core .api .Assertions .assertThat ;
@@ -112,7 +114,7 @@ class ReactiveOAuth2ResourceServerAutoConfigurationTests {
112114 .withConfiguration (AutoConfigurations .of (ReactiveOAuth2ResourceServerAutoConfiguration .class ))
113115 .withUserConfiguration (TestConfig .class );
114116
115- private MockWebServer server ;
117+ private @ Nullable MockWebServer server ;
116118
117119 private static final Duration TIMEOUT = Duration .ofSeconds (5000000 );
118120
@@ -236,6 +238,7 @@ private void decodeJwt(AssertableReactiveWebApplicationContext context) {
236238 SupplierReactiveJwtDecoder supplierReactiveJwtDecoder = context .getBean (SupplierReactiveJwtDecoder .class );
237239 Mono <ReactiveJwtDecoder > reactiveJwtDecoderSupplier = (Mono <ReactiveJwtDecoder >) ReflectionTestUtils
238240 .getField (supplierReactiveJwtDecoder , "jwtDecoderMono" );
241+ assertThat (reactiveJwtDecoderSupplier ).isNotNull ();
239242 try {
240243 reactiveJwtDecoderSupplier .flatMap ((decoder ) -> decoder .decode ("eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9."
241244 + "eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiYWRtaW4iOnRydWUsImlhdCI6MTUxNjIzOTAyMn0."
@@ -538,7 +541,9 @@ void autoConfigurationShouldConfigureAudienceValidatorIfPropertyProvidedAndIssue
538541 SupplierReactiveJwtDecoder supplierJwtDecoderBean = context .getBean (SupplierReactiveJwtDecoder .class );
539542 Mono <ReactiveJwtDecoder > jwtDecoderSupplier = (Mono <ReactiveJwtDecoder >) ReflectionTestUtils
540543 .getField (supplierJwtDecoderBean , "jwtDecoderMono" );
544+ assertThat (jwtDecoderSupplier ).isNotNull ();
541545 ReactiveJwtDecoder jwtDecoder = jwtDecoderSupplier .block ();
546+ assertThat (jwtDecoder ).isNotNull ();
542547 validate (
543548 jwt ().claim ("iss" , URI .create (issuerUri ).toURL ())
544549 .claim ("aud" , List .of ("https://test-audience.com" )),
@@ -612,6 +617,7 @@ void audienceValidatorWhenAudienceInvalid() throws Exception {
612617 ReactiveJwtDecoder jwtDecoder = context .getBean (ReactiveJwtDecoder .class );
613618 DelegatingOAuth2TokenValidator <Jwt > jwtValidator = (DelegatingOAuth2TokenValidator <Jwt >) ReflectionTestUtils
614619 .getField (jwtDecoder , "jwtValidator" );
620+ assertThat (jwtValidator ).isNotNull ();
615621 Jwt jwt = jwt ().claim ("iss" , new URL (issuerUri ))
616622 .claim ("aud" , Collections .singletonList ("https://other-audience.com" ))
617623 .build ();
@@ -638,6 +644,7 @@ void customValidatorWhenInvalid() throws Exception {
638644 ReactiveJwtDecoder jwtDecoder = context .getBean (ReactiveJwtDecoder .class );
639645 DelegatingOAuth2TokenValidator <Jwt > jwtValidator = (DelegatingOAuth2TokenValidator <Jwt >) ReflectionTestUtils
640646 .getField (jwtDecoder , "jwtValidator" );
647+ assertThat (jwtValidator ).isNotNull ();
641648 Jwt jwt = jwt ().claim ("iss" , new URL (issuerUri )).claim ("custom_claim" , "invalid_value" ).build ();
642649 assertThat (jwtValidator .validate (jwt ).hasErrors ()).isTrue ();
643650 });
@@ -720,6 +727,7 @@ void causesReactiveManagementWebSecurityAutoConfigurationToBackOff() {
720727 .doesNotHaveBean (ReactiveManagementWebSecurityAutoConfiguration .class ));
721728 }
722729
730+ @ SuppressWarnings ("unchecked" )
723731 private void assertFilterConfiguredWithJwtAuthenticationManager (AssertableReactiveWebApplicationContext context ) {
724732 MatcherSecurityWebFilterChain filterChain = (MatcherSecurityWebFilterChain ) context
725733 .getBean (BeanIds .SPRING_SECURITY_FILTER_CHAIN );
@@ -728,12 +736,16 @@ private void assertFilterConfiguredWithJwtAuthenticationManager(AssertableReacti
728736 .filter ((f ) -> f instanceof AuthenticationWebFilter )
729737 .findFirst ()
730738 .orElse (null );
731- ReactiveAuthenticationManagerResolver <?> authenticationManagerResolver = (ReactiveAuthenticationManagerResolver <?>) ReflectionTestUtils
739+ assertThat (webFilter ).isNotNull ();
740+ ReactiveAuthenticationManagerResolver <ServerWebExchange > authenticationManagerResolver = (ReactiveAuthenticationManagerResolver <ServerWebExchange >) ReflectionTestUtils
732741 .getField (webFilter , "authenticationManagerResolver" );
733- Object authenticationManager = authenticationManagerResolver .resolve (null ).block (TIMEOUT );
742+ assertThat (authenticationManagerResolver ).isNotNull ();
743+ Object authenticationManager = authenticationManagerResolver .resolve (mock (ServerWebExchange .class ))
744+ .block (TIMEOUT );
734745 assertThat (authenticationManager ).isInstanceOf (JwtReactiveAuthenticationManager .class );
735746 }
736747
748+ @ SuppressWarnings ("unchecked" )
737749 private void assertFilterConfiguredWithOpaqueTokenAuthenticationManager (
738750 AssertableReactiveWebApplicationContext context ) {
739751 MatcherSecurityWebFilterChain filterChain = (MatcherSecurityWebFilterChain ) context
@@ -743,9 +755,12 @@ private void assertFilterConfiguredWithOpaqueTokenAuthenticationManager(
743755 .filter ((f ) -> f instanceof AuthenticationWebFilter )
744756 .findFirst ()
745757 .orElse (null );
746- ReactiveAuthenticationManagerResolver <?> authenticationManagerResolver = (ReactiveAuthenticationManagerResolver <?>) ReflectionTestUtils
758+ assertThat (webFilter ).isNotNull ();
759+ ReactiveAuthenticationManagerResolver <ServerWebExchange > authenticationManagerResolver = (ReactiveAuthenticationManagerResolver <ServerWebExchange >) ReflectionTestUtils
747760 .getField (webFilter , "authenticationManagerResolver" );
748- Object authenticationManager = authenticationManagerResolver .resolve (null ).block (TIMEOUT );
761+ assertThat (authenticationManagerResolver ).isNotNull ();
762+ Object authenticationManager = authenticationManagerResolver .resolve (mock (ServerWebExchange .class ))
763+ .block (TIMEOUT );
749764 assertThat (authenticationManager ).isInstanceOf (OpaqueTokenReactiveAuthenticationManager .class );
750765 }
751766
@@ -760,12 +775,14 @@ private void setupMockResponse(String issuer) {
760775 MockResponse mockResponse = new MockResponse ().setResponseCode (HttpStatus .OK .value ())
761776 .setBody (new ObjectMapper ().writeValueAsString (getResponse (issuer )))
762777 .setHeader (HttpHeaders .CONTENT_TYPE , MediaType .APPLICATION_JSON_VALUE );
778+ assertThat (this .server ).isNotNull ();
763779 this .server .enqueue (mockResponse );
764780 this .server .enqueue (
765781 new MockResponse ().setResponseCode (200 ).setHeader ("Content-Type" , "application/json" ).setBody (JWK_SET ));
766782 }
767783
768784 private void setupMockResponsesWithErrors (String issuer , int errorResponseCount ) {
785+ assertThat (this .server ).isNotNull ();
769786 for (int i = 0 ; i < errorResponseCount ; i ++) {
770787 MockResponse emptyResponse = new MockResponse ().setResponseCode (HttpStatus .NOT_FOUND .value ());
771788 this .server .enqueue (emptyResponse );
@@ -808,6 +825,7 @@ private void validate(Jwt.Builder builder, ReactiveJwtDecoder jwtDecoder,
808825 ThrowingConsumer <List <OAuth2TokenValidator <Jwt >>> validatorsConsumer ) {
809826 DelegatingOAuth2TokenValidator <Jwt > jwtValidator = (DelegatingOAuth2TokenValidator <Jwt >) ReflectionTestUtils
810827 .getField (jwtDecoder , "jwtValidator" );
828+ assertThat (jwtValidator ).isNotNull ();
811829 assertThat (jwtValidator .validate (builder .build ()).hasErrors ()).isFalse ();
812830 validatorsConsumer .accept (extractValidators (jwtValidator ));
813831 }
@@ -816,6 +834,7 @@ private void validate(Jwt.Builder builder, ReactiveJwtDecoder jwtDecoder,
816834 private List <OAuth2TokenValidator <Jwt >> extractValidators (DelegatingOAuth2TokenValidator <Jwt > delegatingValidator ) {
817835 Collection <OAuth2TokenValidator <Jwt >> delegates = (Collection <OAuth2TokenValidator <Jwt >>) ReflectionTestUtils
818836 .getField (delegatingValidator , "tokenValidators" );
837+ assertThat (delegates ).isNotNull ();
819838 List <OAuth2TokenValidator <Jwt >> extracted = new ArrayList <>();
820839 for (OAuth2TokenValidator <Jwt > delegate : delegates ) {
821840 if (delegate instanceof DelegatingOAuth2TokenValidator <Jwt > delegatingDelegate ) {
0 commit comments