【发布时间】:2021-09-15 16:18:20
【问题描述】:
我的要求完全不同,实际上我已经在 Spring Cloud API Gateway(基于 WebFlux)中添加了安全性,现在基本上我想根据端点 /testAPI/ 上存在的一些标头值跳过 OAuth 资源服务器完整流程** 否则 OAuth 资源服务器流程将在相同的端点 /testAPI/** 上启动
安全配置
@Autowired
private ReactiveAuthenticationManager manager;
@Bean
SecurityWebFilterChain springSecurityFilterChain(ServerHttpSecurity http) {
return http
.authorizeExchange()
.pathMatchers("/testAPI/**").authenticated()
.anyExchange().permitAll()
.and()
.securityContextRepository(NoOpServerSecurityContextRepository.getInstance())
.httpBasic().disable()
.formLogin().disable()
.csrf().disable()
.logout().disable()
.oauth2ResourceServer()
.jwt()
.authenticationManager(manager)
.and()
.and()
.addFilterBefore(new SecurityWebFilter(), SecurityWebFiltersOrder.AUTHENTICATION)
.build();
在 SecurityWebFilter 中,我尝试了使用自定义身份验证的 ReactiveSecurityContextHolder.withAuthentication(..),方法是将其设置为 true 并使用
Mono<Authentication> authentication = ReactiveSecurityContextHolder.getContext().map(SecurityContext::getAuthentication)
.doOnSuccess(auth -> {
auth.setAuthenticated(true);
});
没有什么对我有用,我可以使用 OAuth 服务器进行验证,但我想在相同的端点上有条件地跳过它。
请帮忙,我是 WebFlux 的新手,正在探索 Spring 安全性。
【问题讨论】:
标签: spring-boot spring-security oauth-2.0 spring-webflux