diff --git a/base-framework-kms-starter/src/main/java/com/fuhouyu/framework/kms/DefaultKmsAutoConfigure.java b/base-framework-kms-starter/src/main/java/com/fuhouyu/framework/kms/DefaultKmsAutoConfigure.java index 6e25872..e697c21 100644 --- a/base-framework-kms-starter/src/main/java/com/fuhouyu/framework/kms/DefaultKmsAutoConfigure.java +++ b/base-framework-kms-starter/src/main/java/com/fuhouyu/framework/kms/DefaultKmsAutoConfigure.java @@ -26,6 +26,7 @@ import com.fuhouyu.framework.kms.properties.KmsDefaultProperties; import com.fuhouyu.framework.kms.service.KmsService; import com.fuhouyu.framework.kms.service.impl.DefaultKmsServiceImpl; +import lombok.RequiredArgsConstructor; import org.bouncycastle.crypto.CipherParameters; import org.bouncycastle.crypto.engines.SM4Engine; import org.bouncycastle.crypto.macs.CMac; @@ -55,14 +56,11 @@ */ @ConditionalOnMissingBean(KmsService.class) @EnableConfigurationProperties(KmsDefaultProperties.class) +@RequiredArgsConstructor public class DefaultKmsAutoConfigure { private final KmsDefaultProperties properties; - public DefaultKmsAutoConfigure(KmsDefaultProperties properties) { - this.properties = properties; - } - /** * 返回默认的bean * diff --git a/base-framework-kms-starter/src/main/java/com/fuhouyu/framework/kms/service/impl/DefaultKmsServiceImpl.java b/base-framework-kms-starter/src/main/java/com/fuhouyu/framework/kms/service/impl/DefaultKmsServiceImpl.java index 68c2644..2d5f07e 100644 --- a/base-framework-kms-starter/src/main/java/com/fuhouyu/framework/kms/service/impl/DefaultKmsServiceImpl.java +++ b/base-framework-kms-starter/src/main/java/com/fuhouyu/framework/kms/service/impl/DefaultKmsServiceImpl.java @@ -25,8 +25,6 @@ import com.fuhouyu.framework.kms.service.KmsService; import org.bouncycastle.crypto.macs.CMac; import org.bouncycastle.util.encoders.Hex; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import java.io.ByteArrayOutputStream; import java.nio.charset.StandardCharsets; @@ -44,8 +42,6 @@ */ public class DefaultKmsServiceImpl implements KmsService { - private static final Logger LOGGER = LoggerFactory.getLogger(DefaultKmsServiceImpl.class); - /** * 非对称加密 */ diff --git a/base-framework-web-starter/src/main/java/com/fuhouyu/framework/web/WebAutoConfigure.java b/base-framework-web-starter/src/main/java/com/fuhouyu/framework/web/WebAutoConfigure.java index 3e9fcf4..fc37f58 100644 --- a/base-framework-web-starter/src/main/java/com/fuhouyu/framework/web/WebAutoConfigure.java +++ b/base-framework-web-starter/src/main/java/com/fuhouyu/framework/web/WebAutoConfigure.java @@ -20,6 +20,7 @@ import com.fuhouyu.framework.web.config.WebMvcAutoConfigure; import com.fuhouyu.framework.web.filter.DefaultHttpBodyFilter; import com.fuhouyu.framework.web.filter.HttpBodyFilter; +import org.springframework.beans.factory.InitializingBean; import org.springframework.boot.autoconfigure.condition.ConditionalOnBean; import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; import org.springframework.boot.context.properties.ConfigurationPropertiesScan; @@ -38,7 +39,7 @@ @Import({WebMvcAutoConfigure.class, FormAutoConfigure.class}) @ComponentScan(basePackageClasses = WebAutoConfigure.class) @ConfigurationPropertiesScan(basePackages = "com.fuhouyu.framework.web.properties") -public class WebAutoConfigure { +public class WebAutoConfigure implements InitializingBean { /** @@ -53,4 +54,8 @@ public HttpBodyFilter httpBodyFilter(KmsService kmsService) { return new DefaultHttpBodyFilter(kmsService); } + @Override + public void afterPropertiesSet() throws Exception { + System.out.println(); + } } diff --git a/base-framework-web-starter/src/main/java/com/fuhouyu/framework/web/filter/DefaultHttpBodyFilter.java b/base-framework-web-starter/src/main/java/com/fuhouyu/framework/web/filter/DefaultHttpBodyFilter.java index 8481be9..1f1866b 100644 --- a/base-framework-web-starter/src/main/java/com/fuhouyu/framework/web/filter/DefaultHttpBodyFilter.java +++ b/base-framework-web-starter/src/main/java/com/fuhouyu/framework/web/filter/DefaultHttpBodyFilter.java @@ -21,10 +21,10 @@ import com.fuhouyu.framework.utils.JacksonUtil; import com.fuhouyu.framework.utils.LoggerUtil; import lombok.Getter; +import lombok.RequiredArgsConstructor; import lombok.Setter; import lombok.ToString; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; +import lombok.extern.slf4j.Slf4j; import java.util.Objects; @@ -36,26 +36,17 @@ * @author fuhouyu * @since 2024/8/22 12:16 */ +@RequiredArgsConstructor +@Slf4j public class DefaultHttpBodyFilter implements HttpBodyFilter { - private static final Logger LOGGER = LoggerFactory.getLogger(DefaultHttpBodyFilter.class); - private final KmsService kmsService; - /** - * 构造函数 - * - * @param kmsService kms密钥管理器 - */ - public DefaultHttpBodyFilter(KmsService kmsService) { - this.kmsService = kmsService; - } - @Override public byte[] decryptionBody(byte[] encryptBodyBytes) { HttpBodyEncryptionModel httpBodyEncryptionModel = JacksonUtil.readValue(encryptBodyBytes, HttpBodyEncryptionModel.class); if (Objects.isNull(httpBodyEncryptionModel)) { - LoggerUtil.error(LOGGER, + LoggerUtil.warn(log, "需要解密转换后的body对象为空,直接返回"); return encryptBodyBytes; } diff --git a/base-framework-web-starter/src/test/java/com/fuhouyu/framework/web/WebHandlerTest.java b/base-framework-web-starter/src/test/java/com/fuhouyu/framework/web/WebHandlerTest.java index 35830f4..79b0e9e 100644 --- a/base-framework-web-starter/src/test/java/com/fuhouyu/framework/web/WebHandlerTest.java +++ b/base-framework-web-starter/src/test/java/com/fuhouyu/framework/web/WebHandlerTest.java @@ -16,7 +16,9 @@ package com.fuhouyu.framework.web; +import com.fuhouyu.framework.kms.KmsAutoConfigure; import com.fuhouyu.framework.web.config.WebMvcAutoConfigure; +import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; @@ -32,7 +34,8 @@ * @since 2024/8/17 11:47 */ @SpringBootTest(classes = { - WebAutoConfigure.class + KmsAutoConfigure.class, + WebAutoConfigure.class, }) @TestPropertySource(locations = {"classpath:application.yaml"}) class WebHandlerTest { @@ -46,5 +49,6 @@ class WebHandlerTest { void testAutoConfigure() { InterceptorRegistry interceptorRegistry = new InterceptorRegistry(); webMvcAutoConfigure.addInterceptors(interceptorRegistry); + Assertions.assertNotNull(webMvcAutoConfigure); } } diff --git a/base-framework-web-starter/src/test/java/com/fuhouyu/framework/web/form/WebFormNoRepeatSubmitTest.java b/base-framework-web-starter/src/test/java/com/fuhouyu/framework/web/form/WebFormNoRepeatSubmitTest.java index 21783d4..c586425 100644 --- a/base-framework-web-starter/src/test/java/com/fuhouyu/framework/web/form/WebFormNoRepeatSubmitTest.java +++ b/base-framework-web-starter/src/test/java/com/fuhouyu/framework/web/form/WebFormNoRepeatSubmitTest.java @@ -18,14 +18,15 @@ import com.fuhouyu.framework.cache.CacheAutoConfigure; import com.fuhouyu.framework.cache.CaffeineCacheAutoconfigure; +import com.fuhouyu.framework.kms.KmsAutoConfigure; import com.fuhouyu.framework.response.RestResult; import com.fuhouyu.framework.web.WebAutoConfigure; +import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.context.annotation.EnableAspectJAutoProxy; import org.springframework.test.context.TestPropertySource; -import org.springframework.util.Assert; /** *

@@ -36,6 +37,7 @@ * @since 2024/8/17 23:10 */ @SpringBootTest(classes = { + KmsAutoConfigure.class, WebAutoConfigure.class, CacheAutoConfigure.class, CaffeineCacheAutoconfigure.class, @@ -50,7 +52,7 @@ class WebFormNoRepeatSubmitTest { @Test void testNoRepeatSubmit() { RestResult restResult = formTokenController.success(); - Assert.isTrue(restResult.getData(), "表单防重复提交验证失败。"); + Assertions.assertTrue(restResult.getData(), "表单防重复提交验证失败。"); } }