我是把 spring security 大部分的 filter 都移除了( sessionManagement 设置为 STATELESS )只保留部分,加了一些自己需要的(比如记录执行时间的 filter ),少了很多 filter 真爽,然后自己写了一个 HandlerInterceptor 来鉴权。
这样就能保证鉴权过程中抛出的错误能被 RestControllerAdvice 处理到,不用在 spring security 里面单独处理异常。
又能享受到 spring security 提供的 @
PreAuthorize 等注解的便利(主要是注解这个)。🤭
不过 api 接口变动确实让我改过好几次,目前是自己实现了一个 AuthenticationManager ,代替它原本的,不知道今后还会不会影响到我。