|
@@ -4,7 +4,6 @@ import cn.hutool.core.collection.CollectionUtil;
|
|
|
import com.gis.common.constant.ConfigConstant;
|
|
import com.gis.common.constant.ConfigConstant;
|
|
|
import com.gis.common.util.JwtUtil;
|
|
import com.gis.common.util.JwtUtil;
|
|
|
import com.gis.admin.entity.po.SysUserEntity;
|
|
import com.gis.admin.entity.po.SysUserEntity;
|
|
|
-import com.gis.admin.service.SysResourceService;
|
|
|
|
|
import com.gis.admin.service.SysUserService;
|
|
import com.gis.admin.service.SysUserService;
|
|
|
import com.gis.common.util.RedisUtil;
|
|
import com.gis.common.util.RedisUtil;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
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.realm.AuthorizingRealm;
|
|
|
import org.apache.shiro.subject.PrincipalCollection;
|
|
import org.apache.shiro.subject.PrincipalCollection;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
-import org.springframework.data.redis.core.RedisTemplate;
|
|
|
|
|
import org.springframework.stereotype.Component;
|
|
import org.springframework.stereotype.Component;
|
|
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
import javax.annotation.Resource;
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
import java.util.HashSet;
|
|
import java.util.HashSet;
|
|
|
import java.util.List;
|
|
import java.util.List;
|
|
|
-import java.util.Set;
|
|
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* @Description: 用户登录鉴权和获取用户授权
|
|
* @Description: 用户登录鉴权和获取用户授权
|
|
@@ -36,26 +33,13 @@ import java.util.Set;
|
|
|
@Component
|
|
@Component
|
|
|
@Slf4j
|
|
@Slf4j
|
|
|
public class ShiroRealm extends AuthorizingRealm {
|
|
public class ShiroRealm extends AuthorizingRealm {
|
|
|
-// @Lazy
|
|
|
|
|
-// @Resource
|
|
|
|
|
-// private CommonAPI commonAPI;
|
|
|
|
|
-
|
|
|
|
|
-// @Lazy
|
|
|
|
|
-// @Resource
|
|
|
|
|
-// private RedisUtil redisUtil;
|
|
|
|
|
|
|
|
|
|
@Resource
|
|
@Resource
|
|
|
HttpServletRequest request;
|
|
HttpServletRequest request;
|
|
|
|
|
|
|
|
-// @Autowired
|
|
|
|
|
-// SysResourceService sysResourceService;
|
|
|
|
|
-
|
|
|
|
|
@Autowired
|
|
@Autowired
|
|
|
SysUserService sysUserService;
|
|
SysUserService sysUserService;
|
|
|
|
|
|
|
|
-// @Autowired
|
|
|
|
|
-// RedisTemplate<String, String> redisTemplate;
|
|
|
|
|
-
|
|
|
|
|
@Autowired
|
|
@Autowired
|
|
|
ConfigConstant configConstant;
|
|
ConfigConstant configConstant;
|
|
|
|
|
|
|
@@ -113,7 +97,7 @@ public class ShiroRealm extends AuthorizingRealm {
|
|
|
*/
|
|
*/
|
|
|
@Override
|
|
@Override
|
|
|
protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken auth) throws AuthenticationException {
|
|
protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken auth) throws AuthenticationException {
|
|
|
-// log.debug("===============Shiro身份认证开始============doGetAuthenticationInfo==========");
|
|
|
|
|
|
|
+ log.info("run doGetAuthenticationInfo");
|
|
|
String token = (String) auth.getCredentials();
|
|
String token = (String) auth.getCredentials();
|
|
|
// log.info("token: {}", token);
|
|
// log.info("token: {}", token);
|
|
|
if (token == null) {
|
|
if (token == null) {
|
|
@@ -136,8 +120,7 @@ public class ShiroRealm extends AuthorizingRealm {
|
|
|
throw new JwtAuthenticationException(5001, "token invalid");
|
|
throw new JwtAuthenticationException(5001, "token invalid");
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-// 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)) {
|
|
if (!token.equals(redisToken)) {
|
|
|
log.error("redis token is null");
|
|
log.error("redis token is null");
|
|
@@ -145,6 +128,8 @@ public class ShiroRealm extends AuthorizingRealm {
|
|
|
|
|
|
|
|
}
|
|
}
|
|
|
// 查询用户信息
|
|
// 查询用户信息
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
if (! JwtUtil.isVerify(token, username)) {
|
|
if (! JwtUtil.isVerify(token, username)) {
|
|
|
log.error("error token username or password");
|
|
log.error("error token username or password");
|
|
|
throw new JwtAuthenticationException(5001, "token invalid");
|
|
throw new JwtAuthenticationException(5001, "token invalid");
|