|
@@ -8,6 +8,7 @@ import com.qmth.themis.business.entity.TBSession;
|
|
import com.qmth.themis.business.entity.TBUser;
|
|
import com.qmth.themis.business.entity.TBUser;
|
|
import com.qmth.themis.business.enums.RoleEnum;
|
|
import com.qmth.themis.business.enums.RoleEnum;
|
|
import com.qmth.themis.business.service.EhcacheService;
|
|
import com.qmth.themis.business.service.EhcacheService;
|
|
|
|
+import com.qmth.themis.business.service.TBUserService;
|
|
import com.qmth.themis.business.util.EhcacheUtil;
|
|
import com.qmth.themis.business.util.EhcacheUtil;
|
|
import com.qmth.themis.business.util.JwtUtil;
|
|
import com.qmth.themis.business.util.JwtUtil;
|
|
import com.qmth.themis.business.util.RedisUtil;
|
|
import com.qmth.themis.business.util.RedisUtil;
|
|
@@ -44,6 +45,9 @@ public class AuthInterceptor implements HandlerInterceptor {
|
|
@Resource
|
|
@Resource
|
|
DictionaryConfig dictionaryConfig;
|
|
DictionaryConfig dictionaryConfig;
|
|
|
|
|
|
|
|
+ @Resource
|
|
|
|
+ TBUserService tbUserService;
|
|
|
|
+
|
|
@Override
|
|
@Override
|
|
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object object) throws Exception {
|
|
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object object) throws Exception {
|
|
log.info("HandlerInterceptor preHandle is come in");
|
|
log.info("HandlerInterceptor preHandle is come in");
|
|
@@ -67,10 +71,10 @@ public class AuthInterceptor implements HandlerInterceptor {
|
|
if (Objects.isNull(deviceId) || Objects.equals(deviceId, "")) {
|
|
if (Objects.isNull(deviceId) || Objects.equals(deviceId, "")) {
|
|
throw new BusinessException(ExceptionResultEnum.DEVICE_ID_INVALID);
|
|
throw new BusinessException(ExceptionResultEnum.DEVICE_ID_INVALID);
|
|
}
|
|
}
|
|
- String userId = JwtUtil.getClaim(token, SystemConstant.JWT_USERID);
|
|
|
|
|
|
+ Long userId = Long.parseLong(JwtUtil.getClaim(token, SystemConstant.JWT_USERID));
|
|
String role = JwtUtil.getClaim(token, SystemConstant.ROLE);
|
|
String role = JwtUtil.getClaim(token, SystemConstant.ROLE);
|
|
//首先验证token是否匹配
|
|
//首先验证token是否匹配
|
|
- if (!JwtUtil.verify(token, Long.parseLong(userId), platform, deviceId, RoleEnum.valueOf(role))) {
|
|
|
|
|
|
+ if (!JwtUtil.verify(token, userId, platform, deviceId, RoleEnum.valueOf(role))) {
|
|
throw new BusinessException(ExceptionResultEnum.TOKEN_NO);
|
|
throw new BusinessException(ExceptionResultEnum.TOKEN_NO);
|
|
}
|
|
}
|
|
//系统公用接口不拦截
|
|
//系统公用接口不拦截
|
|
@@ -81,16 +85,9 @@ public class AuthInterceptor implements HandlerInterceptor {
|
|
if (sysCount > 0) {
|
|
if (sysCount > 0) {
|
|
return true;
|
|
return true;
|
|
}
|
|
}
|
|
- TBUser tbUser = (TBUser) RedisUtil.getUser(Long.parseLong(userId));
|
|
|
|
- if (Objects.isNull(tbUser)) {
|
|
|
|
- throw new BusinessException(ExceptionResultEnum.LOGIN_NO);
|
|
|
|
- }
|
|
|
|
- AuthDto authDto = (AuthDto) EhcacheUtil.get(SystemConstant.AUTH_CACHE, Long.parseLong(userId));
|
|
|
|
- if (Objects.isNull(authDto)) {
|
|
|
|
- authDto = ehcacheService.addAccountCache(userId);
|
|
|
|
- }
|
|
|
|
//验证token是否有效
|
|
//验证token是否有效
|
|
- String sessionId = SessionUtil.digest(Long.parseLong(userId), authDto.getRoleEnum().name(), platform.getSource());
|
|
|
|
|
|
+ TBUser tbUser = (TBUser) RedisUtil.getUser(userId);
|
|
|
|
+ String sessionId = SessionUtil.digest(userId, RoleEnum.valueOf(role), platform.getSource());
|
|
TBSession tbSession = (TBSession) RedisUtil.getUserSession(sessionId);
|
|
TBSession tbSession = (TBSession) RedisUtil.getUserSession(sessionId);
|
|
if (Objects.isNull(tbSession)) {
|
|
if (Objects.isNull(tbSession)) {
|
|
throw new BusinessException(ExceptionResultEnum.LOGIN_NO);
|
|
throw new BusinessException(ExceptionResultEnum.LOGIN_NO);
|
|
@@ -99,10 +96,22 @@ public class AuthInterceptor implements HandlerInterceptor {
|
|
throw new BusinessException(ExceptionResultEnum.TOKEN_NO);
|
|
throw new BusinessException(ExceptionResultEnum.TOKEN_NO);
|
|
}
|
|
}
|
|
Date expireTime = tbSession.getExpireTime();
|
|
Date expireTime = tbSession.getExpireTime();
|
|
- if (expireTime.getTime() <= System.currentTimeMillis()) {
|
|
|
|
|
|
+ if (Objects.nonNull(expireTime) && expireTime.getTime() <= System.currentTimeMillis()) {
|
|
throw new BusinessException(ExceptionResultEnum.TOKEN_NO);
|
|
throw new BusinessException(ExceptionResultEnum.TOKEN_NO);
|
|
|
|
+ } else {
|
|
|
|
+ if (Objects.isNull(tbUser)) {
|
|
|
|
+ tbUser = tbUserService.getById(userId);
|
|
|
|
+ RedisUtil.setUser(tbUser.getId(), platform, tbUser);
|
|
|
|
+ }
|
|
|
|
+ if (Objects.nonNull(expireTime) && (expireTime.getTime() - System.currentTimeMillis()) <= SystemConstant.REFRESH_EXPIRE_TIME) {
|
|
|
|
+ RedisUtil.refreshUserSession(sessionId, platform);
|
|
|
|
+ }
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
+ AuthDto authDto = (AuthDto) EhcacheUtil.get(SystemConstant.AUTH_CACHE, userId);
|
|
|
|
+ if (Objects.isNull(authDto)) {
|
|
|
|
+ authDto = ehcacheService.addAccountCache(userId);
|
|
|
|
+ }
|
|
//验证权限
|
|
//验证权限
|
|
Set<String> urls = authDto.getUrls();
|
|
Set<String> urls = authDto.getUrls();
|
|
int count = (int) urls.stream().filter(s -> {
|
|
int count = (int) urls.stream().filter(s -> {
|