【发布时间】:2023-03-13 12:33:01
【问题描述】:
在 Spring Boot 应用程序中使用 Shiro spring boot starter 1.4.0,但不知道如何将 shiro principalCollection 数据提取到我的 thymeleaf 模板中以用于其他表达式等...
我在 shiro 中存储了一些轻量级用户数据,并希望使用当前用户的名字和上次登录时间显示自定义消息
例如:
<p th:text="#{welcome.lastlogin.message(${???.firstName},${???.lastLoginTime})}">..Hello, user, how are you today?..</p>
我确实转储了会话属性以查看 shiro 将主体存储为什么,我在会话中看到了这一点:
org.apache.shiro.subject.support.DefaultSubjectContext_PRINCIPALS_SESSION_KEY = john.doe@somewhere.com,{userID=1,firstName=John, lastName=Doe, loginAttempts=0, lastLoginTime=Mon Jan 22 09:30:47美国东部标准时间 2018}
我的代码使用 HashMap 并将其添加到主体...
这可能吗?
编辑:我想另一种选择是根本不为此目的使用 shiro principalCollection,而是将我自己的对象放在会话中并从 thymeleaf 中使用它。
【问题讨论】: