【发布时间】:2020-12-03 16:12:00
【问题描述】:
我正在开发一个使用 Spring Security 5.3.3、Spring Security OAuth 2.5.0 的 Spring Web 应用程序(不是 Spring Boot),并进行如下配置:
http.authorizeRequests().
antMatchers(permitUrls).
permitAll().
anyRequest().
authenticated().
and().
oauth2ResourceServer().
jwt();
我们的客户偶尔会报告我们在应用程序日志中找不到的 401 响应,因此我们假设它来自 Spring Security 本身。我们想记录身份验证和授权失败,但我不知道当前首选的方法是什么。
快速搜索发现 4 条路径:
- 自定义AuthenticationFailureHandler(好像这个只在FormLoginConfigurer中可用,不是我们的情况)
- custom AuthenticationEntryPoint(这个可以在 JWT 中使用,但是我要扩展的 OAuth2AuthenticationEntryPoint 是deprecated with an unhelpful message)。我可以尝试改用 HttpStatusEntryPoint,但我想避免更改应用的当前行为,只想添加日志记录。
- 自定义过滤器(可能不是最干净的路径)
- AuditApplicationEvents — 看起来很漂亮,但似乎只适用于 Spring Boot。
谁能给我一些指导?
【问题讨论】:
标签: spring-security spring-security-oauth2