Skip to content

Commit 5ae1b73

Browse files
committed
Fix Cyclic Bean Dependency
Closes gh-17484
1 parent d8043dc commit 5ae1b73

File tree

3 files changed

+27
-9
lines changed

3 files changed

+27
-9
lines changed

config/src/main/java/org/springframework/security/config/annotation/web/configuration/EnableWebSecurity.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@
8383
@Target(ElementType.TYPE)
8484
@Documented
8585
@Import({ WebSecurityConfiguration.class, SpringWebMvcImportSelector.class, OAuth2ImportSelector.class,
86-
HttpSecurityConfiguration.class, ObservationImportSelector.class })
86+
HttpSecurityConfiguration.class, ObservationImportSelector.class, AuthorizationConfiguration.class })
8787
@EnableGlobalAuthentication
8888
public @interface EnableWebSecurity {
8989

config/src/main/java/org/springframework/security/config/annotation/web/configuration/WebSecurityConfiguration.java

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@
4242
import org.springframework.context.annotation.Bean;
4343
import org.springframework.context.annotation.Configuration;
4444
import org.springframework.context.annotation.DependsOn;
45-
import org.springframework.context.annotation.Fallback;
4645
import org.springframework.context.annotation.ImportAware;
4746
import org.springframework.core.OrderComparator;
4847
import org.springframework.core.Ordered;
@@ -58,7 +57,6 @@
5857
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
5958
import org.springframework.security.config.annotation.web.builders.WebSecurity;
6059
import org.springframework.security.config.crypto.RsaKeyConversionServicePostProcessor;
61-
import org.springframework.security.config.web.PathPatternRequestMatcherBuilderFactoryBean;
6260
import org.springframework.security.context.DelegatingApplicationListener;
6361
import org.springframework.security.core.context.SecurityContextHolderStrategy;
6462
import org.springframework.security.web.FilterChainProxy;
@@ -144,12 +142,6 @@ public WebInvocationPrivilegeEvaluator privilegeEvaluator() {
144142
return this.webSecurity.getPrivilegeEvaluator();
145143
}
146144

147-
@Bean
148-
@Fallback
149-
public PathPatternRequestMatcherBuilderFactoryBean pathPatternRequestMatcherBuilder() {
150-
return new PathPatternRequestMatcherBuilderFactoryBean();
151-
}
152-
153145
/**
154146
* Sets the {@code <SecurityConfigurer<FilterChainProxy, WebSecurityBuilder>}
155147
* instances used to create the web configuration.

config/src/test/java/org/springframework/security/config/annotation/web/configuration/EnableWebSecurityTests.java

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
import org.springframework.test.web.servlet.MockMvc;
3737
import org.springframework.web.bind.annotation.GetMapping;
3838
import org.springframework.web.bind.annotation.RestController;
39+
import org.springframework.web.context.support.AnnotationConfigWebApplicationContext;
3940
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
4041

4142
import static org.assertj.core.api.Assertions.assertThat;
@@ -111,6 +112,15 @@ public void enableWebSecurityWhenProxyBeanMethodsFalseThenBeanProxyingDisabled()
111112
assertThat(parentBean.getChild()).isNotSameAs(childBean);
112113
}
113114

115+
// gh-17484
116+
@Test
117+
void configureWhenEnableWebSecuritySeparateFromSecurityFilterChainThenWires() {
118+
try (AnnotationConfigWebApplicationContext context = new AnnotationConfigWebApplicationContext()) {
119+
context.register(TestConfiguration.class, EnableWebSecurityConfiguration.class);
120+
context.refresh();
121+
}
122+
}
123+
114124
@Configuration
115125
@EnableWebMvc
116126
@EnableWebSecurity(debug = true)
@@ -226,4 +236,20 @@ static class Child {
226236

227237
}
228238

239+
@Configuration(proxyBeanMethods = false)
240+
static class TestConfiguration {
241+
242+
@Bean
243+
SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception {
244+
return http.build();
245+
}
246+
247+
}
248+
249+
@EnableWebSecurity
250+
@Configuration(proxyBeanMethods = false)
251+
static class EnableWebSecurityConfiguration {
252+
253+
}
254+
229255
}

0 commit comments

Comments
 (0)