Skip to content

Remove AbstractConfiguredSecurityBuilder apply method #17498

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 11, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -113,24 +113,6 @@ public O getOrBuild() {
}
}

/**
* 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
Expand Down Expand Up @@ -162,7 +144,6 @@ public <C extends SecurityConfigurer<O, B>> C apply(C configurer) throws Excepti
* @throws Exception
* @since 7.0
*/
@SuppressWarnings("unchecked")
public <C extends SecurityConfigurerAdapter<O, B>> B with(C configurer) throws Exception {
return with(configurer, Customizer.withDefaults());
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -60,8 +60,8 @@ public void objectPostProcessorWhenNullThenThrowIllegalArgumentException() {

@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);
}

Expand All @@ -79,7 +79,7 @@ public void getObjectWhenNotBuiltThenThrowIllegalStateException() {
@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);
Expand All @@ -88,7 +88,7 @@ public void buildWhenConfigurerAppliesAnotherConfigurerThenObjectStillBuilds() t
@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);
Expand All @@ -97,7 +97,7 @@ public void buildWhenConfigurerAppliesAndRemoveAnotherConfigurerThenNotConfigure
@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);
Expand All @@ -107,17 +107,17 @@ public void buildWhenConfigurerAppliesAndRemoveAnotherConfigurersThenNotConfigur
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));
}

@Test
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));
}

Expand All @@ -127,8 +127,8 @@ public void removeConfigurersWhenMultipleConfigurersThenConfigurersRemoved() thr
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);
Expand All @@ -142,8 +142,8 @@ public void getConfigurersWhenMultipleConfigurersThenConfigurersReturned() throw
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);
Expand Down
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -630,7 +630,7 @@ static class ApplyCustomDslConfig {

@Bean
SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
http.apply(CustomDsl.customDsl());
http.with(CustomDsl.customDsl());
return http.build();
}

Expand Down
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -118,10 +118,9 @@ static class Config {
@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
}

Expand Down