Skip to content

Commit 45a1447

Browse files
committed
Use HttpSecurity Lambda DSL in JavaDoc
Issue gh-13067
1 parent 1435e0f commit 45a1447

20 files changed

+81
-50
lines changed

config/src/main/java/org/springframework/security/config/annotation/web/builders/HttpSecurity.java

Lines changed: 26 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,8 @@
103103
import org.springframework.web.filter.CorsFilter;
104104
import org.springframework.web.servlet.handler.HandlerMappingIntrospector;
105105

106+
import static org.springframework.security.config.Customizer.withDefaults;
107+
106108
/**
107109
* A {@link HttpSecurity} is similar to Spring Security's XML <http> element in the
108110
* namespace configuration. It allows configuring web based security for specific http
@@ -219,8 +221,8 @@ private ApplicationContext getContext() {
219221
/**
220222
* Adds the Security headers to the response. This is activated by default when using
221223
* {@link EnableWebSecurity}. Accepting the default provided by
222-
* {@link EnableWebSecurity} or only invoking {@link #headers()} without invoking
223-
* additional methods on it, is the equivalent of:
224+
* {@link EnableWebSecurity} or only invoking {@link #headers(withDefaults())} without
225+
* invoking additional methods on it, is the equivalent of:
224226
*
225227
* <pre>
226228
* &#064;Configuration
@@ -266,8 +268,8 @@ private ApplicationContext getContext() {
266268
*
267269
* You can enable only a few of the headers by first invoking
268270
* {@link HeadersConfigurer#defaultsDisabled()} and then invoking the appropriate
269-
* methods on the {@link #headers()} result. For example, the following will enable
270-
* {@link HeadersConfigurer#cacheControl()} and
271+
* methods on the {@link #headers(withDefaults())} result. For example, the following
272+
* will enable {@link HeadersConfigurer#cacheControl()} and
271273
* {@link HeadersConfigurer#frameOptions()} only.
272274
*
273275
* <pre>
@@ -331,7 +333,8 @@ public HeadersConfigurer<HttpSecurity> headers() throws Exception {
331333
* <h2>Example Configurations</h2>
332334
*
333335
* Accepting the default provided by {@link EnableWebSecurity} or only invoking
334-
* {@link #headers()} without invoking additional methods on it, is the equivalent of:
336+
* {@link #headers(Customizer)} without invoking additional methods on it, is the
337+
* equivalent of:
335338
*
336339
* <pre>
337340
* &#064;Configuration
@@ -372,9 +375,9 @@ public HeadersConfigurer<HttpSecurity> headers() throws Exception {
372375
*
373376
* You can enable only a few of the headers by first invoking
374377
* {@link HeadersConfigurer#defaultsDisabled()} and then invoking the appropriate
375-
* methods on the {@link #headers()} result. For example, the following will enable
376-
* {@link HeadersConfigurer#cacheControl()} and
377-
* {@link HeadersConfigurer#frameOptions()} only.
378+
* methods on the {@link #headers(Customizer)} result. For example, the following will
379+
* enable {@link HeadersConfigurer#cacheControl(Customizer)} and
380+
* {@link HeadersConfigurer#frameOptions(Customizer)} only.
378381
*
379382
* <pre>
380383
* &#064;Configuration
@@ -397,7 +400,7 @@ public HeadersConfigurer<HttpSecurity> headers() throws Exception {
397400
*
398401
* You can also choose to keep the defaults but explicitly disable a subset of
399402
* headers. For example, the following will enable all the default headers except
400-
* {@link HeadersConfigurer#frameOptions()}.
403+
* {@link HeadersConfigurer#frameOptions(Customizer)}.
401404
*
402405
* <pre>
403406
* &#064;Configuration
@@ -615,9 +618,10 @@ public HttpSecurity sessionManagement(
615618
* {@link HttpSecurity#getSharedObject(Class)}. Other provided
616619
* {@link SecurityConfigurer} objects use this configured {@link PortMapper} as a
617620
* default {@link PortMapper} when redirecting from HTTP to HTTPS or from HTTPS to
618-
* HTTP (for example when used in combination with {@link #requiresChannel()}. By
619-
* default Spring Security uses a {@link PortMapperImpl} which maps the HTTP port 8080
620-
* to the HTTPS port 8443 and the HTTP port of 80 to the HTTPS port of 443.
621+
* HTTP (for example when used in combination with
622+
* {@link #requiresChannel(Customizer)} )}. By default Spring Security uses a
623+
* {@link PortMapperImpl} which maps the HTTP port 8080 to the HTTPS port 8443 and the
624+
* HTTP port of 80 to the HTTPS port of 443.
621625
*
622626
* <h2>Example Configuration</h2>
623627
*
@@ -657,7 +661,7 @@ public HttpSecurity sessionManagement(
657661
* <a href=
658662
* "https://docs.spring.io/spring-security/reference/migration-7/configuration.html#_use_the_lambda_dsl">documentation</a>
659663
* for more details.
660-
* @see #requiresChannel()
664+
* @see #requiresChannel(withDefaults())
661665
*/
662666
@Deprecated(since = "6.1", forRemoval = true)
663667
public PortMapperConfigurer<HttpSecurity> portMapper() throws Exception {
@@ -669,9 +673,10 @@ public PortMapperConfigurer<HttpSecurity> portMapper() throws Exception {
669673
* {@link HttpSecurity#getSharedObject(Class)}. Other provided
670674
* {@link SecurityConfigurer} objects use this configured {@link PortMapper} as a
671675
* default {@link PortMapper} when redirecting from HTTP to HTTPS or from HTTPS to
672-
* HTTP (for example when used in combination with {@link #requiresChannel()}. By
673-
* default Spring Security uses a {@link PortMapperImpl} which maps the HTTP port 8080
674-
* to the HTTPS port 8443 and the HTTP port of 80 to the HTTPS port of 443.
676+
* HTTP (for example when used in combination with
677+
* {@link #requiresChannel(withDefaults())}. By default Spring Security uses a
678+
* {@link PortMapperImpl} which maps the HTTP port 8080 to the HTTPS port 8443 and the
679+
* HTTP port of 80 to the HTTPS port of 443.
675680
*
676681
* <h2>Example Configuration</h2>
677682
*
@@ -714,7 +719,7 @@ public PortMapperConfigurer<HttpSecurity> portMapper() throws Exception {
714719
* {@link PortMapperConfigurer}
715720
* @return the {@link HttpSecurity} for further customizations
716721
* @throws Exception
717-
* @see #requiresChannel()
722+
* @see #requiresChannel(Customizer)
718723
*/
719724
public HttpSecurity portMapper(Customizer<PortMapperConfigurer<HttpSecurity>> portMapperCustomizer)
720725
throws Exception {
@@ -1776,7 +1781,7 @@ public HttpSecurity csrf(Customizer<CsrfConfigurer<HttpSecurity>> csrfCustomizer
17761781
* Provides logout support. This is automatically applied when using
17771782
* {@link EnableWebSecurity}. The default is that accessing the URL "/logout" will log
17781783
* the user out by invalidating the HTTP Session, cleaning up any
1779-
* {@link #rememberMe()} authentication that was configured, clearing the
1784+
* {@link #rememberMe(Customizer)} authentication that was configured, clearing the
17801785
* {@link SecurityContextHolder}, and then redirect to "/login?success".
17811786
*
17821787
* <h2>Example Custom Configuration</h2>
@@ -1827,8 +1832,8 @@ public LogoutConfigurer<HttpSecurity> logout() throws Exception {
18271832
* Provides logout support. This is automatically applied when using
18281833
* {@link EnableWebSecurity}. The default is that accessing the URL "/logout" will log
18291834
* the user out by invalidating the HTTP Session, cleaning up any
1830-
* {@link #rememberMe()} authentication that was configured, clearing the
1831-
* {@link SecurityContextHolder}, and then redirect to "/login?success".
1835+
* {@link #rememberMe(withDefaults())} authentication that was configured, clearing
1836+
* the {@link SecurityContextHolder}, and then redirect to "/login?success".
18321837
*
18331838
* <h2>Example Custom Configuration</h2>
18341839
*
@@ -2499,7 +2504,7 @@ public HttpSecurity saml2Logout(Customizer<Saml2LogoutConfigurer<HttpSecurity>>
24992504
* {@link RelyingPartyRegistration}(s) are composed within a
25002505
* {@link RelyingPartyRegistrationRepository}, which is <b>required</b> and must be
25012506
* registered with the {@link ApplicationContext} or configured via
2502-
* {@link #saml2Login()}.<br>
2507+
* {@link #saml2Login(withDefaults())}.<br>
25032508
* <br>
25042509
*
25052510
* The default configuration provides an auto-generated logout endpoint at

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,9 @@
4646
*
4747
* &#064;Bean
4848
* public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception {
49-
* http.authorizeHttpRequests().requestMatchers(&quot;/public/**&quot;).permitAll().anyRequest()
50-
* .hasRole(&quot;USER&quot;).and()
49+
* http.authorizeHttpRequests((authorize) -&gt; authorize
50+
* .requestMatchers(&quot;/public/**&quot;).permitAll()
51+
* .anyRequest().hasRole(&quot;USER&quot;))
5152
* // Possibly more configuration ...
5253
* .formLogin() // enable form based log in
5354
* // set permitAll for all URLs associated with Form Login

config/src/main/java/org/springframework/security/config/annotation/web/configurers/AnonymousConfigurer.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121

2222
import org.springframework.security.authentication.AnonymousAuthenticationProvider;
2323
import org.springframework.security.authentication.AuthenticationProvider;
24+
import org.springframework.security.config.Customizer;
2425
import org.springframework.security.config.annotation.SecurityConfigurer;
2526
import org.springframework.security.config.annotation.web.HttpSecurityBuilder;
2627
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
@@ -57,7 +58,7 @@ public final class AnonymousConfigurer<H extends HttpSecurityBuilder<H>>
5758

5859
/**
5960
* Creates a new instance
60-
* @see HttpSecurity#anonymous()
61+
* @see HttpSecurity#anonymous(Customizer)
6162
*/
6263
public AnonymousConfigurer() {
6364
}

config/src/main/java/org/springframework/security/config/annotation/web/configurers/ChannelSecurityConfigurer.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@
4343
import org.springframework.security.web.access.intercept.DefaultFilterInvocationSecurityMetadataSource;
4444
import org.springframework.security.web.util.matcher.RequestMatcher;
4545

46+
import static org.springframework.security.config.Customizer.withDefaults;
47+
4648
/**
4749
* Adds channel security (i.e. requires HTTPS or HTTP) to an application. In order for
4850
* {@link ChannelSecurityConfigurer} to be useful, at least one {@link RequestMatcher}
@@ -96,7 +98,7 @@ public final class ChannelSecurityConfigurer<H extends HttpSecurityBuilder<H>>
9698

9799
/**
98100
* Creates a new instance
99-
* @see HttpSecurity#requiresChannel()
101+
* @see HttpSecurity#requiresChannel(Customizer)
100102
*/
101103
public ChannelSecurityConfigurer(ApplicationContext context) {
102104
this.REGISTRY = new ChannelRequestMatcherRegistry(context);

config/src/main/java/org/springframework/security/config/annotation/web/configurers/CorsConfigurer.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
import org.springframework.beans.factory.NoSuchBeanDefinitionException;
2020
import org.springframework.context.ApplicationContext;
21+
import org.springframework.security.config.Customizer;
2122
import org.springframework.security.config.annotation.web.HttpSecurityBuilder;
2223
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
2324
import org.springframework.util.Assert;
@@ -57,7 +58,7 @@ public class CorsConfigurer<H extends HttpSecurityBuilder<H>> extends AbstractHt
5758
/**
5859
* Creates a new instance
5960
*
60-
* @see HttpSecurity#cors()
61+
* @see HttpSecurity#cors(Customizer)
6162
*/
6263
public CorsConfigurer() {
6364
}

config/src/main/java/org/springframework/security/config/annotation/web/configurers/CsrfConfigurer.java

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727

2828
import org.springframework.context.ApplicationContext;
2929
import org.springframework.security.access.AccessDeniedException;
30+
import org.springframework.security.config.Customizer;
3031
import org.springframework.security.config.annotation.web.AbstractRequestMatcherRegistry;
3132
import org.springframework.security.config.annotation.web.HttpSecurityBuilder;
3233
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
@@ -56,6 +57,8 @@
5657
import org.springframework.util.Assert;
5758
import org.springframework.util.StringUtils;
5859

60+
import static org.springframework.security.config.Customizer.withDefaults;
61+
5962
/**
6063
* Adds
6164
* <a href="https://www.owasp.org/index.php/Cross-Site_Request_Forgery_(CSRF)" >CSRF</a>
@@ -103,7 +106,7 @@ public final class CsrfConfigurer<H extends HttpSecurityBuilder<H>>
103106

104107
/**
105108
* Creates a new instance
106-
* @see HttpSecurity#csrf()
109+
* @see HttpSecurity#csrf(Customizer)
107110
*/
108111
public CsrfConfigurer(ApplicationContext context) {
109112
this.context = context;
@@ -163,9 +166,8 @@ public CsrfConfigurer<H> csrfTokenRequestHandler(CsrfTokenRequestHandler request
163166
*
164167
* <pre>
165168
* http
166-
* .csrf()
167-
* .ignoringRequestMatchers((request) -&gt; "XMLHttpRequest".equals(request.getHeader("X-Requested-With")))
168-
* .and()
169+
* .csrf((csrf) -&gt; csrf
170+
* .ignoringRequestMatchers((request) -&gt; "XMLHttpRequest".equals(request.getHeader("X-Requested-With"))))
169171
* ...
170172
* </pre>
171173
*
@@ -191,9 +193,8 @@ public CsrfConfigurer<H> ignoringRequestMatchers(RequestMatcher... requestMatche
191193
*
192194
* <pre>
193195
* http
194-
* .csrf()
195-
* .ignoringRequestMatchers("/sockjs/**")
196-
* .and()
196+
* .csrf((csrf) -&gt; csrf
197+
* .ignoringRequestMatchers("/sockjs/**"))
197198
* ...
198199
* </pre>
199200
*

config/src/main/java/org/springframework/security/config/annotation/web/configurers/ExceptionHandlingConfigurer.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
import java.util.LinkedHashMap;
2020

21+
import org.springframework.security.config.Customizer;
2122
import org.springframework.security.config.annotation.web.HttpSecurityBuilder;
2223
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
2324
import org.springframework.security.web.AuthenticationEntryPoint;
@@ -76,7 +77,7 @@ public final class ExceptionHandlingConfigurer<H extends HttpSecurityBuilder<H>>
7677

7778
/**
7879
* Creates a new instance
79-
* @see HttpSecurity#exceptionHandling()
80+
* @see HttpSecurity#exceptionHandling(Customizer)
8081
*/
8182
public ExceptionHandlingConfigurer() {
8283
}

config/src/main/java/org/springframework/security/config/annotation/web/configurers/ExpressionUrlAuthorizationConfigurer.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import org.springframework.security.access.expression.SecurityExpressionHandler;
3030
import org.springframework.security.access.hierarchicalroles.RoleHierarchy;
3131
import org.springframework.security.authentication.AuthenticationTrustResolver;
32+
import org.springframework.security.config.Customizer;
3233
import org.springframework.security.config.ObjectPostProcessor;
3334
import org.springframework.security.config.annotation.web.HttpSecurityBuilder;
3435
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
@@ -41,6 +42,8 @@
4142
import org.springframework.util.Assert;
4243
import org.springframework.util.StringUtils;
4344

45+
import static org.springframework.security.config.Customizer.withDefaults;
46+
4447
/**
4548
* Adds URL based authorization based upon SpEL expressions to an application. At least
4649
* one {@link org.springframework.web.bind.annotation.RequestMapping} needs to be mapped
@@ -77,7 +80,7 @@
7780
* @author Yanming Zhou
7881
* @author Ngoc Nhan
7982
* @since 3.2
80-
* @see org.springframework.security.config.annotation.web.builders.HttpSecurity#authorizeRequests()
83+
* @see org.springframework.security.config.annotation.web.builders.HttpSecurity#authorizeRequests(Customizer)
8184
* @deprecated Use {@link AuthorizeHttpRequestsConfigurer} instead
8285
*/
8386
@Deprecated
@@ -104,7 +107,7 @@ public final class ExpressionUrlAuthorizationConfigurer<H extends HttpSecurityBu
104107

105108
/**
106109
* Creates a new instance
107-
* @see HttpSecurity#authorizeRequests()
110+
* @see HttpSecurity#authorizeRequests(Customizer)
108111
*/
109112
public ExpressionUrlAuthorizationConfigurer(ApplicationContext context) {
110113
GrantedAuthorityDefaults grantedAuthorityDefaults = context.getBeanProvider(GrantedAuthorityDefaults.class)

config/src/main/java/org/springframework/security/config/annotation/web/configurers/FormLoginConfigurer.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
package org.springframework.security.config.annotation.web.configurers;
1818

1919
import org.springframework.http.HttpMethod;
20+
import org.springframework.security.config.Customizer;
2021
import org.springframework.security.config.annotation.web.HttpSecurityBuilder;
2122
import org.springframework.security.config.annotation.web.RequestMatcherFactory;
2223
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
@@ -74,7 +75,7 @@ public final class FormLoginConfigurer<H extends HttpSecurityBuilder<H>> extends
7475

7576
/**
7677
* Creates a new instance
77-
* @see HttpSecurity#formLogin()
78+
* @see HttpSecurity#formLogin(Customizer)
7879
*/
7980
public FormLoginConfigurer() {
8081
super(new UsernamePasswordAuthenticationFilter(), null);

config/src/main/java/org/springframework/security/config/annotation/web/configurers/HeadersConfigurer.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@
4848
import org.springframework.security.web.util.matcher.RequestMatcher;
4949
import org.springframework.util.Assert;
5050

51+
import static org.springframework.security.config.Customizer.withDefaults;
52+
5153
/**
5254
* <p>
5355
* Adds the Security HTTP headers to the response. Security HTTP headers is activated by
@@ -111,7 +113,7 @@ public class HeadersConfigurer<H extends HttpSecurityBuilder<H>>
111113
/**
112114
* Creates a new instance
113115
*
114-
* @see HttpSecurity#headers()
116+
* @see HttpSecurity#headers(Customizer)
115117
*/
116118
public HeadersConfigurer() {
117119
}

0 commit comments

Comments
 (0)