Skip to content

Commit 5fefdd5

Browse files
kse-musicjzheaux
authored andcommitted
Remove AbstractConfiguredSecurityBuilder apply
Closes gh-13441 Signed-off-by: DingHao <dh.hiekn@gmail.com>
1 parent 0c42b61 commit 5fefdd5

File tree

4 files changed

+20
-40
lines changed

4 files changed

+20
-40
lines changed

config/src/main/java/org/springframework/security/config/annotation/AbstractConfiguredSecurityBuilder.java

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -113,24 +113,6 @@ public O getOrBuild() {
113113
}
114114
}
115115

116-
/**
117-
* Applies a {@link SecurityConfigurerAdapter} to this {@link SecurityBuilder} and
118-
* invokes {@link SecurityConfigurerAdapter#setBuilder(SecurityBuilder)}.
119-
* @param configurer
120-
* @return the {@link SecurityConfigurerAdapter} for further customizations
121-
* @throws Exception
122-
* @deprecated For removal in 7.0. Use
123-
* {@link #with(SecurityConfigurerAdapter, Customizer)} instead.
124-
*/
125-
@Deprecated(since = "6.2", forRemoval = true)
126-
@SuppressWarnings("unchecked")
127-
public <C extends SecurityConfigurerAdapter<O, B>> C apply(C configurer) throws Exception {
128-
configurer.addObjectPostProcessor(this.objectPostProcessor);
129-
configurer.setBuilder((B) this);
130-
add(configurer);
131-
return configurer;
132-
}
133-
134116
/**
135117
* Applies a {@link SecurityConfigurer} to this {@link SecurityBuilder} overriding any
136118
* {@link SecurityConfigurer} of the exact same class. Note that object hierarchies
@@ -162,7 +144,6 @@ public <C extends SecurityConfigurer<O, B>> C apply(C configurer) throws Excepti
162144
* @throws Exception
163145
* @since 7.0
164146
*/
165-
@SuppressWarnings("unchecked")
166147
public <C extends SecurityConfigurerAdapter<O, B>> B with(C configurer) throws Exception {
167148
return with(configurer, Customizer.withDefaults());
168149
}

