zoukankan      html  css  js  c++  java
  • 常用公共工具类——Shiro工具类

    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 String getKaptcha(String key) {
            Object kaptcha = getSessionAttribute(key);
            if(kaptcha == null){
                throw new RRException("验证码已失效");
            }
            getSession().removeAttribute(key);
            return kaptcha.toString();
        }
    
    }
    一个小小后端的爬行痕迹
  • 相关阅读:
    Reborn
    个人总结
    第十六周个人进度条
    梦断代码阅读笔记03
    第十五周个人进度条
    第十四周个人进度条
    第十三周个人进度条
    冲刺9
    冲刺8
    事后诸葛亮会议
  • 原文地址:https://www.cnblogs.com/heikedeblack/p/14981938.html
Copyright © 2011-2022 走看看