Now i use spring 2.2.4 for my application. And i have custom starter, for Keycloak(FrontendSpringBootConfiguration.kt) which extend WebSecurityConfigurerAdapter. it's work fine. Now i try upgrade to Spring 2.4.2. And see error: Found WebSecurityConfigurerAdapter as well as SecurityFilterChain. Please select just one. In this release add SecurityFilterChain which add by many AutoConfiguration like ManagementWebSecurityAutoConfiguration, SpringBootWebSecurityConfiguration. All it's Configuration have condition @ConditionalOnDefaultWebSecurity whic match if @ConditionalOnMissingBean({ WebSecurityConfigurerAdapter.class, SecurityFilterChain.class }) I expect that this condition found my custom configuration FrontendSpringBootConfiguration(which extend WebSecurityConfigurerAdapter) and didn't create any SecurityFilterChain. But in logs i see that

ManagementWebSecurityAutoConfiguration matched: - found 'session' scope (OnWebApplicationCondition) - AllNestedConditions 2 matched 0 did not; NestedCondition on DefaultWebSecurityCondition.Beans @ConditionalOnMissingBean (types: org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter,org.springframework.security.web.SecurityFilterChain; SearchStrategy: all) did not find any beans; NestedCondition on DefaultWebSecurityCondition.Classes @ConditionalOnClass found required classes 'org.springframework.security.web.SecurityFilterChain', 'org.springframework.security.config.annotation.web.builders.HttpSecurity' (DefaultWebSecurityCondition)

i can make this work if exclude starters autoconfiguration and import it)

@SpringBootApplication( exclude = [FrontendSpringBootConfiguration::class])
@Import(FrontendSpringBootConfiguration::class)
class PriestBackApplication

fun main(args: Array<String>) {
    SpringApplicationBuilder(PriestBackApplication::class.java)
        .run(*args)
}

But it's look terrible

Comment From: wilkinsona

It sounds like a problem with the ordering of your auto-configuration. When you exclude the auto-configuration class and import it instead, it becomes a user configuration class that is processed before any auto-configuration. The means that it defines its WebSecurityConfigurerAdapter bean before the DefaultWebSecurityCondition is evaluated.

I can't see any auto-configuration ordering annotations on FrontendSpringBootConfiguration so when it's processed as an auto-configuration, there's no guarantee of exactly when it will be processed in relation to other auto-configuration classes. If you want it to cause Boot's default web security to back off then you will need to configure it to be processed before Boot's security auto-configuration. You can either use @AutoConfigureBefore to order it relative to Spring Boot's auto-configuration classes or you can use @AutoConfigureOrder to order it absolutely.

Comment From: Monax111

i tried to do @Order(Ordered.HIGHEST_PRECEDENCE) - negative i tried set many AutoConfigureBefore, but it's problem, becouse i don't now list of all Configuration, which create SecurityFilterChain may be i can do it in runtime? gett all configuration with condition ConditionalOnDefaultWebSecurity and set AutoConfigureBefore on it?

Comment From: Monax111

@wilkinsona maybe there is a way / log / dedug to set up the order correctly? now i see that ManagementWebSecurityAutoConfiguration (haven't Order) cjfigure befre my FrontendSpringBootConfiguration with HIGHEST_PRECEDENCE. But create bean in this configuration have revert order. First create bean from my FrontendSpringBootConfiguration and after ManagementWebSecurityAutoConfiguration.

Comment From: wilkinsona

You need to use @AutoConfigureOrder rather than @Order. Or use @AutoConfigureBefore or @AutoConfigureAfter if you prefer to use relative ordering.

If you want to see the sorting in action, set a break point in AutoConfigurationSorter.

i tried set many AutoConfigureBefore, but it's problem, becouse i don't now list of all Configuration, which create SecurityFilterChain

Absolute ordering is probably a better option in this case. Given that it works when @Imported as a user configuration, you could just use @AutoConfigureOrder(Ordered.HIGHEST_PRECEDENCE).

If you have any further questions, please follow up on Stack Overflow or Gitter. As mentioned in the guidelines for contributing, we prefer to use GitHub issues only for bugs and enhancements.