mirror of
https://github.com/spring-projects/spring-security.git
synced 2025-07-12 21:33:30 +00:00
Fix Cyclic Bean Dependency
Closes gh-17484
This commit is contained in:
parent
d8043dc8a7
commit
5ae1b73bae
@ -83,7 +83,7 @@ import org.springframework.security.web.SecurityFilterChain;
|
|||||||
@Target(ElementType.TYPE)
|
@Target(ElementType.TYPE)
|
||||||
@Documented
|
@Documented
|
||||||
@Import({ WebSecurityConfiguration.class, SpringWebMvcImportSelector.class, OAuth2ImportSelector.class,
|
@Import({ WebSecurityConfiguration.class, SpringWebMvcImportSelector.class, OAuth2ImportSelector.class,
|
||||||
HttpSecurityConfiguration.class, ObservationImportSelector.class })
|
HttpSecurityConfiguration.class, ObservationImportSelector.class, AuthorizationConfiguration.class })
|
||||||
@EnableGlobalAuthentication
|
@EnableGlobalAuthentication
|
||||||
public @interface EnableWebSecurity {
|
public @interface EnableWebSecurity {
|
||||||
|
|
||||||
|
@ -42,7 +42,6 @@ import org.springframework.beans.factory.support.ManagedList;
|
|||||||
import org.springframework.context.annotation.Bean;
|
import org.springframework.context.annotation.Bean;
|
||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
import org.springframework.context.annotation.DependsOn;
|
import org.springframework.context.annotation.DependsOn;
|
||||||
import org.springframework.context.annotation.Fallback;
|
|
||||||
import org.springframework.context.annotation.ImportAware;
|
import org.springframework.context.annotation.ImportAware;
|
||||||
import org.springframework.core.OrderComparator;
|
import org.springframework.core.OrderComparator;
|
||||||
import org.springframework.core.Ordered;
|
import org.springframework.core.Ordered;
|
||||||
@ -58,7 +57,6 @@ import org.springframework.security.config.annotation.web.WebSecurityConfigurer;
|
|||||||
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
|
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
|
||||||
import org.springframework.security.config.annotation.web.builders.WebSecurity;
|
import org.springframework.security.config.annotation.web.builders.WebSecurity;
|
||||||
import org.springframework.security.config.crypto.RsaKeyConversionServicePostProcessor;
|
import org.springframework.security.config.crypto.RsaKeyConversionServicePostProcessor;
|
||||||
import org.springframework.security.config.web.PathPatternRequestMatcherBuilderFactoryBean;
|
|
||||||
import org.springframework.security.context.DelegatingApplicationListener;
|
import org.springframework.security.context.DelegatingApplicationListener;
|
||||||
import org.springframework.security.core.context.SecurityContextHolderStrategy;
|
import org.springframework.security.core.context.SecurityContextHolderStrategy;
|
||||||
import org.springframework.security.web.FilterChainProxy;
|
import org.springframework.security.web.FilterChainProxy;
|
||||||
@ -144,12 +142,6 @@ public class WebSecurityConfiguration implements ImportAware {
|
|||||||
return this.webSecurity.getPrivilegeEvaluator();
|
return this.webSecurity.getPrivilegeEvaluator();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Bean
|
|
||||||
@Fallback
|
|
||||||
public PathPatternRequestMatcherBuilderFactoryBean pathPatternRequestMatcherBuilder() {
|
|
||||||
return new PathPatternRequestMatcherBuilderFactoryBean();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the {@code <SecurityConfigurer<FilterChainProxy, WebSecurityBuilder>}
|
* Sets the {@code <SecurityConfigurer<FilterChainProxy, WebSecurityBuilder>}
|
||||||
* instances used to create the web configuration.
|
* instances used to create the web configuration.
|
||||||
|
@ -36,6 +36,7 @@ import org.springframework.security.web.SecurityFilterChain;
|
|||||||
import org.springframework.test.web.servlet.MockMvc;
|
import org.springframework.test.web.servlet.MockMvc;
|
||||||
import org.springframework.web.bind.annotation.GetMapping;
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
import org.springframework.web.context.support.AnnotationConfigWebApplicationContext;
|
||||||
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
|
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
|
||||||
|
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
@ -111,6 +112,15 @@ public class EnableWebSecurityTests {
|
|||||||
assertThat(parentBean.getChild()).isNotSameAs(childBean);
|
assertThat(parentBean.getChild()).isNotSameAs(childBean);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// gh-17484
|
||||||
|
@Test
|
||||||
|
void configureWhenEnableWebSecuritySeparateFromSecurityFilterChainThenWires() {
|
||||||
|
try (AnnotationConfigWebApplicationContext context = new AnnotationConfigWebApplicationContext()) {
|
||||||
|
context.register(TestConfiguration.class, EnableWebSecurityConfiguration.class);
|
||||||
|
context.refresh();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Configuration
|
@Configuration
|
||||||
@EnableWebMvc
|
@EnableWebMvc
|
||||||
@EnableWebSecurity(debug = true)
|
@EnableWebSecurity(debug = true)
|
||||||
@ -226,4 +236,20 @@ public class EnableWebSecurityTests {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Configuration(proxyBeanMethods = false)
|
||||||
|
static class TestConfiguration {
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception {
|
||||||
|
return http.build();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@EnableWebSecurity
|
||||||
|
@Configuration(proxyBeanMethods = false)
|
||||||
|
static class EnableWebSecurityConfiguration {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user