publish 2.0.0.rc4
This commit is contained in:
BIN
springboot-util/.DS_Store
vendored
Normal file
BIN
springboot-util/.DS_Store
vendored
Normal file
Binary file not shown.
@@ -6,7 +6,7 @@
|
||||
<parent>
|
||||
<groupId>com.tiesheng.springboot-parent</groupId>
|
||||
<artifactId>springboot-parent</artifactId>
|
||||
<version>2.0.0.rc3</version>
|
||||
<version>2.0.0.rc4</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>springboot-util</artifactId>
|
||||
|
||||
@@ -4,15 +4,15 @@ package com.tiesheng.util.config;
|
||||
import cn.hutool.core.map.MapUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.extra.servlet.ServletUtil;
|
||||
import cn.hutool.extra.spring.SpringUtil;
|
||||
import cn.hutool.json.JSONUtil;
|
||||
import cn.hutool.jwt.JWT;
|
||||
import cn.hutool.jwt.JWTValidator;
|
||||
import com.tiesheng.util.ServletKit;
|
||||
import com.tiesheng.util.exception.ApiException;
|
||||
import com.tiesheng.util.pojos.TokenBean;
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.util.Map;
|
||||
|
||||
|
||||
@@ -23,6 +23,11 @@ import java.util.Map;
|
||||
@ConfigurationProperties("tiesheng.token")
|
||||
public class TsTokenConfig {
|
||||
|
||||
/**
|
||||
* token常量
|
||||
*/
|
||||
public static final String TOKEN_KEY = "token";
|
||||
|
||||
private Map<String, TokenBean> testMap = MapUtil.newHashMap();
|
||||
private String encryptKey = "%kIp9frQCu";
|
||||
private Integer expireHours = 48;
|
||||
@@ -30,28 +35,6 @@ public class TsTokenConfig {
|
||||
private boolean validLoginSign = false;
|
||||
|
||||
|
||||
/**
|
||||
* 获取当前登录的token
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public static TokenBean get() {
|
||||
TsTokenConfig tokenConfig = SpringUtil.getBean(TsTokenConfig.class);
|
||||
return tokenConfig.validToken(true);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取当前登录的token
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public static TokenBean getWithoutThr() {
|
||||
TsTokenConfig tokenConfig = SpringUtil.getBean(TsTokenConfig.class);
|
||||
return tokenConfig.validToken(false);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 验证token
|
||||
*
|
||||
@@ -72,8 +55,8 @@ public class TsTokenConfig {
|
||||
* @param thrExp
|
||||
* @return
|
||||
*/
|
||||
public TokenBean validToken(boolean thrExp) {
|
||||
String token = ServletUtil.getHeader(ServletKit.getRequest(), "token", "utf-8");
|
||||
public TokenBean validToken(HttpServletRequest request, boolean thrExp) {
|
||||
String token = ServletUtil.getHeader(request, TOKEN_KEY, "utf-8");
|
||||
return validToken(token, thrExp);
|
||||
}
|
||||
|
||||
@@ -92,14 +75,7 @@ public class TsTokenConfig {
|
||||
try {
|
||||
JWT decode = JWT.of(token);
|
||||
JWTValidator.of(decode).validateDate();
|
||||
String id = decode.getPayload("id").toString();
|
||||
String environmentType = decode.getPayload("environmentType").toString();
|
||||
String service = decode.getPayload("service").toString();
|
||||
String extra = StrUtil.toStringOrNull(decode.getPayload("extra"));
|
||||
String roleId = StrUtil.toStringOrNull(decode.getPayload("roleId"));
|
||||
tokenBean = new TokenBean(id, environmentType, service);
|
||||
tokenBean.setRoleId(roleId);
|
||||
tokenBean.setExtra(extra);
|
||||
tokenBean = JSONUtil.toBean(decode.getPayloads(), TokenBean.class);
|
||||
} catch (Exception ignored) {
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user