简体   繁体   English

从 Spring 安全中检索未记录的用户详细信息

[英]Retrieve not-logged User Details from Spring Security

I know how to retrieve user details if he is logged on, using SecurityContextHolder.如果用户登录,我知道如何使用 SecurityContextHolder 检索用户详细信息。

// Some code

UserDetails userDetails =
 (UserDetails)SecurityContextHolder.getContext().getAuthentication().getPrincipal();

So, my question is:所以,我的问题是:

Is it possible to retrieve information about not currently logged user, for example by User Id only?是否可以检索有关当前未登录用户的信息,例如仅通过用户 ID?

And how can I update the information about users if they are currently offline?如果用户当前处于离线状态,我如何更新有关用户的信息?

The one populating your SecurityContext is usually a UserDetailsService , which you have to implement yourself or you take one of the existing ones.填充您的SecurityContext的通常是一个UserDetailsService ,您必须自己实现它,或者您使用现有的一个。

I'm not sure I fully understand your question, but in theory you can simply use your UserDetailsService (or the services it itself uses to load a user), to get all the details you want.我不确定我是否完全理解您的问题,但理论上您可以简单地使用您的 UserDetailsService (或它本身用于加载用户的服务)来获取您想要的所有详细信息。 So, if you have a JPAUserDetailsService, this will likely call a repository and there's nothing stopping you from using that repository yourself.因此,如果您有一个 JPAUserDetailsService,这可能会调用一个存储库,并且没有什么可以阻止您自己使用该存储库。

What exactly is it that you are trying to do?你到底想做什么?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM