Reputation: 493
After migrating from Spring Cloud Azure 4.x to 5.x, the JdbcOAuth2AuthorizedClientService no longer seems to save the "OAuth2 Authorized Client".
Previous 4.6 code:
@EnableWebSecurity
@Configuration
@EnableJdbcRepositories
public class AzureOauthClientConfiguration extends AadWebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
super.configure(http);
http.authorizeRequests()
.antMatchers("/auth/**")
.authenticated();
}
@Bean
JdbcOAuth2AuthorizedClientService oAuth2AuthorizedClientService(JdbcOperations jdbcOperations, ClientRegistrationRepository clientRegistrationRepository) {
return new JdbcOAuth2AuthorizedClientService(jdbcOperations, clientRegistrationRepository);
}
}
and the 5.x equivalent:
@Configuration(proxyBeanMethods = false)
@EnableWebSecurity()
@EnableJdbcRepositories
public class AzureOauthClientConfiguration {
@Bean
SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
http.apply(AadWebApplicationHttpSecurityConfigurer.aadWebApplication())
.and()
.authorizeHttpRequests()
.requestMatchers("/auth/**")
.authenticated();
return http.build();
}
@Bean
JdbcOAuth2AuthorizedClientService oAuth2AuthorizedClientService(JdbcOperations jdbcOperations, ClientRegistrationRepository clientRegistrationRepository) {
return new JdbcOAuth2AuthorizedClientService(jdbcOperations, clientRegistrationRepository);
}
}
The internal code of both AAD classes seem effectively equivalent. Any pointers on how to make this work or why it no longer works?
Upvotes: 0
Views: 100
Reputation: 493
Not sure if this is the best/correct way, but adding the below bean to the configuration worked:
@Bean
public OAuth2AuthorizedClientRepository authorizedClientRepository(OAuth2AuthorizedClientService authorizedClientService) {
return new AuthenticatedPrincipalOAuth2AuthorizedClientRepository(authorizedClientService);
}
Upvotes: 0