我发现,在版本 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/