移除 SaSignConfig 的 isCheckNonce 配置项

This commit is contained in:
click33 2024-04-27 02:55:21 +08:00
parent 50f9e00576
commit 7b45385ffd
2 changed files with 18 additions and 34 deletions

View File

@ -36,11 +36,6 @@ public class SaSignConfig {
*/
private long timestampDisparity = 1000 * 60 * 15;
/**
* 是否校验 nonce 随机字符串
*/
private Boolean isCheckNonce = true;
/**
* 获取 API 调用签名秘钥
@ -88,26 +83,6 @@ public class SaSignConfig {
return this;
}
/**
* 获取 是否校验 nonce 随机字符串
*
* @return /
*/
public Boolean getIsCheckNonce() {
return this.isCheckNonce;
}
/**
* 设置 是否校验 nonce 随机字符串
*
* @param isCheckNonce /
* @return 对象自身
*/
public SaSignConfig setIsCheckNonce(Boolean isCheckNonce) {
this.isCheckNonce = isCheckNonce;
return this;
}
/**
* 计算保存 nonce 时应该使用的 ttl单位
* @return /
@ -128,8 +103,18 @@ public class SaSignConfig {
return "SaSignConfig ["
+ "secretKey=" + secretKey
+ ", timestampDisparity=" + timestampDisparity
+ ", isCheckNonce=" + isCheckNonce
+ "]";
}
/**
* 设置是否校验 nonce 随机字符串
* <h2> isCheckNonce 方案已废弃不再提供此配置项 </h2>
*
* @param isCheckNonce /
*/
@Deprecated
public void setIsCheckNonce(Boolean isCheckNonce) {
System.err.println("--------- isCheckNonce 方案已废弃,不再提供此配置项 ---------");
}
}

View File

@ -295,13 +295,14 @@ public class SaSignTemplate {
String signValue = paramMap.get(sign);
// 参数非空校验
SaSignException.notEmpty(timestampValue, "缺少 timestamp 字段");
// SaSignException.throwByNull(nonceValue, "缺少 nonce 字段"); // 配置isCheckNonce=false时可以不传 nonce
SaSignException.notEmpty(signValue, "缺少 sign 字段");
// 配置isCheckNonce=false时可以不传 nonce
if(SaFoxUtil.isEmpty(timestampValue) || SaFoxUtil.isEmpty(signValue)) {
return false;
}
// 三个值的校验必须全部通过
return isValidTimestamp(Long.parseLong(timestampValue))
&& (getSignConfigOrGlobal().getIsCheckNonce() ? isValidNonce(nonceValue) : true)
&& isValidNonce(nonceValue)
&& isValidSign(paramMap, signValue);
}
@ -317,14 +318,12 @@ public class SaSignTemplate {
// 参数非空校验
SaSignException.notEmpty(timestampValue, "缺少 timestamp 字段");
// SaSignException.throwByNull(nonceValue, "缺少 nonce 字段"); // 配置isCheckNonce=false时可以不传 nonce
SaSignException.notEmpty(nonceValue, "缺少 nonce 字段");
SaSignException.notEmpty(signValue, "缺少 sign 字段");
// 依次校验三个参数
checkTimestamp(Long.parseLong(timestampValue));
if(getSignConfigOrGlobal().getIsCheckNonce()) {
checkNonce(nonceValue);
}
checkNonce(nonceValue);
checkSign(paramMap, signValue);
// 通过