gpt4 book ai didi

java - RedisTokenstore : Cannot cast . ..用户到...用户

转载 作者:行者123 更新时间:2023-11-30 06:13:03 25 4
gpt4 key购买 nike

我将 Spring OAuth2 应用程序切换到了 RedisTokenstore。现在访问主体,基本上是通过...

SecurityContextHolder.getContext().authentication.userAuthentication.principal 作为用户

...我得到了...

java.lang.ClassCastException: ...User 无法转换为 ...User

(三个点实际上是完整的类路径)。

我对 jave/kotlin 还很陌生,对正在发生的事情只有一个模糊的了解。

一些提示:

  • 我非常确定 redis token 存储不会同时存储,因此内容应该是相同的(相关请求中不会调用 storeAccessToken)
  • 我看到 readAccessToken 被调用了两次(我认为这是一次不必要的往返,但这是另一回事)
  • 混合发生在安全链方法的 doFilter 方法内,即第二次遍历时。

更新:串行版本hickhup是因为我在添加串行后没有刷新redis缓存。所以这只是无法转换错误。

我怎样才能开始调试这个?

最佳答案

spring-devtools 中实际上存在一个问题:

https://docs.spring.io/spring-boot/docs/current/reference/htmlsingle/#using-boot-devtools-known-restart-limitations

20.2.7 Known Limitations

Restart functionality does not work well with objects that are deserialized by using a standard ObjectInputStream. If you need to deserialize data, you may need to use Spring’s ConfigurableObjectInputStream in combination with Thread.currentThread().getContextClassLoader().

Unfortunately, several third-party libraries deserialize without considering the context classloader. If you find such a problem, you need to request a fix with the original authors.

一种选择是升级到 spring-boot 2.+

另一种方法是假设您不需要它,则将其全部删除。下面是一个示例,如果您使用 Maven,它将删除 1.3.0 及更高版本中的任何版本:

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<version>[1.3.0,)</version>
<scope>provided</scope>
</dependency>

完成验证后,请务必先刷新 Redis。

关于java - RedisTokenstore : Cannot cast . ..用户到...用户,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49829595/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com