通用框架平台,每个分支对应子通用框架平台,禁止Merge不同分支!! 分支版本区别见项目内readme.md
whycxzp
2021-01-15 86771052e3fc386dfbe393ccae9f5b9f6af75391
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
/*
 * <b>文件名</b>:ShiroUtil.java
 *
 * 文件描述:
 *
 *
 * 2017-10-11  下午2:28:25
 */
 
package com.whyc.util;
 
import com.mysql.cj.core.util.StringUtils;
import com.whyc.constant.SuperConstant;
import com.whyc.pojo.User;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.session.Session;
import org.apache.shiro.subject.Subject;
import org.apache.shiro.util.ThreadContext;
 
 
/**
 * @Description shiro工具类
 */
public class ShiroUtil {
    
    /**
     * @Description 获得shiro的session
     * @param
     * @return
     */
    public static Session getShiroSession() {
        return SecurityUtils.getSubject().getSession();
    }
    
    /**
     * @Description 获得shiro的sessionId
     * @param
     * @return
     */
    public static String getShiroSessionId() {
        return getShiroSession().getId().toString();
    }
    
    /**
     * @Description 是否登陆
     * @param
     * @return
     */
    public static Boolean isAuthenticated(){
        Subject subject = SecurityUtils.getSubject();
        return subject.isAuthenticated();
    }
 
    public static User getUser() {
        if (!isNullOrEmpty(ThreadContext.getSubject()) && !isNullOrEmpty(SecurityUtils.getSubject().getPrincipal())) {
            return (User) SecurityUtils.getSubject().getPrincipal();
        }else {
            return new User(0,"none");
        }
    }
 
    public static boolean isNullOrEmpty(Object obj) {
        if (obj == null || "".equals(obj)) {
            return true;
        } else {
            return false;
        }
    }
}