Merge remote-tracking branch 'origin/在线访问lhj' into 在线访问lhj

在线访问lhj
李宏杰 8 months ago
commit e1eb747b6e

@ -1,43 +1,68 @@
package com.tamguo.utils;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.session.Session;
import org.apache.shiro.subject.Subject;
import com.tamguo.modules.member.model.MemberEntity;
import org.apache.shiro.SecurityUtils; // 导入 Shiro 的安全工具类
import org.apache.shiro.session.Session; // 导入 Shiro 的会话类
import org.apache.shiro.subject.Subject; // 导入 Shiro 的主体类
import com.tamguo.modules.member.model.MemberEntity; // 导入会员实体类
/**
* ShiroUtils Shiro
*/
public class ShiroUtils {
/**
*
*/
public static Session getSession() {
return SecurityUtils.getSubject().getSession();
return SecurityUtils.getSubject().getSession(); // 获取 Shiro 主体的会话
}
/**
*
*/
public static Subject getSubject() {
return SecurityUtils.getSubject();
return SecurityUtils.getSubject(); // 获取 Shiro 主体
}
/**
*
*/
public static MemberEntity getMember() {
return (MemberEntity)SecurityUtils.getSubject().getPrincipal();
return (MemberEntity)SecurityUtils.getSubject().getPrincipal(); // 获取 Shiro 主体的主要对象(会员实体)
}
/**
* ID
*/
public static String getMemberId() {
return getMember().getId();
return getMember().getId(); // 获取会员实体的 ID
}
/**
*
*/
public static void setSessionAttribute(Object key, Object value) {
getSession().setAttribute(key, value);
getSession().setAttribute(key, value); // 在会话中设置属性键值对
}
/**
*
*/
public static Object getSessionAttribute(Object key) {
return getSession().getAttribute(key);
return getSession().getAttribute(key); // 获取会话中指定键的属性值
}
/**
*
*/
public static boolean isLogin() {
return SecurityUtils.getSubject().getPrincipal() != null;
return SecurityUtils.getSubject().getPrincipal()!= null; // 判断 Shiro 主体的主要对象是否不为空
}
/**
*
*/
public static void logout() {
SecurityUtils.getSubject().logout();
SecurityUtils.getSubject().logout(); // 执行 Shiro 主体的注销操作
}
}
}
Loading…
Cancel
Save