diff --git a/scfs-api-core/src/main/java/com/czcb/scfs/api/core/cipher/Signer.java b/scfs-api-core/src/main/java/com/czcb/scfs/api/core/cipher/Signer.java index ffb42c0..d95df95 100644 --- a/scfs-api-core/src/main/java/com/czcb/scfs/api/core/cipher/Signer.java +++ b/scfs-api-core/src/main/java/com/czcb/scfs/api/core/cipher/Signer.java @@ -14,6 +14,9 @@ public interface Signer { */ SignatureResult sign(String message); + /** + * @return 签名证书编号 + */ String getCertificateSerial(); /** diff --git a/scfs-api-core/src/main/java/com/czcb/scfs/api/core/cipher/Validator.java b/scfs-api-core/src/main/java/com/czcb/scfs/api/core/cipher/Validator.java index 1741b21..477738f 100644 --- a/scfs-api-core/src/main/java/com/czcb/scfs/api/core/cipher/Validator.java +++ b/scfs-api-core/src/main/java/com/czcb/scfs/api/core/cipher/Validator.java @@ -14,4 +14,9 @@ public interface Validator { * 验证返回是否合法 */ void validate(HttpRequest request, OriginalResponse response, Channel channel); + + /** + * 验证请求 + */ + void validate(HttpRequest newRequest); } diff --git a/scfs-api-core/src/test/java/com/czcb/scfs/api/core/cipher/DefaultValidatorTest.java b/scfs-api-core/src/test/java/com/czcb/scfs/api/core/cipher/DefaultValidatorTest.java index a79f5b0..d6ecbb6 100644 --- a/scfs-api-core/src/test/java/com/czcb/scfs/api/core/cipher/DefaultValidatorTest.java +++ b/scfs-api-core/src/test/java/com/czcb/scfs/api/core/cipher/DefaultValidatorTest.java @@ -1,5 +1,6 @@ package com.czcb.scfs.api.core.cipher; +import com.czcb.scfs.api.core.Channel; import com.czcb.scfs.api.core.DefaultChannel; import com.czcb.scfs.api.core.KeyText; import com.czcb.scfs.api.core.Profile; @@ -95,7 +96,9 @@ class DefaultValidatorTest { .statusCode(200) .build(); - defaultValidator.isInvalidHttpCode(response); + Assertions.assertDoesNotThrow(() -> { + defaultValidator.isInvalidHttpCode(response); + }); } @Test @@ -240,10 +243,12 @@ class DefaultValidatorTest { .statusCode(200) .build(); - ValidationException validationException = Assertions.assertThrows(ValidationException.class, () -> defaultValidator.validateResponseSignature(response, new DefaultChannel.Builder() + Channel channel = new DefaultChannel.Builder() .channelNo("1010") .appNo("1111") - .build())); + .build(); + + ValidationException validationException = Assertions.assertThrows(ValidationException.class, () -> defaultValidator.validateResponseSignature(response, channel)); Assertions.assertEquals("校验失败, 签名[X-SCFS-Signature]不存在, Request-Id=123456789, HttpResponseBody=123", validationException.getLocalizedMessage()); } @@ -265,10 +270,12 @@ class DefaultValidatorTest { .statusCode(200) .build(); - ValidationException validationException = Assertions.assertThrows(ValidationException.class, () -> defaultValidator.validateResponseSignature(response, new DefaultChannel.Builder() + + Channel channel = new DefaultChannel.Builder() .channelNo("1010") .appNo("1111") - .build())); + .build(); + ValidationException validationException = Assertions.assertThrows(ValidationException.class, () -> defaultValidator.validateResponseSignature(response, channel)); Assertions.assertEquals("校验失败, 签名[X-SCFS-Signature=MTIzNDU2Nzg5]校验未通过, Request-Id=123456789, HttpResponseBody=123", validationException.getLocalizedMessage()); } diff --git a/scfs-api-spring-boot-starter/src/main/java/com/czcb/scfs/spring/boot/starter/ScfsApiGatewayProperties.java b/scfs-api-spring-boot-starter/src/main/java/com/czcb/scfs/spring/boot/starter/ScfsApiGatewayProperties.java index f817487..42bb818 100644 --- a/scfs-api-spring-boot-starter/src/main/java/com/czcb/scfs/spring/boot/starter/ScfsApiGatewayProperties.java +++ b/scfs-api-spring-boot-starter/src/main/java/com/czcb/scfs/spring/boot/starter/ScfsApiGatewayProperties.java @@ -2,6 +2,7 @@ package com.czcb.scfs.spring.boot.starter; import com.czcb.scfs.api.core.cipher.StoreType; import com.czcb.scfs.api.core.http.LogLevel; +import lombok.Data; import org.springframework.boot.context.properties.ConfigurationProperties; import java.util.HashMap; @@ -12,6 +13,7 @@ import java.util.Map; * @author wangwei * @since 2.0.0 */ +@Data @ConfigurationProperties(prefix = "scfs.api-gateway") public class ScfsApiGatewayProperties { /** @@ -38,46 +40,7 @@ public class ScfsApiGatewayProperties { */ private Httpclient httpclient = new Httpclient(); - public Boolean getOnline() { - return online; - } - - public void setOnline(Boolean online) { - this.online = online; - } - - public String getHost() { - return host; - } - - public Channel getChannel() { - return channel; - } - - public void setChannel(Channel channel) { - this.channel = channel; - } - - public void setHost(String host) { - this.host = host; - } - - public Httpclient getHttpclient() { - return httpclient; - } - - public void setHttpclient(Httpclient httpclient) { - this.httpclient = httpclient; - } - - public Cipher getCipher() { - return cipher; - } - - public void setCipher(Cipher cipher) { - this.cipher = cipher; - } - + @Data public static class Channel { /** * 渠道号 @@ -89,23 +52,9 @@ public class ScfsApiGatewayProperties { */ private String appNo; - public String getChannelNo() { - return channelNo; - } - - public void setChannelNo(String channelNo) { - this.channelNo = channelNo; - } - - public String getAppNo() { - return appNo; - } - - public void setAppNo(String appNo) { - this.appNo = appNo; - } } + @Data public static class Cipher { /** * 存储方式,默认文件系统(绝对路径) @@ -126,39 +75,9 @@ public class ScfsApiGatewayProperties { */ private List certificate; - public StoreType getStoreType() { - return storeType; - } - - public void setStoreType(StoreType storeType) { - this.storeType = storeType; - } - - public String getChannelPrivateKey() { - return channelPrivateKey; - } - - public void setChannelPrivateKey(String channelPrivateKey) { - this.channelPrivateKey = channelPrivateKey; - } - - public String getChannelCertificateSerial() { - return channelCertificateSerial; - } - - public void setChannelCertificateSerial(String channelCertificateSerial) { - this.channelCertificateSerial = channelCertificateSerial; - } - - public List getCertificate() { - return certificate; - } - - public void setCertificate(List certificate) { - this.certificate = certificate; - } } + @Data public static class Httpclient { /** * 请求日志打印级别 默认 basic @@ -184,46 +103,7 @@ public class ScfsApiGatewayProperties { */ private Map headers = new HashMap<>(); - public LogLevel getLogLevel() { - return logLevel; - } - - public void setLogLevel(LogLevel logLevel) { - this.logLevel = logLevel; - } - - public Boolean getCompressionEnabled() { - return compressionEnabled; - } - - public void setCompressionEnabled(Boolean compressionEnabled) { - this.compressionEnabled = compressionEnabled; - } - - public ConnPool getConnPool() { - return connPool; - } - - public void setConnPool(ConnPool connPool) { - this.connPool = connPool; - } - - public Proxy getProxy() { - return proxy; - } - - public void setProxy(Proxy proxy) { - this.proxy = proxy; - } - - public Map getHeaders() { - return headers; - } - - public void setHeaders(Map headers) { - this.headers = headers; - } - + @Data public static class Proxy { /** * 是否启用代理模式 @@ -250,56 +130,9 @@ public class ScfsApiGatewayProperties { * 代理协议 默认 http */ private String scheme = "http"; - - public Boolean getEnabled() { - return enabled; - } - - public void setEnabled(Boolean enabled) { - this.enabled = enabled; - } - - public String getHost() { - return host; - } - - public void setHost(String host) { - this.host = host; - } - - public String getPort() { - return port; - } - - public void setPort(String port) { - this.port = port; - } - - public String getUsername() { - return username; - } - - public void setUsername(String username) { - this.username = username; - } - - public String getPassword() { - return password; - } - - public void setPassword(String password) { - this.password = password; - } - - public String getScheme() { - return scheme; - } - - public void setScheme(String scheme) { - this.scheme = scheme; - } } + @Data public static class ConnPool { /** * 最大连接数 @@ -317,38 +150,6 @@ public class ScfsApiGatewayProperties { * socket 超时时间 默认60秒 */ private Integer socketTimeout = 60; - - public int getMaxRequests() { - return maxRequests; - } - - public void setMaxRequests(Integer maxRequests) { - this.maxRequests = maxRequests; - } - - public int getMaxRequestPerHost() { - return maxRequestPerHost; - } - - public void setMaxRequestPerHost(Integer maxRequestPerHost) { - this.maxRequestPerHost = maxRequestPerHost; - } - - public Integer getConnectTimeout() { - return connectTimeout; - } - - public void setConnectTimeout(Integer connectTimeout) { - this.connectTimeout = connectTimeout; - } - - public Integer getSocketTimeout() { - return socketTimeout; - } - - public void setSocketTimeout(Integer socketTimeout) { - this.socketTimeout = socketTimeout; - } } } }