mirror of
https://github.com/spring-projects/spring-security.git
synced 2025-06-22 12:02:14 +00:00
Use ServerHttpSecurity Lambda DSL in Config
Issue gh-13067
This commit is contained in:
parent
9fcfacf283
commit
461f00ed38
@ -43,6 +43,8 @@ import org.springframework.security.web.reactive.result.method.annotation.Curren
|
|||||||
import org.springframework.web.reactive.config.WebFluxConfigurer;
|
import org.springframework.web.reactive.config.WebFluxConfigurer;
|
||||||
import org.springframework.web.reactive.result.method.annotation.ArgumentResolverConfigurer;
|
import org.springframework.web.reactive.result.method.annotation.ArgumentResolverConfigurer;
|
||||||
|
|
||||||
|
import static org.springframework.security.config.Customizer.withDefaults;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Rob Winch
|
* @author Rob Winch
|
||||||
* @author Dan Zheng
|
* @author Dan Zheng
|
||||||
@ -156,8 +158,8 @@ class ServerHttpSecurityConfiguration {
|
|||||||
ContextAwareServerHttpSecurity http = new ContextAwareServerHttpSecurity();
|
ContextAwareServerHttpSecurity http = new ContextAwareServerHttpSecurity();
|
||||||
// @formatter:off
|
// @formatter:off
|
||||||
return http.authenticationManager(authenticationManager())
|
return http.authenticationManager(authenticationManager())
|
||||||
.headers().and()
|
.headers(withDefaults())
|
||||||
.logout().and();
|
.logout(withDefaults());
|
||||||
// @formatter:on
|
// @formatter:on
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -40,6 +40,8 @@ import org.springframework.util.ClassUtils;
|
|||||||
import org.springframework.util.ObjectUtils;
|
import org.springframework.util.ObjectUtils;
|
||||||
import org.springframework.web.reactive.result.view.AbstractView;
|
import org.springframework.web.reactive.result.view.AbstractView;
|
||||||
|
|
||||||
|
import static org.springframework.security.config.Customizer.withDefaults;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Rob Winch
|
* @author Rob Winch
|
||||||
* @since 5.0
|
* @since 5.0
|
||||||
@ -121,13 +123,13 @@ class WebFluxSecurityConfiguration {
|
|||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
private SecurityWebFilterChain springSecurityFilterChain(ServerHttpSecurity http) {
|
private SecurityWebFilterChain springSecurityFilterChain(ServerHttpSecurity http) {
|
||||||
http.authorizeExchange().anyExchange().authenticated();
|
http.authorizeExchange((exchange) -> exchange.anyExchange().authenticated());
|
||||||
if (isOAuth2Present && OAuth2ClasspathGuard.shouldConfigure(this.context)) {
|
if (isOAuth2Present && OAuth2ClasspathGuard.shouldConfigure(this.context)) {
|
||||||
OAuth2ClasspathGuard.configure(this.context, http);
|
OAuth2ClasspathGuard.configure(this.context, http);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
http.httpBasic();
|
http.httpBasic(withDefaults());
|
||||||
http.formLogin();
|
http.formLogin(withDefaults());
|
||||||
}
|
}
|
||||||
SecurityWebFilterChain result = http.build();
|
SecurityWebFilterChain result = http.build();
|
||||||
return result;
|
return result;
|
||||||
@ -136,8 +138,8 @@ class WebFluxSecurityConfiguration {
|
|||||||
private static class OAuth2ClasspathGuard {
|
private static class OAuth2ClasspathGuard {
|
||||||
|
|
||||||
static void configure(ApplicationContext context, ServerHttpSecurity http) {
|
static void configure(ApplicationContext context, ServerHttpSecurity http) {
|
||||||
http.oauth2Login();
|
http.oauth2Login(withDefaults());
|
||||||
http.oauth2Client();
|
http.oauth2Client(withDefaults());
|
||||||
}
|
}
|
||||||
|
|
||||||
static boolean shouldConfigure(ApplicationContext context) {
|
static boolean shouldConfigure(ApplicationContext context) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user