Remove AbstractConfiguredSecurityBuilder apply

Closes gh-13441

Signed-off-by: DingHao <dh.hiekn@gmail.com>
This commit is contained in:
DingHao 2025-07-08 15:35:39 +08:00 committed by Josh Cummings
parent 0c42b61cc1
commit 5fefdd5bb3
4 changed files with 20 additions and 40 deletions

View File

@ -113,24 +113,6 @@ public abstract class AbstractConfiguredSecurityBuilder<O, B extends SecurityBui
}
}
/**
* Applies a {@link SecurityConfigurerAdapter} to this {@link SecurityBuilder} and
* invokes {@link SecurityConfigurerAdapter#setBuilder(SecurityBuilder)}.
* @param configurer
* @return the {@link SecurityConfigurerAdapter} for further customizations
* @throws Exception
* @deprecated For removal in 7.0. Use
* {@link #with(SecurityConfigurerAdapter, Customizer)} instead.
*/
@Deprecated(since = "6.2", forRemoval = true)
@SuppressWarnings("unchecked")
public <C extends SecurityConfigurerAdapter<O, B>> C apply(C configurer) throws Exception {
configurer.addObjectPostProcessor(this.objectPostProcessor);
configurer.setBuilder((B) this);
add(configurer);
return configurer;
}
/**
* Applies a {@link SecurityConfigurer} to this {@link SecurityBuilder} overriding any
* {@link SecurityConfigurer} of the exact same class. Note that object hierarchies
@ -162,7 +144,6 @@ public abstract class AbstractConfiguredSecurityBuilder<O, B extends SecurityBui
* @throws Exception
* @since 7.0
*/
@SuppressWarnings("unchecked")
public <C extends SecurityConfigurerAdapter<O, B>> B with(C configurer) throws Exception {
return with(configurer, Customizer.withDefaults());
}

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2023 the original author or authors.
* Copyright 2002-2025 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -60,8 +60,8 @@ public class AbstractConfiguredSecurityBuilderTests {
@Test
public void applyWhenDuplicateConfigurerAddedThenDuplicateConfigurerRemoved() throws Exception {
this.builder.apply(new TestSecurityConfigurer());
this.builder.apply(new TestSecurityConfigurer());
this.builder.with(new TestSecurityConfigurer());
this.builder.with(new TestSecurityConfigurer());
assertThat(this.builder.getConfigurers(TestSecurityConfigurer.class)).hasSize(1);
}
@ -79,7 +79,7 @@ public class AbstractConfiguredSecurityBuilderTests {
@Test
public void buildWhenConfigurerAppliesAnotherConfigurerThenObjectStillBuilds() throws Exception {
DelegateSecurityConfigurer.CONFIGURER = mock(SecurityConfigurer.class);
this.builder.apply(new DelegateSecurityConfigurer());
this.builder.with(new DelegateSecurityConfigurer());
this.builder.build();
verify(DelegateSecurityConfigurer.CONFIGURER).init(this.builder);
verify(DelegateSecurityConfigurer.CONFIGURER).configure(this.builder);
@ -88,7 +88,7 @@ public class AbstractConfiguredSecurityBuilderTests {
@Test
public void buildWhenConfigurerAppliesAndRemoveAnotherConfigurerThenNotConfigured() throws Exception {
ApplyAndRemoveSecurityConfigurer.CONFIGURER = mock(SecurityConfigurer.class);
this.builder.apply(new ApplyAndRemoveSecurityConfigurer());
this.builder.with(new ApplyAndRemoveSecurityConfigurer());
this.builder.build();
verify(ApplyAndRemoveSecurityConfigurer.CONFIGURER, never()).init(this.builder);
verify(ApplyAndRemoveSecurityConfigurer.CONFIGURER, never()).configure(this.builder);
@ -97,7 +97,7 @@ public class AbstractConfiguredSecurityBuilderTests {
@Test
public void buildWhenConfigurerAppliesAndRemoveAnotherConfigurersThenNotConfigured() throws Exception {
ApplyAndRemoveAllSecurityConfigurer.CONFIGURER = mock(SecurityConfigurer.class);
this.builder.apply(new ApplyAndRemoveAllSecurityConfigurer());
this.builder.with(new ApplyAndRemoveAllSecurityConfigurer());
this.builder.build();
verify(ApplyAndRemoveAllSecurityConfigurer.CONFIGURER, never()).init(this.builder);
verify(ApplyAndRemoveAllSecurityConfigurer.CONFIGURER, never()).configure(this.builder);
@ -107,8 +107,8 @@ public class AbstractConfiguredSecurityBuilderTests {
public void getConfigurerWhenMultipleConfigurersThenThrowIllegalStateException() throws Exception {
TestConfiguredSecurityBuilder builder = new TestConfiguredSecurityBuilder(mock(ObjectPostProcessor.class),
true);
builder.apply(new DelegateSecurityConfigurer());
builder.apply(new DelegateSecurityConfigurer());
builder.with(new DelegateSecurityConfigurer());
builder.with(new DelegateSecurityConfigurer());
assertThatIllegalStateException().isThrownBy(() -> builder.getConfigurer(DelegateSecurityConfigurer.class));
}
@ -116,8 +116,8 @@ public class AbstractConfiguredSecurityBuilderTests {
public void removeConfigurerWhenMultipleConfigurersThenThrowIllegalStateException() throws Exception {
TestConfiguredSecurityBuilder builder = new TestConfiguredSecurityBuilder(mock(ObjectPostProcessor.class),
true);
builder.apply(new DelegateSecurityConfigurer());
builder.apply(new DelegateSecurityConfigurer());
builder.with(new DelegateSecurityConfigurer());
builder.with(new DelegateSecurityConfigurer());
assertThatIllegalStateException().isThrownBy(() -> builder.removeConfigurer(DelegateSecurityConfigurer.class));
}
@ -127,8 +127,8 @@ public class AbstractConfiguredSecurityBuilderTests {
DelegateSecurityConfigurer configurer2 = new DelegateSecurityConfigurer();
TestConfiguredSecurityBuilder builder = new TestConfiguredSecurityBuilder(mock(ObjectPostProcessor.class),
true);
builder.apply(configurer1);
builder.apply(configurer2);
builder.with(configurer1);
builder.with(configurer2);
List<DelegateSecurityConfigurer> removedConfigurers = builder
.removeConfigurers(DelegateSecurityConfigurer.class);
assertThat(removedConfigurers).hasSize(2);
@ -142,8 +142,8 @@ public class AbstractConfiguredSecurityBuilderTests {
DelegateSecurityConfigurer configurer2 = new DelegateSecurityConfigurer();
TestConfiguredSecurityBuilder builder = new TestConfiguredSecurityBuilder(mock(ObjectPostProcessor.class),
true);
builder.apply(configurer1);
builder.apply(configurer2);
builder.with(configurer1);
builder.with(configurer2);
List<DelegateSecurityConfigurer> configurers = builder.getConfigurers(DelegateSecurityConfigurer.class);
assertThat(configurers).hasSize(2);
assertThat(configurers).containsExactly(configurer1, configurer2);

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2024 the original author or authors.
* Copyright 2002-2025 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -630,7 +630,7 @@ public class HttpSecurityConfigurationTests {
@Bean
SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
http.apply(CustomDsl.customDsl());
http.with(CustomDsl.customDsl());
return http.build();
}

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2022 the original author or authors.
* Copyright 2002-2025 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -118,10 +118,9 @@ public class CustomHttpSecurityConfigurerTests {
@Bean
SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
// @formatter:off
http
.apply(CustomConfigurer.customConfigurer())
.loginPage("/custom");
return http.build();
return http
.with(CustomConfigurer.customConfigurer(), (c) -> c.loginPage("/custom"))
.build();
// @formatter:on
}