在没有 ThreadLocal 的情况下实现 SecurityService 以与 Kotlin 协程一起使用

问题描述

this有些相关:

我们正在尝试注入一个 SecurityService bean,以便我可以在控制器之外访问身份验证对象。不幸的是,与之前的 RequestScope 实现一样,getAuthentication 的 DefaultSecurityService 实现依赖于使用 ThreadLocal 的 ServerRequestContext.currentRequest():

@Override
public Optional<Authentication> getAuthentication() {
    return ServerRequestContext.currentRequest()
            .flatMap(request -> request.getUserPrincipal(Authentication.class));
}

而且由于我们也在使用 Kotlin 协程,我们希望找到一种无需 ThreadLocal 即可实现 getAuthentication 的方法。关于我们如何去做的任何建议?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)