update 优化 !pr451 改进代码逻辑 支持注解强制加密接口数据

This commit is contained in:
疯狂的狮子Li
2023-11-27 11:14:16 +08:00
parent c45ffaec0f
commit b0faebc5e6
8 changed files with 14 additions and 23 deletions

View File

@ -37,16 +37,9 @@
<artifactId>hutool-crypto</artifactId>
</dependency>
<!-- SpringBoot Web容器 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<exclusions>
<exclusion>
<artifactId>spring-boot-starter-tomcat</artifactId>
<groupId>org.springframework.boot</groupId>
</exclusion>
</exclusions>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
</dependency>
</dependencies>

View File

@ -13,8 +13,8 @@ import java.lang.annotation.*;
public @interface ApiEncrypt {
/**
* 响应加密忽略,默认加密,为 false 时加密
* 响应加密忽略,默认加密,为 true 时加密
*/
boolean response() default true;
boolean response() default false;
}

View File

@ -58,7 +58,7 @@ public class CryptoFilter implements Filter {
encryptFlag = apiEncrypt.response();
} else {
// 是否有注解,有就报错,没有放行
HandlerExceptionResolver exceptionResolver = SpringUtils.getBean("handlerExceptionResolver");
HandlerExceptionResolver exceptionResolver = SpringUtils.getBean(HandlerExceptionResolver.class);
exceptionResolver.resolveException(
servletRequest, servletResponse, null,
new ServiceException("没有访问权限,请联系管理员授权", HttpStatus.FORBIDDEN));

View File

@ -70,7 +70,6 @@ public class EncryptResponseBodyWrapper extends HttpServletResponseWrapper {
public String getEncryptContent(HttpServletResponse servletResponse, String publicKey, String headerFlag) throws IOException {
// 生成秘钥
String aesPassword = RandomUtil.randomString(32);
System.out.println("aesPassword = " + aesPassword);
// 秘钥使用 Base64 编码
String encryptAes = EncryptUtils.encryptByBase64(aesPassword);
// Rsa 公钥加密 Base64 编码