whyclxw
2024-07-01 db23586fd744582cd8ee237c34ff29d9277009ee
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
package com.whyc.util;
 
 
import com.whyc.pojo.UserInf;
import org.apache.shiro.SecurityUtils;
 
/**
 * 从Shiro中直接获取用户信息
 */
public class UserUtil {
 
    public static UserInf getUser(){
 
        UserInf principal = (UserInf) SecurityUtils.getSubject().getPrincipal();
        if(principal == null){
            UserInf user = new UserInf();
            user.setUname("unlogged user");
            user.setUid(0);
            user.setUdownloadRole(0);
            return user;
        }else {
            return principal;
        }
    }
}