在程序中获取当前用户信息的方法

来源:互联网 发布:视频添加背景音乐软件 编辑:程序博客网 时间:2024/06/05 03:04

第一种:

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

第二种:

protected AbstractUser getUserInfo() {        Authentication authentication = SecurityContextHolder.getContext().getAuthentication();        if (authentication == null) {            return null;        }        return (AbstractUser) authentication.getPrincipal();    }


原创粉丝点击