1、问题概述?
SpringSecurity默认通过loadUserByUsername登录成功后,我们期望在项目中使用登录后的用户信息。
2、在Controller中获取用户的登录信息。
主要通过Authentication 对象进行查询
@RequestMapping("/checkRemoteDevice")
@ResponseBody
public void checkRemoteDevice(Authentication authentication) throws UnknownHostException {
System.out.println("用户名===>"+authentication.getName());
System.out.println("主要信息===>"+authentication.getPrincipal());
System.out.println("密码===>"+authentication.getCredentials());
System.out.println("详情===>"+authentication.getDetails());
System.out.println("权限===>"+authentication.getAuthorities());
}
返回值信息如下:

3、在页面中如何SpringSecurity登录消息
页面中可以使用thymeleaf+security标签直接获取
注意点:thymeleaf-extras-springsecurity5,我项目中使用的是springSe

最低0.47元/天 解锁文章
1861

被折叠的 条评论
为什么被折叠?



