在我的项目中,我使用 request.getUserPrincipal()
来检查用户是否登录,但我不知道在哪里将实例设置为登录用户?
我还注意到 request.getUserPrincipal().getName()
返回用户登录 ID。
最佳答案
最后我找到了我们将自己的数据库用户详细信息设置为 spring security Principal 的地方,我们有一个实现 spring security AuthenticationProvider
接口(interface)的类,并且在 public Authentication authenticate( Authentication authentication)
方法,我们将USER_TB
中的值设置为Spring Security的UserDetails
对象。我还在研究,spring security 是一个很大的学习部分
关于java - 何时何地设置 UserPrincipal 的 Java 安全性?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25885747/