|
|
|
@ -1,8 +1,8 @@
|
|
|
|
|
package com.ibeetl.admin.core.util;
|
|
|
|
|
|
|
|
|
|
import cn.hutool.core.collection.CollectionUtil;
|
|
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
|
|
import com.ibeetl.admin.core.conf.MVCConf;
|
|
|
|
|
import org.apache.commons.compress.utils.Lists;
|
|
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
|
import org.springframework.context.annotation.Bean;
|
|
|
|
@ -21,8 +21,7 @@ import java.util.concurrent.ConcurrentHashMap;
|
|
|
|
|
import java.util.concurrent.TimeUnit;
|
|
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
|
|
import static cn.hutool.core.util.ObjectUtil.defaultIfBlank;
|
|
|
|
|
import static cn.hutool.core.util.ObjectUtil.defaultIfNull;
|
|
|
|
|
import static cn.hutool.core.util.ObjectUtil.*;
|
|
|
|
|
import static com.ibeetl.admin.core.service.CorePlatformService.LOGIN_USER_TTL;
|
|
|
|
|
import static com.ibeetl.admin.core.service.CorePlatformService.TOKEN_KEY;
|
|
|
|
|
import static com.ibeetl.admin.core.util.servlet.ServletUtils.getRequest;
|
|
|
|
@ -87,6 +86,7 @@ public class HttpRequestLocal {
|
|
|
|
|
public String getRequestToken() {
|
|
|
|
|
HttpServletRequest request = getRequest();
|
|
|
|
|
final String tokenHeader = request.getHeader(AUTHORIZATION);
|
|
|
|
|
final Cookie cookies[] = request.getCookies();
|
|
|
|
|
|
|
|
|
|
String cookieTokenValue = null;
|
|
|
|
|
|
|
|
|
@ -96,10 +96,10 @@ public class HttpRequestLocal {
|
|
|
|
|
Comparator<Cookie> cookieComparator = (o1, o2) ->
|
|
|
|
|
defaultIfNull(jwtTokenSplitTimestamp(o2.getValue())[1], "")
|
|
|
|
|
.compareTo(defaultIfNull(jwtTokenSplitTimestamp(o1.getValue())[1], ""));
|
|
|
|
|
List<Cookie> cookies = Arrays.stream(request.getCookies())
|
|
|
|
|
List<Cookie> cookiecookieList = isNull(cookies) ? Lists.newArrayList() : Arrays.stream(cookies)
|
|
|
|
|
.sorted(cookieComparator).collect(Collectors.toList());
|
|
|
|
|
|
|
|
|
|
Cookie cookie = CollectionUtil.emptyIfNull(cookies).stream().findFirst().orElseGet(null);
|
|
|
|
|
Cookie cookie = cookiecookieList.stream().findFirst().orElseGet(null);
|
|
|
|
|
|
|
|
|
|
if (cookie != null) {
|
|
|
|
|
cookieTokenValue = cookie.getValue();
|
|
|
|
@ -110,7 +110,8 @@ public class HttpRequestLocal {
|
|
|
|
|
// 获取url中的_role_tag 时间戳属性,匹配cookie中的时间戳值。来拿到token
|
|
|
|
|
String roleTag = defaultIfNull(request.getParameter("_role_tag"), request.getHeader("_role_tag"));
|
|
|
|
|
|
|
|
|
|
Optional<Cookie> first = Arrays.stream(request.getCookies())
|
|
|
|
|
|
|
|
|
|
Optional<Cookie> first = isNull(cookies) ? Optional.empty() : Arrays.stream(cookies)
|
|
|
|
|
// 时间戳结尾判断
|
|
|
|
|
.filter(item -> item.getValue().endsWith("\\." + roleTag)).findFirst();
|
|
|
|
|
|
|
|
|
|