12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455 |
- package com.kmall.admin.utils;
- import com.kmall.admin.fromcomm.entity.SysUserEntity;
- import org.apache.shiro.SecurityUtils;
- import org.apache.shiro.session.Session;
- import org.apache.shiro.subject.Subject;
- /**
- * Shiro工具类
- *
- * @author Scott
- * @email
- * @date 2016年11月12日 上午9:49:19
- */
- public class ShiroUtils {
- public static Session getSession() {
- return SecurityUtils.getSubject().getSession();
- }
- public static Subject getSubject() {
- return SecurityUtils.getSubject();
- }
- public static SysUserEntity getUserEntity() {
- return (SysUserEntity) 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();
- }
- public static String getKaptcha(String key) {
- String kaptcha = getSessionAttribute(key).toString();
- getSession().removeAttribute(key);
- return kaptcha;
- }
- }
|