/*
|
* <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;
|
}
|
}
|
}
|