获取最新的cookie时间戳,前端暂未对接

beetlsql3-dev
Mlxa0324 2 years ago
parent a985c9b1e1
commit e11fb4b079

@ -212,6 +212,34 @@ public class HttpRequestLocal {
return defaultIfBlank(defaultIfBlank(tokenHeader, cookieValue), cookieTokenValue);
}
/**
*
* @return
*/
public static String getLastRoleTag() {
HttpServletRequest request = getRequest();
final Cookie cookies[] = request.getCookies();
String roleTag = "";
try {
// Cookie里取最新时间创建的Token
Comparator<Cookie> cookieComparator = (o1, o2) ->
defaultIfNull(jwtTokenSplitTimestamp(o2.getValue())[1], "")
.compareTo(defaultIfNull(jwtTokenSplitTimestamp(o1.getValue())[1], ""));
List<Cookie> cookieList = isNull(cookies) ? Lists.newArrayList() : Arrays.stream(cookies)
.sorted(cookieComparator).collect(Collectors.toList());
Cookie cookie = cookieList.stream().findFirst().orElseGet(null);
if (cookie != null) {
String[] tokenValue = cookie.getValue().split("\\.");
roleTag = tokenValue[tokenValue.length - 1];
}
} catch (Exception e) { }
return roleTag;
}
public Object getSessionValue(String key){
String headerToken = getRequestToken();
if (headerToken == null) {

@ -57,6 +57,7 @@ import static cn.jlw.Interceptor.AuthenticationInterceptor.indexTokenMap;
import static cn.jlw.token.TokenService.updateByIds;
import static com.ibeetl.admin.core.enums.MenuEnums.JT_S_02;
import static com.ibeetl.admin.core.service.CorePlatformService.tokenSessionMap;
import static com.ibeetl.admin.core.util.HttpRequestLocal.getLastRoleTag;
import static com.ibeetl.admin.core.util.HttpRequestLocal.jwtTokenSplitTimestamp;
@Controller
@ -927,7 +928,7 @@ public class IndexController {
log.error("教师用户信息:"+ JSONUtil.toJsonStr(teacher));
log.error("学生用户信息:"+ JSONUtil.toJsonStr(student));
String roleTagCopy = StringUtils.isNotBlank(roleTag) ? ( "?_role_tag=" + roleTag ) : "";
String roleTagCopy = StringUtils.isNotBlank(roleTag) ? ( "?_role_tag=" + roleTag ) : getLastRoleTag();
try {
//判断是老师还是学生

Loading…
Cancel
Save