Skip to content

Commit

Permalink
Merge branch 'feature/1.0.0' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
fuhouyu committed Oct 8, 2024
2 parents ac7518f + fb630c5 commit ac274e2
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -44,8 +42,6 @@
*/
public class DefaultKmsServiceImpl implements KmsService {

private static final Logger LOGGER = LoggerFactory.getLogger(DefaultKmsServiceImpl.class);

/**
* 非对称加密
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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 {


/**
Expand All @@ -53,4 +54,8 @@ public HttpBodyFilter httpBodyFilter(KmsService kmsService) {
return new DefaultHttpBodyFilter(kmsService);
}

@Override
public void afterPropertiesSet() throws Exception {
System.out.println();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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 {
Expand All @@ -46,5 +49,6 @@ class WebHandlerTest {
void testAutoConfigure() {
InterceptorRegistry interceptorRegistry = new InterceptorRegistry();
webMvcAutoConfigure.addInterceptors(interceptorRegistry);
Assertions.assertNotNull(webMvcAutoConfigure);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;

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

Expand Down

0 comments on commit ac274e2

Please sign in to comment.