refactor(data): 移除 AesEncryptionUtil 中的测试代码并添加新的测试接口
- 删除了 AesEncryptionUtil 类中的 main 方法及其内容 - 新增了 TestController 和 TestDto 类用于测试加密解密功能 - 优化了 EncryptionMapping 注解的文档注释 - 调整了 EncryptionRequestFilter 类的代码格式dev
parent
4bee366007
commit
e92653959e
|
@ -41,12 +41,4 @@ public class AesEncryptionUtil {
|
|||
byte[] decrypted = cipher.doFinal(decodedBytes);
|
||||
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));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,6 +8,10 @@ import java.lang.annotation.*;
|
|||
|
||||
/**
|
||||
* 用于加解密的接口注解
|
||||
*
|
||||
* @author liu jun
|
||||
*
|
||||
* @version 0.1
|
||||
*/
|
||||
@Target(ElementType.METHOD)
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
|
|
|
@ -19,9 +19,7 @@ public class EncryptionRequestFilter extends OncePerRequestFilter {
|
|||
|
||||
|
||||
@Override
|
||||
protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain)
|
||||
throws ServletException, IOException {
|
||||
|
||||
protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws ServletException, IOException {
|
||||
try {
|
||||
// 手动设置路径信息避免Spring 2.7+路径丢失问题
|
||||
ServletRequestPathUtils.parseAndCache(request);
|
||||
|
|
|
@ -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";
|
||||
}
|
||||
}
|
|
@ -0,0 +1,8 @@
|
|||
package com.zcloud.modules.data.controller.test;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class TestDto {
|
||||
private String id;
|
||||
}
|
Loading…
Reference in New Issue