|
@@ -9,9 +9,14 @@ import com.fasterxml.jackson.databind.JsonNode;
|
|
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
|
|
import com.fasterxml.jackson.databind.node.ArrayNode;
|
|
import com.fasterxml.jackson.databind.node.ArrayNode;
|
|
|
import com.fasterxml.jackson.databind.node.ObjectNode;
|
|
import com.fasterxml.jackson.databind.node.ObjectNode;
|
|
|
|
|
+import com.storlead.framework.auth.vo.LoginUser;
|
|
|
|
|
+import com.storlead.framework.common.constant.DefContants;
|
|
|
|
|
+import com.storlead.framework.common.constant.UserCacheKeyConstants;
|
|
|
import com.storlead.framework.common.util.SystemUtils;
|
|
import com.storlead.framework.common.util.SystemUtils;
|
|
|
|
|
+import com.storlead.framework.common.util.UrlChainBlackAndWhiteUtil;
|
|
|
import com.storlead.framework.core.context.Context;
|
|
import com.storlead.framework.core.context.Context;
|
|
|
import com.storlead.framework.core.context.IContext;
|
|
import com.storlead.framework.core.context.IContext;
|
|
|
|
|
+import com.storlead.framework.redis.RedisService;
|
|
|
import com.storlead.framework.web.assemble.Result;
|
|
import com.storlead.framework.web.assemble.Result;
|
|
|
import com.storlead.framework.web.enums.ResultCode;
|
|
import com.storlead.framework.web.enums.ResultCode;
|
|
|
import com.storlead.framework.web.wrapper.JsonRequestWrapper;
|
|
import com.storlead.framework.web.wrapper.JsonRequestWrapper;
|
|
@@ -41,6 +46,12 @@ import java.util.concurrent.TimeUnit;
|
|
|
@Component
|
|
@Component
|
|
|
public class AuthRequestFilter implements Filter, Ordered {
|
|
public class AuthRequestFilter implements Filter, Ordered {
|
|
|
|
|
|
|
|
|
|
+ @Resource
|
|
|
|
|
+ private RedisService redisService;
|
|
|
|
|
+
|
|
|
|
|
+ @Resource
|
|
|
|
|
+ private UrlChainBlackAndWhiteUtil chainBlackAndWhiteUtil;
|
|
|
|
|
+
|
|
|
@Override
|
|
@Override
|
|
|
public void init(FilterConfig filterConfig) throws ServletException {
|
|
public void init(FilterConfig filterConfig) throws ServletException {
|
|
|
Filter.super.init(filterConfig);
|
|
Filter.super.init(filterConfig);
|
|
@@ -109,6 +120,64 @@ public class AuthRequestFilter implements Filter, Ordered {
|
|
|
|
|
|
|
|
private Boolean loginHandle(HttpServletRequest req) {
|
|
private Boolean loginHandle(HttpServletRequest req) {
|
|
|
// 获取URL
|
|
// 获取URL
|
|
|
|
|
+ String url = req.getRequestURI();
|
|
|
|
|
+ log.error("login--WebSocket ---- url---"+url);
|
|
|
|
|
+ Boolean isNeedLogin = chainBlackAndWhiteUtil.IsWhiteUri(url);
|
|
|
|
|
+ if (isNeedLogin) {
|
|
|
|
|
+ return isNeedLogin;
|
|
|
|
|
+ }
|
|
|
|
|
+ log.error("login--WebSocket ---- isNeedLogin---"+url);
|
|
|
|
|
+ String token = req.getHeader(DefContants.ACCESS_TOKEN);
|
|
|
|
|
+ if (StrUtil.isBlank(token)) {
|
|
|
|
|
+ token = req.getHeader("Sec-WebSocket-Protocol");
|
|
|
|
|
+ if (StrUtil.isNotBlank(token)) {
|
|
|
|
|
+ log.error("login--WebSocket ---- token---"+token);
|
|
|
|
|
+ req.setAttribute("token",token);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if (StringUtils.isNotBlank(token)) {
|
|
|
|
|
+ String jsonInfo = redisService.getCacheObject(token);
|
|
|
|
|
+ if (StrUtil.isNotBlank(jsonInfo) && jsonInfo.length() < "1efb52db4da5d2b92516a4eba0b3145b34234234".length()) {
|
|
|
|
|
+ jsonInfo = redisService.getCacheObject(jsonInfo);
|
|
|
|
|
+ }
|
|
|
|
|
+ if (StringUtils.isNotBlank(jsonInfo)) {
|
|
|
|
|
+ try {
|
|
|
|
|
+ IContext context = Context.getContext();
|
|
|
|
|
+ LoginUser loginUserInfo = JSONUtil.toBean(jsonInfo, LoginUser.class);
|
|
|
|
|
+
|
|
|
|
|
+ String scopeMenuId = context.getAttribute("scopeMenuId",String.class);
|
|
|
|
|
+ Object commonScope = context.getAttribute("commonScope",Object.class);
|
|
|
|
|
+ Object commonScopeType = context.getAttribute("commonScopeType",Object.class);
|
|
|
|
|
+ // 当前接口的地址
|
|
|
|
|
+ loginUserInfo.setApiUrl(url);
|
|
|
|
|
+ loginUserInfo.setScopeMenuId(scopeMenuId);
|
|
|
|
|
+ if (Objects.nonNull(commonScope)) {
|
|
|
|
|
+ loginUserInfo.setCommonScope((Integer)commonScope);
|
|
|
|
|
+ }
|
|
|
|
|
+ if (Objects.nonNull(commonScopeType)) {
|
|
|
|
|
+ loginUserInfo.setCommonScopeType(commonScopeType.toString());
|
|
|
|
|
+ }
|
|
|
|
|
+ context.setAttribute(UserCacheKeyConstants.LOGIN_USER_INFO_KEY, loginUserInfo);
|
|
|
|
|
+ context.setAttribute(UserCacheKeyConstants.LOGIN_USER_INFO_TOKEN_KEY, token);
|
|
|
|
|
+ context.setAttribute(UserCacheKeyConstants.LOGIN_USER_INFO_ID_KEY, loginUserInfo.getId());
|
|
|
|
|
+
|
|
|
|
|
+ // 修改失效时间,超过24小时没有使用,
|
|
|
|
|
+ Long expire = redisService.getCacheExpire(token,TimeUnit.SECONDS);
|
|
|
|
|
+ log.debug("getCacheExpire-----------当前用户信息 = "+loginUserInfo);
|
|
|
|
|
+ if (expire < 3600) {
|
|
|
|
|
+ redisService.setCacheExpire(token,60 * 60 * 24L * 7, TimeUnit.SECONDS);
|
|
|
|
|
+ }
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ log.error("loginHandle error",e);
|
|
|
|
|
+ return false;
|
|
|
|
|
+ }
|
|
|
|
|
+ } else {
|
|
|
|
|
+ return false;
|
|
|
|
|
+ }
|
|
|
|
|
+ } else {
|
|
|
|
|
+ return false;
|
|
|
|
|
+ }
|
|
|
return true;
|
|
return true;
|
|
|
}
|
|
}
|
|
|
|
|
|