@@ -531,8 +531,8 @@ public void requestWhenClientRegistersWithSecretExpirationThenClientRegistration
531
531
532
532
OidcClientRegistration clientRegistrationResponse = registerClient (clientRegistration );
533
533
534
- var expectedSecretExpiryDate = Instant .now ().plus (Duration .ofHours (24 ));
535
- var allowedDelta = new TemporalUnitWithinOffset (1 , ChronoUnit .MINUTES );
534
+ Instant expectedSecretExpiryDate = Instant .now ().plus (Duration .ofHours (24 ));
535
+ TemporalUnitWithinOffset allowedDelta = new TemporalUnitWithinOffset (1 , ChronoUnit .MINUTES );
536
536
537
537
// Returned response contains expiration date
538
538
assertThat (clientRegistrationResponse .getClientSecretExpiresAt ())
@@ -685,40 +685,52 @@ public SecurityFilterChain authorizationServerSecurityFilterChain(HttpSecurity h
685
685
686
686
@ EnableWebSecurity
687
687
@ Configuration (proxyBeanMethods = false )
688
- static class CustomClientMetadataConfiguration extends ClientRegistrationConvertersConfiguration {
689
-
690
- private static final List <String > supportedCustomClientMetadata = List .of ("custom-metadata-name-1" , "custom-metadata-name-2" );
688
+ static class CustomClientMetadataConfiguration extends AuthorizationServerConfiguration {
691
689
690
+ // @formatter:off
691
+ @ Bean
692
692
@ Override
693
- protected Converter <OidcClientRegistration , RegisteredClient > registeredClientConverter () {
694
- return new CustomRegisteredClientConverter (supportedCustomClientMetadata );
693
+ public SecurityFilterChain authorizationServerSecurityFilterChain (HttpSecurity http ) throws Exception {
694
+ OAuth2AuthorizationServerConfigurer authorizationServerConfigurer =
695
+ OAuth2AuthorizationServerConfigurer .authorizationServer ();
696
+ http
697
+ .securityMatcher (authorizationServerConfigurer .getEndpointsMatcher ())
698
+ .with (authorizationServerConfigurer , (authorizationServer ) ->
699
+ authorizationServer
700
+ .oidc ((oidc ) ->
701
+ oidc
702
+ .clientRegistrationEndpoint ((clientRegistration ) ->
703
+ clientRegistration
704
+ .authenticationProviders (configureClientRegistrationConverters ())
705
+ )
706
+ )
707
+ )
708
+ .authorizeHttpRequests ((authorize ) ->
709
+ authorize .anyRequest ().authenticated ()
710
+ );
711
+ return http .build ();
695
712
}
713
+ // @formatter:on
696
714
697
- @ Override
698
- protected Converter <RegisteredClient , OidcClientRegistration > oidcClientRegistrationConverter () {
699
- return new CustomClientRegistrationConverter (supportedCustomClientMetadata );
715
+ private Consumer <List <AuthenticationProvider >> configureClientRegistrationConverters () {
716
+ // @formatter:off
717
+ return (authenticationProviders ) ->
718
+ authenticationProviders .forEach ((authenticationProvider ) -> {
719
+ List <String > supportedCustomClientMetadata = List .of ("custom-metadata-name-1" , "custom-metadata-name-2" );
720
+ if (authenticationProvider instanceof OidcClientRegistrationAuthenticationProvider provider ) {
721
+ provider .setRegisteredClientConverter (new CustomRegisteredClientConverter (supportedCustomClientMetadata ));
722
+ provider .setClientRegistrationConverter (new CustomClientRegistrationConverter (supportedCustomClientMetadata ));
723
+ }
724
+ });
725
+ // @formatter:on
700
726
}
701
727
702
728
}
703
729
704
730
@ EnableWebSecurity
705
731
@ Configuration (proxyBeanMethods = false )
706
- static class ClientSecretExpirationConfiguration extends ClientRegistrationConvertersConfiguration {
707
-
708
- @ Override
709
- protected Converter <OidcClientRegistration , RegisteredClient > registeredClientConverter () {
710
- return new ClientSecretExpirationRegisteredClientConverter ();
711
- }
732
+ static class ClientSecretExpirationConfiguration extends AuthorizationServerConfiguration {
712
733
713
- }
714
-
715
- /**
716
- * This test configuration allows to override {@code RegisteredClient} -> {@code OidcClientRegistration} and
717
- * {@code OidcClientRegistration} -> {@code RegisteredClient} converters
718
- */
719
- @ EnableWebSecurity
720
- @ Configuration (proxyBeanMethods = false )
721
- static class ClientRegistrationConvertersConfiguration extends AuthorizationServerConfiguration {
722
734
// @formatter:off
723
735
@ Bean
724
736
@ Override
@@ -749,26 +761,12 @@ private Consumer<List<AuthenticationProvider>> configureClientRegistrationConver
749
761
return (authenticationProviders ) ->
750
762
authenticationProviders .forEach ((authenticationProvider ) -> {
751
763
if (authenticationProvider instanceof OidcClientRegistrationAuthenticationProvider provider ) {
752
- var registeredClientConverter = registeredClientConverter ();
753
- if (registeredClientConverter != null ) {
754
- provider .setRegisteredClientConverter (registeredClientConverter );
755
- }
756
- var oidcClientRegistrationConverter = oidcClientRegistrationConverter ();
757
- if (oidcClientRegistrationConverter != null ) {
758
- provider .setClientRegistrationConverter (oidcClientRegistrationConverter );
759
- }
764
+ provider .setRegisteredClientConverter (new ClientSecretExpirationRegisteredClientConverter ());
760
765
}
761
766
});
762
767
// @formatter:on
763
768
}
764
769
765
- protected Converter <OidcClientRegistration , RegisteredClient > registeredClientConverter () {
766
- return null ;
767
- }
768
-
769
- protected Converter <RegisteredClient , OidcClientRegistration > oidcClientRegistrationConverter () {
770
- return null ;
771
- }
772
770
}
773
771
774
772
@ EnableWebSecurity
@@ -921,5 +919,4 @@ public RegisteredClient convert(OidcClientRegistration clientRegistration) {
921
919
return registeredClientBuilder .build ();
922
920
}
923
921
}
924
-
925
922
}
0 commit comments