|
@@ -4,7 +4,6 @@ import cn.hutool.core.collection.CollectionUtil;
|
|
|
import com.gis.common.constant.ConfigConstant;
|
|
|
import com.gis.common.util.JwtUtil;
|
|
|
import com.gis.admin.entity.po.SysUserEntity;
|
|
|
-import com.gis.admin.service.SysResourceService;
|
|
|
import com.gis.admin.service.SysUserService;
|
|
|
import com.gis.common.util.RedisUtil;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
@@ -18,14 +17,12 @@ import org.apache.shiro.authz.SimpleAuthorizationInfo;
|
|
|
import org.apache.shiro.realm.AuthorizingRealm;
|
|
|
import org.apache.shiro.subject.PrincipalCollection;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
-import org.springframework.data.redis.core.RedisTemplate;
|
|
|
import org.springframework.stereotype.Component;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
import java.util.HashSet;
|
|
|
import java.util.List;
|
|
|
-import java.util.Set;
|
|
|
|
|
|
/**
|
|
|
* @Description: 用户登录鉴权和获取用户授权
|
|
@@ -36,25 +33,13 @@ import java.util.Set;
|
|
|
@Component
|
|
|
@Slf4j
|
|
|
public class ShiroRealm extends AuthorizingRealm {
|
|
|
-// @Lazy
|
|
|
-// @Resource
|
|
|
-// private CommonAPI commonAPI;
|
|
|
-
|
|
|
-// @Lazy
|
|
|
-// @Resource
|
|
|
-// private RedisUtil redisUtil;
|
|
|
|
|
|
@Resource
|
|
|
HttpServletRequest request;
|
|
|
|
|
|
-// @Autowired
|
|
|
-// SysResourceService sysResourceService;
|
|
|
-
|
|
|
@Autowired
|
|
|
SysUserService sysUserService;
|
|
|
|
|
|
-// @Autowired
|
|
|
-// RedisTemplate<String, String> redisTemplate;
|
|
|
|
|
|
@Autowired
|
|
|
ConfigConstant configConstant;
|
|
@@ -88,7 +73,6 @@ public class ShiroRealm extends AuthorizingRealm {
|
|
|
SimpleAuthorizationInfo info = new SimpleAuthorizationInfo();
|
|
|
|
|
|
String token = request.getHeader("token");
|
|
|
-// log.info("token: {}", token);
|
|
|
if (StringUtils.isNotBlank(token)){
|
|
|
List userRole = JwtUtil.getUserRole(token);
|
|
|
// userId = JwtUtil.getUserId(token);
|
|
@@ -142,7 +126,7 @@ public class ShiroRealm extends AuthorizingRealm {
|
|
|
}
|
|
|
|
|
|
// String redisToken = redisTemplate.opsForValue().get(configConstant.redisPrefix + token);
|
|
|
- String redisToken = (String)redisUtil.get(configConstant.redisPrefix + token);
|
|
|
+ String redisToken = redisUtil.getCacheObject(configConstant.redisPrefix + token);
|
|
|
|
|
|
if (!token.equals(redisToken)) {
|
|
|
log.error("redis token is null");
|
|
@@ -155,7 +139,8 @@ public class ShiroRealm extends AuthorizingRealm {
|
|
|
throw new JwtAuthenticationException(5001, "token invalid");
|
|
|
}
|
|
|
|
|
|
- SysUserEntity userEntity = sysUserService.findByUserName(username);
|
|
|
+// SysUserEntity userEntity = sysUserService.findByUserName(username);
|
|
|
+ SysUserEntity userEntity = sysUserService.cacheById(JwtUtil.getUserId(token));
|
|
|
if (userEntity == null) {
|
|
|
log.error("error token userEntity");
|
|
|
throw new JwtAuthenticationException(5001, "User didn't existed!");
|