|
@@ -2,6 +2,7 @@ package com.diagbot.aop;
|
|
|
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
+import com.diagbot.client.bean.Response;
|
|
|
import com.diagbot.dto.RespDTO;
|
|
|
import com.diagbot.util.CryptPojoUtils;
|
|
|
import com.diagbot.util.RespDTOUtil;
|
|
@@ -22,19 +23,20 @@ import org.springframework.context.annotation.Configuration;
|
|
|
@Configuration
|
|
|
public class CryptAspect {
|
|
|
|
|
|
- //切所有mapper
|
|
|
+ //切所有Controller
|
|
|
@Pointcut("execution(* com.diagbot.web..*.*(..))")
|
|
|
- public void pointcut() {
|
|
|
+ public void pointcutController() {
|
|
|
}
|
|
|
|
|
|
- @Around("pointcut()")
|
|
|
- public Object aroundReturning(ProceedingJoinPoint joinPoint) throws Throwable {
|
|
|
+ //Controller 入参加密出参解密
|
|
|
+ @Around("pointcutController()")
|
|
|
+ public Object aroundReturningController(ProceedingJoinPoint joinPoint) throws Throwable {
|
|
|
//获取方法参数
|
|
|
Object[] args = joinPoint.getArgs();
|
|
|
|
|
|
- //获取参数实体类注解
|
|
|
+ //获取参数实体类注解加密
|
|
|
CryptPojoUtils.encryptFields(args);
|
|
|
- //执行方法
|
|
|
+ //执行方法后获取出参
|
|
|
Object proceed = joinPoint.proceed(args);
|
|
|
if (null == proceed) {
|
|
|
return null;
|
|
@@ -54,6 +56,47 @@ public class CryptAspect {
|
|
|
|
|
|
}
|
|
|
|
|
|
+ return proceed;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ @Pointcut("execution(* com.diagbot.client..*.*(..))")
|
|
|
+ public void pointcutRpcClient() {
|
|
|
+ }
|
|
|
+
|
|
|
+ //RpcClient 入参解密出参加密
|
|
|
+ @Around("pointcutRpcClient()")
|
|
|
+ public Object aroundReturningRpcClient(ProceedingJoinPoint joinPoint) throws Throwable {
|
|
|
+ //获取方法参数
|
|
|
+ Object[] args = joinPoint.getArgs();
|
|
|
+
|
|
|
+ //获取参数实体类解密
|
|
|
+ CryptPojoUtils.decryptFields(args);
|
|
|
+ //执行方法后获取出参
|
|
|
+ Object proceed = joinPoint.proceed(args);
|
|
|
+ if (null == proceed) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ //加密
|
|
|
+ if (proceed instanceof RespDTO) {
|
|
|
+ RespDTO respDTO = (RespDTO) proceed;
|
|
|
+ if (RespDTOUtil.respIsOK(respDTO)) {
|
|
|
+ if (respDTO.data instanceof IPage) {
|
|
|
+ Page page = (Page) respDTO.data;
|
|
|
+ CryptPojoUtils.encryptFieldOrList(page.getRecords());
|
|
|
+ } else {
|
|
|
+ CryptPojoUtils.encryptFieldOrList(respDTO.data);
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ } else if (proceed instanceof Response) {
|
|
|
+ Response response = (Response) proceed;
|
|
|
+ if (null != response && null != response.getData()) {
|
|
|
+ CryptPojoUtils.encryptFieldOrList(response.getData());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
return proceed;
|
|
|
}
|
|
|
}
|