2
13693261870
2022-09-16 653761a31dfeb50dd3d007e892d69c90bf0cdafc
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
43
44
45
46
47
48
package com.landtool.lanbase.common.utils;
 
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.session.Session;
import org.apache.shiro.subject.Subject;
 
import com.landtool.lanbase.modules.org.entity.OrgUser;
 
/**
 * @author lanbase
 * @Description: TODO(Shiro工具类)
 * @date 2017-6-23 15:07
 */
public class ShiroUtils {
 
    public static Session getSession() {
        return SecurityUtils.getSubject().getSession();
    }
 
    public static Subject getSubject() {
        return SecurityUtils.getSubject();
    }
 
    public static OrgUser getUserEntity() {
        return (OrgUser)SecurityUtils.getSubject().getPrincipal();
    }
 
    public static Long getUserId() {
        return getUserEntity().getUserid();
    }
    
    public static void setSessionAttribute(Object key, Object value) {
        getSession().setAttribute(key, value);
    }
 
    public static Object getSessionAttribute(Object key) {
        return getSession().getAttribute(key);
    }
 
    public static boolean isLogin() {
        return SecurityUtils.getSubject().getPrincipal() != null;
    }
 
    public static void logout() {
        SecurityUtils.getSubject().logout();
    }
 
}