浏览代码

解决空指针

yumeng 5 年之前
父节点
当前提交
678c6b6e0e
共有 1 个文件被更改,包括 9 次插入4 次删除
  1. 9 4
      jeecg-boot-module-system/src/main/java/org/jeecg/modules/shiro/authc/ShiroRealm.java

+ 9 - 4
jeecg-boot-module-system/src/main/java/org/jeecg/modules/shiro/authc/ShiroRealm.java

@@ -1,7 +1,7 @@
 package org.jeecg.modules.shiro.authc;
 
-import java.util.Set;
-
+import cn.com.ctop.common.module.utils.Check;
+import lombok.extern.slf4j.Slf4j;
 import org.apache.shiro.authc.AuthenticationException;
 import org.apache.shiro.authc.AuthenticationInfo;
 import org.apache.shiro.authc.AuthenticationToken;
@@ -22,7 +22,7 @@ import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.context.annotation.Lazy;
 import org.springframework.stereotype.Component;
 
-import lombok.extern.slf4j.Slf4j;
+import java.util.Set;
 
 /**
  * @Description: 用户登录鉴权和获取用户授权
@@ -99,13 +99,18 @@ public class ShiroRealm extends AuthorizingRealm {
      * @param token
      */
     public LoginUser checkUserTokenIsEffect(String token) throws AuthenticationException {
+        if (Check.isNull(token)) {
+            log.error("token为空");
+            return null;
+
+        }
+
         // 解密获得username,用于和数据库进行对比
         String username = JwtUtil.getUsername(token);
         if (username == null) {
             log.error("token非法无效!");
             // throw new AuthenticationException("token非法无效!");
         }
-
         // 查询用户信息
         LoginUser loginUser = new LoginUser();
         SysUser sysUser = sysUserService.getUserByName(username);