Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Spring 按用户名检索用户会话详细信息_Spring_Spring Security - Fatal编程技术网

Spring 按用户名检索用户会话详细信息

Spring 按用户名检索用户会话详细信息,spring,spring-security,Spring,Spring Security,有没有一种方法可以通过用户名或其他对象来识别用户会话(例如,权限)的详细信息 我知道为当前用户获取这些详细信息很容易(例如,收集权限=authentication.getAuthorities()),但是有什么方法可以像这样做吗 Collection<?> authorities = authentication.getAuthoritiesByUsername('skn'); Collection authorities=authentication.getAuthorities

有没有一种方法可以通过用户名或其他对象来识别用户会话(例如,权限)的详细信息

我知道为当前用户获取这些详细信息很容易(例如,
收集权限=authentication.getAuthorities()
),但是有什么方法可以像这样做吗

Collection<?> authorities = authentication.getAuthoritiesByUsername('skn');
Collection authorities=authentication.getAuthoritiesByUsername('skn');

Collection authorities=authentication.getAuthorities(principalObject);

用例是我需要通过RESTAPI调用获取用户的会话细节。

Spring通过接口为用户检索权限

通常,您将向身份验证管理器提供UserDetailsService实现bean,该管理器将调用接口以检索用户详细信息


根据您配置服务的方式,应该可以将UserDetailsService注入任何其他bean。此时,您只需调用loadUserByUsername()来检索用户的UserDetails对象,然后对其调用getAuhtorities()。

但这不是一个安全漏洞吗?我的意思是,身份验证对象将特定于刚刚获得身份验证的用户。除非您有来自REST调用的安全令牌,并且您有办法在spring安全性和REST调用之间共享身份验证,否则我认为这听起来很可疑。REST调用将进行spring安全检查,并将进行身份验证等。感谢您为我指出答案。我能在你建议的基础上再接再厉。
Collection<?> authorities = authentication.getAuthorities(principalObject);