refactor(data): 移除 AesEncryptionUtil 中的测试代码并添加新的测试接口

- 删除了 AesEncryptionUtil 类中的 main 方法及其内容
- 新增了 TestController 和 TestDto 类用于测试加密解密功能
- 优化了 EncryptionMapping 注解的文档注释
- 调整了 EncryptionRequestFilter 类的代码格式
dev
liujun 2025-06-26 16:30:28 +08:00
parent 4bee366007
commit e92653959e
5 changed files with 33 additions and 11 deletions

View File

@ -41,12 +41,4 @@ public class AesEncryptionUtil {
byte[] decrypted = cipher.doFinal(decodedBytes); byte[] decrypted = cipher.doFinal(decodedBytes);
return new String(decrypted, StandardCharsets.UTF_8); return new String(decrypted, StandardCharsets.UTF_8);
} }
public static void main(String[] args) throws Exception {
TestDto dto = new TestDto();
dto.setId("1");
String message = AesEncryptionUtil.encrypt(SECRET_KEY, JSONObject.toJSONString(dto));
System.out.println(message);
System.out.println(AesEncryptionUtil.decrypt(SECRET_KEY,message));
}
} }

View File

@ -8,6 +8,10 @@ import java.lang.annotation.*;
/** /**
* *
*
* @author liu jun
*
* @version 0.1
*/ */
@Target(ElementType.METHOD) @Target(ElementType.METHOD)
@Retention(RetentionPolicy.RUNTIME) @Retention(RetentionPolicy.RUNTIME)

View File

@ -19,9 +19,7 @@ public class EncryptionRequestFilter extends OncePerRequestFilter {
@Override @Override
protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws ServletException, IOException {
throws ServletException, IOException {
try { try {
// 手动设置路径信息避免Spring 2.7+路径丢失问题 // 手动设置路径信息避免Spring 2.7+路径丢失问题
ServletRequestPathUtils.parseAndCache(request); ServletRequestPathUtils.parseAndCache(request);

View File

@ -0,0 +1,20 @@
package com.zcloud.modules.data.controller.test;
import com.alibaba.fastjson.JSONObject;
import com.zcloud.modules.data.aop.EncryptionMapping;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@Slf4j
@RestController
@RequestMapping("/data")
public class TestController {
@EncryptionMapping("/test")
public String test(@RequestBody TestDto dto) {
System.out.println(JSONObject.toJSONString(dto));
return "test";
}
}

View File

@ -0,0 +1,8 @@
package com.zcloud.modules.data.controller.test;
import lombok.Data;
@Data
public class TestDto {
private String id;
}