Browse Source

修改

master
yechuan 1 year ago
parent
commit
c936810044
6 changed files with 11 additions and 12 deletions
  1. +2
    -2
      common/src/main/java/work/xuye/common/dto/HttpRequestParams.java
  2. +1
    -1
      common/src/main/java/work/xuye/common/dto/HttpRes.java
  3. +1
    -1
      common/src/main/java/work/xuye/common/service/UrlMD5Service.java
  4. +2
    -2
      common/src/main/java/work/xuye/common/utils/signature/AbstractSignatureService.java
  5. +3
    -3
      common/src/main/java/work/xuye/common/utils/signature/RSASignatureService.java
  6. +2
    -3
      source/src/main/java/work/xuye/source/handler/SourceHandler.java

+ 2
- 2
common/src/main/java/work/xuye/common/dto/HttpRequestParams.java View File

@@ -37,7 +37,7 @@ public class HttpRequestParams {
private Map<String, String> placeholderExpressions = Map.of();
private String mediaType = MediaType.APPLICATION_JSON_VALUE;

private RequestSignatureConfig signature;
private RequestSignatureConfig signatureConfig;

/**
* 仅计算一次的表达式(同次请求后续使用上次计算值)
@@ -103,7 +103,7 @@ public class HttpRequestParams {
@AllArgsConstructor
@EqualsAndHashCode(callSuper = true)
public static class RequestSignatureConfig extends SignatureConfig {
private String signatureFile;
private String signatureField;
private String signatureContext;
private SignatureEnumGroup.SignatureLocation signatureLocation;
}


+ 1
- 1
common/src/main/java/work/xuye/common/dto/HttpRes.java View File

@@ -27,7 +27,7 @@ public class HttpRes {
private Long costTimeMillis;

/**
* 时变量
* 时变量
*/
@JsonInclude
private Object temporary;


+ 1
- 1
common/src/main/java/work/xuye/common/service/UrlMD5Service.java View File

@@ -50,7 +50,7 @@ public class UrlMD5Service {
parentOtherCacheKeySet.forEach(this::removeUrlMD5);
}
String sendUrl = message.getHeaders().get(MessageConstants.SEED_URL, String.class);
if (!StringUtils.hasText(sendUrl)) {
if (StringUtils.hasText(sendUrl)) {
this.removeUrlMD5(sendUrl);
}
}


+ 2
- 2
common/src/main/java/work/xuye/common/utils/signature/AbstractSignatureService.java View File

@@ -17,11 +17,11 @@ public abstract class AbstractSignatureService {
/**
* 使用私钥加密
*
* @param context
* @param content
* @return
* @throws GeneralSecurityException
*/
public abstract String signatureByPriKey(String context) throws GeneralSecurityException;
public abstract String signatureByPriKey(String content) throws GeneralSecurityException;


void init(SignatureConfig signatureConfig) throws GeneralSecurityException {


+ 3
- 3
common/src/main/java/work/xuye/common/utils/signature/RSASignatureService.java View File

@@ -23,15 +23,15 @@ import java.security.spec.X509EncodedKeySpec;
class RSASignatureService extends AbstractSignatureService {

@Override
public String signatureByPriKey(String context) throws GeneralSecurityException {
public String signatureByPriKey(String content) throws GeneralSecurityException {
if (signatureContext == null) {
throw new RuntimeException("未初始化公私钥信息");
}
Signature signature = signatureContext.getSignature();
PrivateKey priKey = signatureContext.getPriKey();
signature.initSign(priKey);
context = DigestUtils.md5DigestAsHex(context.getBytes(StandardCharsets.UTF_8)).toUpperCase();
signature.update(context.getBytes(StandardCharsets.UTF_8));
content = DigestUtils.md5DigestAsHex(content.getBytes(StandardCharsets.UTF_8)).toUpperCase();
signature.update(content.getBytes(StandardCharsets.UTF_8));
return Base64.encodeBase64String(signature.sign());
}



+ 2
- 3
source/src/main/java/work/xuye/source/handler/SourceHandler.java View File

@@ -236,7 +236,6 @@ public class SourceHandler {
.setHeader(MessageConstants.TASK_ID, task.getId())
.setHeader(MessageConstants.TASK_NAME, task.getName())
.setHeader(MessageConstants.SEED_URL, httpRes.getRequestParams().getUrl())
.setHeader(MessageConstants.SEED_URL, httpRes.getRequestParams().getUrl())
.setHeader(MessageConstants.OTHER_CACHE_KEY_SET, otherCacheKeySet)
.build();
resultMap.put(topic, nextTaskMessage);
@@ -328,7 +327,7 @@ public class SourceHandler {


private void preHandleSignature(HttpRequestParams requestParams) {
HttpRequestParams.RequestSignatureConfig signatureConfig = requestParams.getSignature();
HttpRequestParams.RequestSignatureConfig signatureConfig = requestParams.getSignatureConfig();
if (ObjectUtils.isEmpty(signatureConfig)) {
return;
}
@@ -340,7 +339,7 @@ public class SourceHandler {
String signature = signatureService.signatureByPriKey(signatureContext);
// 优化
if (SignatureEnumGroup.SignatureLocation.header.equals(signatureConfig.getSignatureLocation())) {
requestParams.getHeaders().put(signatureConfig.getSignatureFile(), signature);
requestParams.getHeaders().put(signatureConfig.getSignatureField(), signature);
}
} catch (GeneralSecurityException e) {
throw new RuntimeException(e);


Loading…
Cancel
Save