Skip to content

Commit a8d4905

Browse files
committed
Post-review fixes
Signed-off-by: wheleph <[email protected]>
1 parent 5228576 commit a8d4905

File tree

1 file changed

+38
-41
lines changed
  • oauth2-authorization-server/src/test/java/org/springframework/security/oauth2/server/authorization/config/annotation/web/configurers

1 file changed

+38
-41
lines changed

oauth2-authorization-server/src/test/java/org/springframework/security/oauth2/server/authorization/config/annotation/web/configurers/OidcClientRegistrationTests.java

Lines changed: 38 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -531,8 +531,8 @@ public void requestWhenClientRegistersWithSecretExpirationThenClientRegistration
531531

532532
OidcClientRegistration clientRegistrationResponse = registerClient(clientRegistration);
533533

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);
536536

537537
// Returned response contains expiration date
538538
assertThat(clientRegistrationResponse.getClientSecretExpiresAt())
@@ -685,40 +685,52 @@ public SecurityFilterChain authorizationServerSecurityFilterChain(HttpSecurity h
685685

686686
@EnableWebSecurity
687687
@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 {
691689

690+
// @formatter:off
691+
@Bean
692692
@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();
695712
}
713+
// @formatter:on
696714

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
700726
}
701727

702728
}
703729

704730
@EnableWebSecurity
705731
@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 {
712733

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 {
722734
// @formatter:off
723735
@Bean
724736
@Override
@@ -749,26 +761,12 @@ private Consumer<List<AuthenticationProvider>> configureClientRegistrationConver
749761
return (authenticationProviders) ->
750762
authenticationProviders.forEach((authenticationProvider) -> {
751763
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());
760765
}
761766
});
762767
// @formatter:on
763768
}
764769

765-
protected Converter<OidcClientRegistration, RegisteredClient> registeredClientConverter() {
766-
return null;
767-
}
768-
769-
protected Converter<RegisteredClient, OidcClientRegistration> oidcClientRegistrationConverter() {
770-
return null;
771-
}
772770
}
773771

774772
@EnableWebSecurity
@@ -921,5 +919,4 @@ public RegisteredClient convert(OidcClientRegistration clientRegistration) {
921919
return registeredClientBuilder.build();
922920
}
923921
}
924-
925922
}

0 commit comments

Comments
 (0)