使用SessionRegistry对象,我检索了用户所有活动会话的SessionInformation。
现在,我想要检查这些会话的权限。为此,我需要身份验证对象。
春天的安全性是否有办法解决这个问题
我的代码:
List<SessionInformation> sessionInformationList = sessionRegistry.getAllSessions( user, false);
SessionInformation sessionInformation = sessionRegistry.getSessionInformation(lastSessionId);
//Now I need Authentication Object, any idea
我这样做是为了检索不同会话ID的用户角色
答案 0 :(得分:1)
在我们Stormpath Spring Security integration中,我们在身份验证工作流程中编码了您需要的内容。对用户进行适当身份验证后,将生成Granted Authorites
并将其应用于正在检索的Authentication
对象。
我们将该信息封装在名为StormpathUserDetails
的对象中。您可以查看this piece of code。
然后,您的代码可以通过以下方式检索该信息:Collection<? extends GrantedAuthority> grantedAuthorities = ((StormpathUserDetails)SecurityContextHolder.getContext().getAuthentication().getPrincipal()).getAuthorities();
希望这有助于您做什么。