Skip to content

Commit 728b522

Browse files
committed
Add withDefaults Shortcut for Custom Configurers
Issue gh-13204
1 parent f1725b2 commit 728b522

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

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

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,29 @@ public <C extends SecurityConfigurer<O, B>> C apply(C configurer) throws Excepti
144144
return configurer;
145145
}
146146

147+
/**
148+
* Applies a {@link SecurityConfigurerAdapter} to this {@link SecurityBuilder} and
149+
* invokes {@link SecurityConfigurerAdapter#setBuilder(SecurityBuilder)}.
150+
*
151+
* <p>
152+
* A shortcut for applying a configurer as-is, or in other words: <code>
153+
* .with(new MyConfigurer())
154+
* </code>
155+
*
156+
* <p>
157+
* Is identical to: <code>
158+
* .with(new MyConfigurer(), Customizer.withDefaults())
159+
* </code>
160+
* @param configurer
161+
* @return the {@link SecurityBuilder} for further customizations
162+
* @throws Exception
163+
* @since 7.0
164+
*/
165+
@SuppressWarnings("unchecked")
166+
public <C extends SecurityConfigurerAdapter<O, B>> B with(C configurer) throws Exception {
167+
return with(configurer, Customizer.withDefaults());
168+
}
169+
147170
/**
148171
* Applies a {@link SecurityConfigurerAdapter} to this {@link SecurityBuilder} and
149172
* invokes {@link SecurityConfigurerAdapter#setBuilder(SecurityBuilder)}.

0 commit comments

Comments
 (0)