Browse Source

fix:补充提交

韩帛霖 1 year ago
parent
commit
f073e2ea0e

+ 23 - 0
zkqy-framework/src/main/java/com/zkqy/framework/web/service/TokenService.java

@@ -4,6 +4,8 @@ import java.util.HashMap;
 import java.util.Map;
 import java.util.concurrent.TimeUnit;
 import javax.servlet.http.HttpServletRequest;
+
+import com.zkqy.common.utils.SecurityUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Value;
 import org.springframework.stereotype.Component;
@@ -76,6 +78,27 @@ public class TokenService
         }
         return null;
     }
+    /**
+     * 验证当前用户是否为admin
+     *
+     * @return 用户信息
+     */
+    public boolean getLoginUserIsAdminByToken(String token) {
+        if (StringUtils.isNotEmpty(token)) {
+            try {
+                String uuid = "";
+                Claims claims = parseToken(token);
+                // 解析对应的权限以及用户信息
+                uuid = (String) claims.get(Constants.LOGIN_USER_KEY);
+                String userKey = getTokenKey(uuid);
+                LoginUser user = redisCache.getCacheObject(userKey);
+                return SecurityUtils.isAdmin(user.getUserId());
+            } catch (Exception e) {
+                System.out.println(e);
+            }
+        }
+        return false;
+    }
 
     /**
      * 设置用户身份信息