Skip to content

Commit 461f00e

Browse files
committed
Use ServerHttpSecurity Lambda DSL in Config
Issue gh-13067
1 parent 9fcfacf commit 461f00e

File tree

2 files changed

+11
-7
lines changed

2 files changed

+11
-7
lines changed

config/src/main/java/org/springframework/security/config/annotation/web/reactive/ServerHttpSecurityConfiguration.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@
4343
import org.springframework.web.reactive.config.WebFluxConfigurer;
4444
import org.springframework.web.reactive.result.method.annotation.ArgumentResolverConfigurer;
4545

46+
import static org.springframework.security.config.Customizer.withDefaults;
47+
4648
/**
4749
* @author Rob Winch
4850
* @author Dan Zheng
@@ -156,8 +158,8 @@ ServerHttpSecurity httpSecurity() {
156158
ContextAwareServerHttpSecurity http = new ContextAwareServerHttpSecurity();
157159
// @formatter:off
158160
return http.authenticationManager(authenticationManager())
159-
.headers().and()
160-
.logout().and();
161+
.headers(withDefaults())
162+
.logout(withDefaults());
161163
// @formatter:on
162164
}
163165

config/src/main/java/org/springframework/security/config/annotation/web/reactive/WebFluxSecurityConfiguration.java

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@
4040
import org.springframework.util.ObjectUtils;
4141
import org.springframework.web.reactive.result.view.AbstractView;
4242

43+
import static org.springframework.security.config.Customizer.withDefaults;
44+
4345
/**
4446
* @author Rob Winch
4547
* @since 5.0
@@ -121,13 +123,13 @@ private SecurityWebFilterChain springSecurityFilterChain() {
121123
* @return
122124
*/
123125
private SecurityWebFilterChain springSecurityFilterChain(ServerHttpSecurity http) {
124-
http.authorizeExchange().anyExchange().authenticated();
126+
http.authorizeExchange((exchange) -> exchange.anyExchange().authenticated());
125127
if (isOAuth2Present && OAuth2ClasspathGuard.shouldConfigure(this.context)) {
126128
OAuth2ClasspathGuard.configure(this.context, http);
127129
}
128130
else {
129-
http.httpBasic();
130-
http.formLogin();
131+
http.httpBasic(withDefaults());
132+
http.formLogin(withDefaults());
131133
}
132134
SecurityWebFilterChain result = http.build();
133135
return result;
@@ -136,8 +138,8 @@ private SecurityWebFilterChain springSecurityFilterChain(ServerHttpSecurity http
136138
private static class OAuth2ClasspathGuard {
137139

138140
static void configure(ApplicationContext context, ServerHttpSecurity http) {
139-
http.oauth2Login();
140-
http.oauth2Client();
141+
http.oauth2Login(withDefaults());
142+
http.oauth2Client(withDefaults());
141143
}
142144

143145
static boolean shouldConfigure(ApplicationContext context) {

0 commit comments

Comments
 (0)