xiangpei
2025-04-18 ccadf9480d4e6a9dcc227a2a0b1f9ae0612e36fd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package com.monkeylessey.framework.utils;
 
import com.monkeylessey.sys.domain.vo.SysUserVO;
import org.springframework.security.core.context.SecurityContextHolder;
 
 
/**
 * 安全服务工具类
 *
 * @author xp
 */
public class SecurityUtil {
    /**
     * 获取当前请求的用户的信息
     *
     * @return
     */
    public static SysUserVO getCurrentUser() {
        SysUserVO loginUser = (SysUserVO) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
        loginUser.setPassword("");
        return loginUser;
    }
 
    /**
     * 获取当前请求的用户名
     *
     * @return
     */
    public static String getCurrentUserName() {
        SysUserVO loginUser = (SysUserVO) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
        return loginUser.getUserName();
    }
 
    /**
     * 获取当前请求用户的id
     *
     * @return
     */
    public static String getCurrentUserId() {
        return getCurrentUser().getId();
    }
}