Browse Source

修正测试

shilin 3 years ago
parent
commit
c790b2e387

File diff suppressed because it is too large
+ 1091 - 0
web/monitor-web-hb/doc/springbootv2.sql


+ 0 - 0
web/monitor-web-hb/lib/ueditor-1.1.2.jar


+ 104 - 0
web/monitor-web-hb/src/main/java/com/gyee/frame/common/domain/AjaxResult.java

@@ -0,0 +1,104 @@
+package com.gyee.frame.common.domain;
+
+import java.util.HashMap;
+
+/**
+ * @ClassName: AjaxResult
+ * @Description: ajax操作消息提醒
+ * @author gyee
+ * @date 2018年8月18日
+ *
+ */
+public class AjaxResult extends HashMap<String, Object>
+{
+    private static final long serialVersionUID = 1L;
+
+    /**
+     * 初始化一个新创建的 Message 对象
+     */
+    public AjaxResult()
+    {
+    }
+
+    /**
+     * 返回错误消息
+     *
+     * @return 错误消息
+     */
+    public static AjaxResult error()
+    {
+        return error(1, "操作失败");
+    }
+
+    /**
+     * 返回错误消息
+     *
+     * @param msg 内容
+     * @return 错误消息
+     */
+    public static AjaxResult error(String msg)
+    {
+        return error(500, msg);
+    }
+
+    /**
+     * 返回错误消息
+     *
+     * @param code 错误码
+     * @param msg 内容
+     * @return 错误消息
+     */
+    public static AjaxResult error(int code, String msg)
+    {
+        AjaxResult json = new AjaxResult();
+        json.put("code", code);
+        json.put("msg", msg);
+        return json;
+    }
+
+    /**
+     * 返回成功消息
+     *
+     * @param msg 内容
+     * @return 成功消息
+     */
+    public static AjaxResult success(String msg)
+    {
+        AjaxResult json = new AjaxResult();
+        json.put("msg", msg);
+        json.put("code", 200);
+        return json;
+    }
+
+    /**
+     * 返回成功消息
+     *
+     * @return 成功消息
+     */
+    public static AjaxResult success()
+    {
+        return AjaxResult.success("操作成功");
+    }
+
+    public static AjaxResult successData(int code, Object value){
+        AjaxResult json = new AjaxResult();
+        json.put("code", code);
+        json.put("data", value);
+        return json;
+    }
+
+
+    /**
+     * 返回成功消息
+     *
+     * @param key 键值
+     * @param value 内容
+     * @return 成功消息
+     */
+    @Override
+    public AjaxResult put(String key, Object value)
+    {
+        super.put(key, value);
+        return this;
+    }
+}

+ 165 - 0
web/monitor-web-hb/src/main/java/com/gyee/frame/shiro/util/ShiroUtils.java

@@ -0,0 +1,165 @@
+package com.gyee.frame.shiro.util;
+
+import com.gyee.frame.model.auto.TsysUser;
+import com.gyee.frame.shiro.config.ShiroConfig;
+import com.gyee.frame.shiro.service.MyShiroRealm;
+import com.gyee.frame.util.BeanUtils;
+import com.gyee.frame.util.StringUtils;
+import org.apache.shiro.SecurityUtils;
+import org.apache.shiro.mgt.RealmSecurityManager;
+import org.apache.shiro.session.Session;
+import org.apache.shiro.subject.PrincipalCollection;
+import org.apache.shiro.subject.SimplePrincipalCollection;
+import org.apache.shiro.subject.Subject;
+
+import java.util.concurrent.ConcurrentHashMap;
+
+
+/**
+ * shiro 工具类
+ *
+ * @author gyee
+ */
+public class ShiroUtils {
+
+    private ShiroUtils(){}
+
+    /**
+     * 获取shiro subject
+     * @return
+     * @author gyee
+     * @Date 2019年11月21日 上午10:00:55
+     */
+    public static Subject getSubjct()
+    {
+        return SecurityUtils.getSubject();
+    }
+
+    /**
+     * 获取登录session
+     * @return
+     * @author gyee
+     * @Date 2019年11月21日 上午10:00:41
+     */
+    public static Session getSession()
+    {
+        return SecurityUtils.getSubject().getSession();
+    }
+
+    /**
+     * 退出登录
+     * @author gyee
+     * @Date 2019年11月21日 上午10:00:24
+     */
+    public static void logout()
+    {
+        getSubjct().logout();
+    }
+
+    /**
+     * 获取登录用户model
+     * @return
+     * @author gyee
+     * @Date 2019年11月21日 上午10:00:10
+     */
+    public static TsysUser getUser()
+    {
+        TsysUser user = null;
+        Object obj = getSubjct().getPrincipal();
+        if (StringUtils.isNotNull(obj))
+        {
+            if(ShiroConfig.usercacheMap.containsKey(getSessionId()))
+            {
+                ConcurrentHashMap<String,Object> cmap=ShiroConfig.usercacheMap.get(getSessionId());
+                user =(TsysUser)cmap.get("user");
+                BeanUtils.copyBeanProp(user, obj);
+            }else
+            {
+                user = new TsysUser();
+                BeanUtils.copyBeanProp(user, obj);
+            }
+
+        }
+        return user;
+    }
+
+    /**
+     * set用户
+     * @param user
+     * @author gyee
+     * @Date 2019年11月21日 上午9:59:52
+     */
+    public static void setUser(TsysUser user)
+    {
+        Subject subject = getSubjct();
+        PrincipalCollection principalCollection = subject.getPrincipals();
+        String realmName = principalCollection.getRealmNames().iterator().next();
+        PrincipalCollection newPrincipalCollection = new SimplePrincipalCollection(user, realmName);
+        // 重新加载Principal
+        subject.runAs(newPrincipalCollection);
+    }
+
+    /**
+     * 清除授权信息
+     * @author gyee
+     * @Date 2019年11月21日 上午9:59:37
+     */
+    public static void clearCachedAuthorizationInfo()
+    {
+        RealmSecurityManager rsm = (RealmSecurityManager) SecurityUtils.getSecurityManager();
+        MyShiroRealm realm = (MyShiroRealm) rsm.getRealms().iterator().next();
+        realm.clearCachedAuthorizationInfo();
+    }
+
+    /**
+     * 获取登录用户id
+     * @return
+     * @author gyee
+     * @Date 2019年11月21日 上午9:58:55
+     */
+    public static String getUserId()
+    {
+        TsysUser tsysUser = getUser();
+        if (tsysUser == null || tsysUser.getId() == null){
+            throw new RuntimeException("用户不存在!");
+        }
+        return tsysUser.getId().trim();
+    }
+
+    /**
+     * 获取登录用户name
+     * @return
+     * @author gyee
+     * @Date 2019年11月21日 上午9:58:48
+     */
+    public static String getLoginName()
+    {
+        TsysUser tsysUser = getUser();
+        if (tsysUser == null){
+            throw new RuntimeException("用户不存在!");
+        }
+        return tsysUser.getUsername();
+    }
+
+    /**
+     * 获取登录用户ip
+     * @return
+     * @author gyee
+     * @Date 2019年11月21日 上午9:58:26
+     */
+    public static String getIp()
+    {
+        return getSubjct().getSession().getHost();
+    }
+
+    /**
+     * 获取登录用户sessionid
+     * @return
+     * @author gyee
+     * @Date 2019年11月21日 上午9:58:37
+     */
+    public static String getSessionId()
+    {
+        return String.valueOf(getSubjct().getSession().getId());
+    }
+}