config/src/test/java/org/springframework/security/config/annotation/web/AbstractConfiguredSecurityBuilderTests.java

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2023 the original author or authors.
2+
* Copyright 2002-2025 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -60,8 +60,8 @@ public void objectPostProcessorWhenNullThenThrowIllegalArgumentException() {
6060

6161
@Test
6262
public void applyWhenDuplicateConfigurerAddedThenDuplicateConfigurerRemoved() throws Exception {
63-
this.builder.apply(new TestSecurityConfigurer());
64-
this.builder.apply(new TestSecurityConfigurer());
63+
this.builder.with(new TestSecurityConfigurer());
64+
this.builder.with(new TestSecurityConfigurer());
6565
assertThat(this.builder.getConfigurers(TestSecurityConfigurer.class)).hasSize(1);
6666
}
6767

@@ -79,7 +79,7 @@ public void getObjectWhenNotBuiltThenThrowIllegalStateException() {
7979
@Test
8080
public void buildWhenConfigurerAppliesAnotherConfigurerThenObjectStillBuilds() throws Exception {
8181
DelegateSecurityConfigurer.CONFIGURER = mock(SecurityConfigurer.class);
82-
this.builder.apply(new DelegateSecurityConfigurer());
82+
this.builder.with(new DelegateSecurityConfigurer());
8383
this.builder.build();
8484
verify(DelegateSecurityConfigurer.CONFIGURER).init(this.builder);
8585
verify(DelegateSecurityConfigurer.CONFIGURER).configure(this.builder);
@@ -88,7 +88,7 @@ public void buildWhenConfigurerAppliesAnotherConfigurerThenObjectStillBuilds() t
8888
@Test
8989
public void buildWhenConfigurerAppliesAndRemoveAnotherConfigurerThenNotConfigured() throws Exception {
9090
ApplyAndRemoveSecurityConfigurer.CONFIGURER = mock(SecurityConfigurer.class);
91-
this.builder.apply(new ApplyAndRemoveSecurityConfigurer());
91+
this.builder.with(new ApplyAndRemoveSecurityConfigurer());
9292
this.builder.build();
9393
verify(ApplyAndRemoveSecurityConfigurer.CONFIGURER, never()).init(this.builder);
9494
verify(ApplyAndRemoveSecurityConfigurer.CONFIGURER, never()).configure(this.builder);
@@ -97,7 +97,7 @@ public void buildWhenConfigurerAppliesAndRemoveAnotherConfigurerThenNotConfigure
9797
@Test
9898
public void buildWhenConfigurerAppliesAndRemoveAnotherConfigurersThenNotConfigured() throws Exception {
9999
ApplyAndRemoveAllSecurityConfigurer.CONFIGURER = mock(SecurityConfigurer.class);
100-
this.builder.apply(new ApplyAndRemoveAllSecurityConfigurer());
100+
this.builder.with(new ApplyAndRemoveAllSecurityConfigurer());
101101
this.builder.build();
102102
verify(ApplyAndRemoveAllSecurityConfigurer.CONFIGURER, never()).init(this.builder);
103103
verify(ApplyAndRemoveAllSecurityConfigurer.CONFIGURER, never()).configure(this.builder);
@@ -107,17 +107,17 @@ public void buildWhenConfigurerAppliesAndRemoveAnotherConfigurersThenNotConfigur
107107
public void getConfigurerWhenMultipleConfigurersThenThrowIllegalStateException() throws Exception {
108108
TestConfiguredSecurityBuilder builder = new TestConfiguredSecurityBuilder(mock(ObjectPostProcessor.class),
109109
true);
110-
builder.apply(new DelegateSecurityConfigurer());
111-
builder.apply(new DelegateSecurityConfigurer());
110+
builder.with(new DelegateSecurityConfigurer());
111+
builder.with(new DelegateSecurityConfigurer());
112112
assertThatIllegalStateException().isThrownBy(() -> builder.getConfigurer(DelegateSecurityConfigurer.class));
113113
}
114114

115115
@Test
116116
public void removeConfigurerWhenMultipleConfigurersThenThrowIllegalStateException() throws Exception {
117117
TestConfiguredSecurityBuilder builder = new TestConfiguredSecurityBuilder(mock(ObjectPostProcessor.class),
118118
true);
119-
builder.apply(new DelegateSecurityConfigurer());
120-
builder.apply(new DelegateSecurityConfigurer());
119+
builder.with(new DelegateSecurityConfigurer());
120+
builder.with(new DelegateSecurityConfigurer());
121121
assertThatIllegalStateException().isThrownBy(() -> builder.removeConfigurer(DelegateSecurityConfigurer.class));
122122
}
123123

@@ -127,8 +127,8 @@ public void removeConfigurersWhenMultipleConfigurersThenConfigurersRemoved() thr
127127
DelegateSecurityConfigurer configurer2 = new DelegateSecurityConfigurer();
128128
TestConfiguredSecurityBuilder builder = new TestConfiguredSecurityBuilder(mock(ObjectPostProcessor.class),
129129
true);
130-
builder.apply(configurer1);
131-
builder.apply(configurer2);
130+
builder.with(configurer1);
131+
builder.with(configurer2);
132132
List<DelegateSecurityConfigurer> removedConfigurers = builder
133133
.removeConfigurers(DelegateSecurityConfigurer.class);
134134
assertThat(removedConfigurers).hasSize(2);
@@ -142,8 +142,8 @@ public void getConfigurersWhenMultipleConfigurersThenConfigurersReturned() throw
142142
DelegateSecurityConfigurer configurer2 = new DelegateSecurityConfigurer();
143143
TestConfiguredSecurityBuilder builder = new TestConfiguredSecurityBuilder(mock(ObjectPostProcessor.class),
144144
true);
145-
builder.apply(configurer1);
146-
builder.apply(configurer2);
145+
builder.with(configurer1);
146+
builder.with(configurer2);
147147
List<DelegateSecurityConfigurer> configurers = builder.getConfigurers(DelegateSecurityConfigurer.class);
148148
assertThat(configurers).hasSize(2);
149149
assertThat(configurers).containsExactly(configurer1, configurer2);

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2024 the original author or authors.
2+
* Copyright 2002-2025 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -630,7 +630,7 @@ static class ApplyCustomDslConfig {
630630

631631
@Bean
632632
SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
633-
http.apply(CustomDsl.customDsl());
633+
http.with(CustomDsl.customDsl());
634634
return http.build();
635635
}
636636

config/src/test/java/org/springframework/security/config/http/customconfigurer/CustomHttpSecurityConfigurerTests.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2022 the original author or authors.
2+
* Copyright 2002-2025 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -118,10 +118,9 @@ static class Config {
118118
@Bean
119119
SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
120120
// @formatter:off
121-
http
122-
.apply(CustomConfigurer.customConfigurer())
123-
.loginPage("/custom");
124-
return http.build();
121+
return http
122+
.with(CustomConfigurer.customConfigurer(), (c) -> c.loginPage("/custom"))
123+
.build();
125124
// @formatter:on
126125
}
127126

0 commit comments

Comments
 (0)