在spring boot 2 m6上创建一个简单的弹簧安全配置
@Configuration
@EnableWebFluxSecurity
@EnableReactiveMethodSecurity
public class SecurityConfig {
@Bean
public ReactiveUserDetailsService userDetailsRepository() {
UserDetails user = User.withDefaultPasswordEncoder()
.username("test")
.password("test")
.roles("USER")
.build();
return new MapReactiveUserDetailsService(user);
}
@Bean
SecurityWebFilterChain springWebFilterChain(ServerHttpSecurity http) throws Exception {
return http.csrf()
.disable()
.authorizeExchange()
.anyExchange().authenticated()
.and()
.httpBasic().and()
.build();
}
但是当我在authenfication之后尝试在处理程序请求中获取身份验证对象时,我总是得到null
ReactiveSecurityContextHolder.getContext().block().getAuthentication()
当我尝试登录时
public Mono<ServerResponse> checkStatus(ServerRequest request) {
System.out.println(request.principal().block());
我也是空的
问题出在哪里?