token 解密
This commit is contained in:
parent
6d6d6cf5ea
commit
8274d8fd70
|
|
@ -79,4 +79,9 @@ public class CacheConstants
|
||||||
* */
|
* */
|
||||||
public static final String REPLAY_ATTACK ="replayAttack";
|
public static final String REPLAY_ATTACK ="replayAttack";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* auth是否需要解密
|
||||||
|
* */
|
||||||
|
public static final String AUTH ="auth";
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,11 +1,17 @@
|
||||||
package com.bonus.framework.web.service;
|
package com.bonus.framework.web.service;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.Objects;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
|
||||||
|
import com.alibaba.fastjson2.JSON;
|
||||||
import com.bonus.common.utils.encryption.Sm4Utils;
|
import com.bonus.common.utils.encryption.Sm4Utils;
|
||||||
|
import com.bonus.system.domain.vo.SystemConfigVo;
|
||||||
|
import com.bonus.system.service.ISystemConfigService;
|
||||||
|
import org.apache.commons.collections4.CollectionUtils;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
|
@ -56,6 +62,13 @@ public class TokenService
|
||||||
@Autowired
|
@Autowired
|
||||||
private RedisCache redisCache;
|
private RedisCache redisCache;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private ISystemConfigService configService;
|
||||||
|
|
||||||
|
private static final long TIMESTAMP_TOLERANCE = 15 * 60 * 1000; // 15分钟
|
||||||
|
// 请求签名在Redis中的过期时间(秒)
|
||||||
|
private static final int SIGNATURE_EXPIRE_SECONDS = (int) (TIMESTAMP_TOLERANCE * 2 / 1000);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取用户身份信息
|
* 获取用户身份信息
|
||||||
*
|
*
|
||||||
|
|
@ -278,8 +291,13 @@ public class TokenService
|
||||||
if(StringUtils.isEmpty(token)){
|
if(StringUtils.isEmpty(token)){
|
||||||
return token;
|
return token;
|
||||||
}else{
|
}else{
|
||||||
|
boolean systemConfigStatus = getSystemConfigStatus(CacheConstants.AUTH);
|
||||||
String decryptToken = Sm4Utils.decrypt(token);
|
String decryptToken = Sm4Utils.decrypt(token);
|
||||||
return decryptToken;
|
if(!systemConfigStatus && Objects.equals(decryptToken, token)){
|
||||||
|
return token;
|
||||||
|
}else{
|
||||||
|
return decryptToken;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -408,4 +426,50 @@ public class TokenService
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取系统配置
|
||||||
|
* @return boolean
|
||||||
|
* @author cwchen
|
||||||
|
* @date 2025/9/28 10:36
|
||||||
|
*/
|
||||||
|
public boolean getSystemConfigStatus(String key) {
|
||||||
|
boolean SystemConfigStatus = false;
|
||||||
|
Object cacheObject = redisCache.getCacheObject(CacheConstants.SYSTEM_CONFIG_VOS);
|
||||||
|
if(Objects.isNull(cacheObject)){
|
||||||
|
List<SystemConfigVo> systemConfigVos = configService.listConfig();
|
||||||
|
Boolean stored = redisCache.setNxCacheObject(CacheConstants.SYSTEM_CONFIG_VOS,
|
||||||
|
JSON.toJSONString(systemConfigVos),
|
||||||
|
(long) SIGNATURE_EXPIRE_SECONDS,
|
||||||
|
TimeUnit.SECONDS);
|
||||||
|
if(CollectionUtils.isNotEmpty(systemConfigVos)){
|
||||||
|
SystemConfigVo config = systemConfigVos.stream()
|
||||||
|
.filter(item -> key.equals(item.getConfigCode()))
|
||||||
|
.findFirst()
|
||||||
|
.orElse(null);
|
||||||
|
if(Objects.nonNull(config)){
|
||||||
|
String useStatus = config.getUseStatus();
|
||||||
|
if(Objects.equals("0",useStatus)){
|
||||||
|
SystemConfigStatus = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}else{
|
||||||
|
String cacheStr = (String) cacheObject;
|
||||||
|
List<SystemConfigVo> systemConfigVos = JSON.parseArray(cacheStr, SystemConfigVo.class);
|
||||||
|
if(CollectionUtils.isNotEmpty(systemConfigVos)){
|
||||||
|
SystemConfigVo config = systemConfigVos.stream()
|
||||||
|
.filter(item -> key.equals(item.getConfigCode()))
|
||||||
|
.findFirst()
|
||||||
|
.orElse(null);
|
||||||
|
if(Objects.nonNull(config)){
|
||||||
|
String useStatus = config.getUseStatus();
|
||||||
|
if(Objects.equals("0",useStatus)){
|
||||||
|
SystemConfigStatus = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return SystemConfigStatus;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Loading…
Reference in New Issue