Browse Source

代码提交

hy 6 years ago
parent
commit
54fa954398

+ 1 - 0
bi-core/src/main/java/com/usoftchina/bi/core/base/BaseContextHolder.java

@@ -25,6 +25,7 @@ public class BaseContextHolder {
     public static Object get(String key) {
         Map<String, Object> map = contextHolder.get();
         if (null == map) {
+
             return null;
         }
         return map.get(key);

+ 30 - 0
bi-server/src/main/java/com/usoftchina/bi/server/aspect/JwtTokenAspect.java

@@ -111,4 +111,34 @@ public class JwtTokenAspect {
 
         return jwt.getClaims();
     }
+
+    public static Map<String, Claim> setBaseContextHolder(String token) {
+        DecodedJWT jwt = null;
+        if( StringUtils.isEmpty(token) || "null".equals(token) ){
+            return null;
+        }
+        JWTVerifier verifier = null;
+        try {
+            verifier = JWT.require(Algorithm.HMAC256(SECRET)).build();
+        } catch (UnsupportedEncodingException e) {
+            e.printStackTrace();
+        }
+        try {
+            jwt = verifier.verify(token);
+        } catch (MyException e) {
+            throw new MyException(-505, "token过期");
+        }
+
+        Lock lock = new ReentrantLock();
+        lock.lock();
+        try {
+            BaseContextHolder.setUserId(Integer.valueOf(jwt.getClaim("id").asString()));
+            BaseContextHolder.setUserName(jwt.getClaim("name").asString());
+            BaseContextHolder.setRole(jwt.getClaim("role").asString());
+        } finally {
+            lock.unlock();
+        }
+
+        return jwt.getClaims();
+    }
 }

+ 3 - 0
bi-server/src/main/java/com/usoftchina/bi/server/service/dashboard/DashboardsToChartsUtilService.java

@@ -2,6 +2,7 @@ package com.usoftchina.bi.server.service.dashboard;
 
 import com.alibaba.fastjson.JSONObject;
 import com.usoftchina.bi.core.utils.EncryUtil;
+import com.usoftchina.bi.server.aspect.JwtTokenAspect;
 import com.usoftchina.bi.server.dao.chart.ChartsConfigMapper;
 import com.fasterxml.jackson.databind.ObjectMapper;
 import com.usoftchina.bi.server.model.bo.Screen;
@@ -57,6 +58,8 @@ public class DashboardsToChartsUtilService {
             token = userService.login(loginInfo).getData().getToken();
         }
 
+        JwtTokenAspect.setBaseContextHolder(token);
+
         int chartId = chartsToDashInfo.getChartId();
 
         //拿到图表配置