I try to create a @AutoConfigure springboot3 library following azure example and create a a class with @AutoConfiguration instead of @Configuration below.
@AutoConfiguration
@EnableWebSecurity
@EnableMethodSecurity
public class AadOAuth2ResourceServerSecurityConfig {
/**
* Add configuration logic as needed.
*/
@Bean
public SecurityFilterChain apiFilterChain(HttpSecurity http) throws Exception {
http.apply(AadResourceServerHttpSecurityConfigurer.aadResourceServer())
.and()
.authorizeHttpRequests()
.anyRequest().authenticated();
return http.build();
}
}
So, you can see AadResourceServerHttpSecurityConfigurer
is the dependency.
I also add this class AadOAuth2ResourceServerSecurityConfig
to org.springframework.boot.autoconfigure.AutoConfiguration.imports
for autoconfigure in spring.
The idea is whenever my personal project (like com.myproject package) include the jar of this library and I will have the security layer out of the box.
However, there is an issue when I start the application. I received the error below
Description:
Parameter 0 of method setFilterChains in org.springframework.security.config.annotation.web.configuration.WebSecurityConfiguration required a bean of type 'com.azure.spring.cloud.autoconfigure.implementation.aad.configuration.properties.AadResourceServerProperties' that could not be found.
Action:
Consider defining a bean of type 'com.azure.spring.cloud.autoconfigure.implementation.aad.configuration.properties.AadResourceServerProperties' in your configuration.
Process finished with exit code 1
So, the problem is some bean is not initialized in the azure library.
I try to add the required class AadResourceServerProperties
in AutoConfiguration.imports
file . This indeed solve the error I received before. However, another bean is also missing after I fix this one.
So, I need to add those class in the AutoConfiguration.imports
as well.
However, I notice I see unexpected behaviour from the library because some bean is still missing and it behave differently because of this.
So, my question is How can we ensure the dependency AadResourceServerHttpSecurityConfigurer
can be auto configured like we use the AadResourceServerHttpSecurityConfigurer
with @Configuration?