@@ -114,10 +114,9 @@ void autoConfigurationShouldMatchDefaultJwsAlgorithm() {
114
114
.withPropertyValues ("spring.security.oauth2.resourceserver.jwt.jwk-set-uri=https://jwk-set-uri.com" )
115
115
.run ((context ) -> {
116
116
JwtDecoder jwtDecoder = context .getBean (JwtDecoder .class );
117
- Object processor = ReflectionTestUtils .getField (jwtDecoder , "jwtProcessor" );
118
- Object keySelector = ReflectionTestUtils .getField (processor , "jwsKeySelector" );
119
- assertThat (keySelector ).hasFieldOrPropertyWithValue ("jwsAlgs" ,
120
- Collections .singleton (JWSAlgorithm .RS256 ));
117
+ assertThat (jwtDecoder ).extracting ("jwtProcessor.jwsKeySelector.jwsAlgs" )
118
+ .asInstanceOf (InstanceOfAssertFactories .collection (JWSAlgorithm .class ))
119
+ .containsExactlyInAnyOrder (JWSAlgorithm .RS256 );
121
120
});
122
121
}
123
122
@@ -144,9 +143,7 @@ void autoConfigurationShouldConfigureResourceServerWithSingleJwsAlgorithm() {
144
143
"spring.security.oauth2.resourceserver.jwt.jws-algorithms=RS384" )
145
144
.run ((context ) -> {
146
145
JwtDecoder jwtDecoder = context .getBean (JwtDecoder .class );
147
- Object processor = ReflectionTestUtils .getField (jwtDecoder , "jwtProcessor" );
148
- Object keySelector = ReflectionTestUtils .getField (processor , "jwsKeySelector" );
149
- assertThat (keySelector ).extracting ("jwsAlgs" )
146
+ assertThat (jwtDecoder ).extracting ("jwtProcessor.jwsKeySelector.jwsAlgs" )
150
147
.asInstanceOf (InstanceOfAssertFactories .collection (JWSAlgorithm .class ))
151
148
.containsExactlyInAnyOrder (JWSAlgorithm .RS384 );
152
149
assertThat (getBearerTokenFilter (context )).isNotNull ();
@@ -160,9 +157,7 @@ void autoConfigurationShouldConfigureResourceServerWithMultipleJwsAlgorithms() {
160
157
"spring.security.oauth2.resourceserver.jwt.jws-algorithms=RS256, RS384, RS512" )
161
158
.run ((context ) -> {
162
159
JwtDecoder jwtDecoder = context .getBean (JwtDecoder .class );
163
- Object processor = ReflectionTestUtils .getField (jwtDecoder , "jwtProcessor" );
164
- Object keySelector = ReflectionTestUtils .getField (processor , "jwsKeySelector" );
165
- assertThat (keySelector ).extracting ("jwsAlgs" )
160
+ assertThat (jwtDecoder ).extracting ("jwtProcessor.jwsKeySelector.jwsAlgs" )
166
161
.asInstanceOf (InstanceOfAssertFactories .collection (JWSAlgorithm .class ))
167
162
.containsExactlyInAnyOrder (JWSAlgorithm .RS256 , JWSAlgorithm .RS384 , JWSAlgorithm .RS512 );
168
163
assertThat (getBearerTokenFilter (context )).isNotNull ();
@@ -472,11 +467,9 @@ void autoConfigurationShouldConfigureResourceServerUsingJwkSetUriAndIssuerUri()
472
467
.run ((context ) -> {
473
468
assertThat (context ).hasSingleBean (JwtDecoder .class );
474
469
JwtDecoder jwtDecoder = context .getBean (JwtDecoder .class );
475
- DelegatingOAuth2TokenValidator <Jwt > jwtValidator = (DelegatingOAuth2TokenValidator <Jwt >) ReflectionTestUtils
476
- .getField (jwtDecoder , "jwtValidator" );
477
- Collection <OAuth2TokenValidator <Jwt >> tokenValidators = (Collection <OAuth2TokenValidator <Jwt >>) ReflectionTestUtils
478
- .getField (jwtValidator , "tokenValidators" );
479
- assertThat (tokenValidators ).hasAtLeastOneElementOfType (JwtIssuerValidator .class );
470
+ assertThat (jwtDecoder ).extracting ("jwtValidator.tokenValidators" )
471
+ .asInstanceOf (InstanceOfAssertFactories .collection (OAuth2TokenValidator .class ))
472
+ .hasAtLeastOneElementOfType (JwtIssuerValidator .class );
480
473
});
481
474
}
482
475
@@ -494,13 +487,11 @@ void autoConfigurationShouldNotConfigureIssuerUriAndAudienceJwtValidatorIfProper
494
487
.run ((context ) -> {
495
488
assertThat (context ).hasSingleBean (JwtDecoder .class );
496
489
JwtDecoder jwtDecoder = context .getBean (JwtDecoder .class );
497
- DelegatingOAuth2TokenValidator <Jwt > jwtValidator = (DelegatingOAuth2TokenValidator <Jwt >) ReflectionTestUtils
498
- .getField (jwtDecoder , "jwtValidator" );
499
- Collection <OAuth2TokenValidator <Jwt >> tokenValidators = (Collection <OAuth2TokenValidator <Jwt >>) ReflectionTestUtils
500
- .getField (jwtValidator , "tokenValidators" );
501
- assertThat (tokenValidators ).hasExactlyElementsOfTypes (JwtTimestampValidator .class );
502
- assertThat (tokenValidators ).doesNotHaveAnyElementsOfTypes (JwtClaimValidator .class );
503
- assertThat (tokenValidators ).doesNotHaveAnyElementsOfTypes (JwtIssuerValidator .class );
490
+ assertThat (jwtDecoder ).extracting ("jwtValidator.tokenValidators" )
491
+ .asInstanceOf (InstanceOfAssertFactories .collection (OAuth2TokenValidator .class ))
492
+ .hasExactlyElementsOfTypes (JwtTimestampValidator .class )
493
+ .doesNotHaveAnyElementsOfTypes (JwtClaimValidator .class )
494
+ .doesNotHaveAnyElementsOfTypes (JwtIssuerValidator .class );
504
495
});
505
496
}
506
497
@@ -565,10 +556,10 @@ private void validateDelegates(String issuerUri, Collection<OAuth2TokenValidator
565
556
assertThat (delegates ).hasAtLeastOneElementOfType (JwtClaimValidator .class );
566
557
OAuth2TokenValidator <Jwt > delegatingValidator = delegates .stream ()
567
558
.filter ((v ) -> v instanceof DelegatingOAuth2TokenValidator ).findFirst ().get ();
568
- Collection <OAuth2TokenValidator <Jwt >> nestedDelegates = (Collection <OAuth2TokenValidator <Jwt >>) ReflectionTestUtils
569
- .getField (delegatingValidator , "tokenValidators" );
570
559
if (issuerUri != null ) {
571
- assertThat (nestedDelegates ).hasAtLeastOneElementOfType (JwtIssuerValidator .class );
560
+ assertThat (delegatingValidator ).extracting ("tokenValidators" )
561
+ .asInstanceOf (InstanceOfAssertFactories .collection (OAuth2TokenValidator .class ))
562
+ .hasAtLeastOneElementOfType (JwtIssuerValidator .class );
572
563
}
573
564
}
574
565
0 commit comments