spring-security - 是否可以使用自定义的 ServerAuthenticationEntryPoint 添加响应正文?

标签 spring-security spring-security-oauth2 spring-webflux

我发现,在版本 5.2.0.M1 中,在 react 堆栈 (Webflux) 上使用 Spring Security 的 OAuth2 资源服务器时,无法自定义 ServerAuthenticationEntryPoint。

(另请参阅 https://github.com/spring-projects/spring-security/issues/6052 )

但是,当我现在尝试编写自己的 ServerAuthenticationEntryPoint 时,我问自己如何向 http 响应添加正文? begin(...) 方法返回一个 Mono,我还没有找到在某处指定主体的方法。

有人可以给我提示如何执行此操作(如果可能的话)吗?

最佳答案

同时我找到了解决这个问题的方法。当仅将 lambda 添加到 WebSecurityConfiguration 类中的 ServerHttpSecurity 配置时,如下所示

http
  . ...
  .oauth2ResourceServer()
  .authenticationEntryPoint((exchange, exception) -> Mono.error(exception));

我可以在我的自定义实现中处理错误 AbstractErrorWebExceptionHandler ,无论如何我都会处理所有非 spring 安全相关的异常。这有效。我必须从 BearerTokenServerAuthenticationEntryPoint 复制一些逻辑,才能在响应中获得正确的 WWW-Authenticate header ,但现在使用自定义主体可以正常工作,以防出现来自 spring security 的任何异常。 p>

关于spring-security - 是否可以使用自定义的 ServerAuthenticationEntryPoint 添加响应正文?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56892926/

相关文章:

java - 如何在 Spring Boot 中使用缓存来提高 OAuth2 ResourceServer 的性能

java - Oauth2 在 Spring Boot 中不起作用

spring-security-oauth2 - Spring Oauth2 - 每个客户端 ID 有多个 token

java - Spring http/web 转发不适用于 spring-reactive

json - Spring webflux Netty : How to expose proto as json endpoints without duplication of code?

docker - docker中的Grails应用程序,安装spring-security插件?

spring-security - 使用 CSRF 进行放心和基本身份验证的集成测试

java - Autowired 在自定义注销处理程序和自定义用户详细信息中给出 null

json - 将 OAuth2 错误返回为 JSON 而不是 XML

java - Spring Reactive Web 更新方法创建一条新记录而不是更新现有记录