【发布时间】:2019-01-01 22:11:48
【问题描述】:
我已经在 Spring Boot 中实现了一个带有 Spring Security 的应用程序。我需要在成功登录后在jsp页面中显示用户的名字,姓氏和图像路径(用于标题,即使我们导航到另一个URL也意味着全局可用)强>。我正在使用remember-me 使用PersistentLogin。所以我不能使用会话来存储详细信息。因为如果我关闭浏览器,会话将被销毁。
我已经实现了CustomUserDetailsService,它返回org.springframework.security.core.userdetails.User
@Service("customUserDetailsService")
public class CustomUserDetailsService implements UserDetailsService{
//codes
return new org.springframework.security.core.userdetails.User(
username,
password,
enabled,
accountNonExpired,
credentialsNonExpired,
accountNonLocked,
authorities);
}
我知道有两个限制
- 如果我不使用记住我,我可以轻松地在会话中存储。
- 如果我在
CustomUserDetailsService ...中返回User模型类,我可以很容易地在jsp中获取用户详细信息 页面使用<security:authentication property="principal.firstName">jsp中的标签。但我需要返回org.springframework.security.core.userdetails.User
不幸的是,我需要这两个限制。我的User 模型类有firstName, lastName, imagePath,.. etc.
如何在 jsp 页面中显示用户详细信息?有什么可用的方法吗?提前致谢。
【问题讨论】:
标签: spring spring-mvc jsp spring-boot spring-security