第二次修改
This commit is contained in:
parent
23c53ee068
commit
d040250343
|
|
@ -0,0 +1,13 @@
|
||||||
|
package com.bonus.nxdt.energy.manager.config.aes;
|
||||||
|
|
||||||
|
import java.lang.annotation.ElementType;
|
||||||
|
import java.lang.annotation.Retention;
|
||||||
|
import java.lang.annotation.RetentionPolicy;
|
||||||
|
import java.lang.annotation.Target;
|
||||||
|
|
||||||
|
@Target(ElementType.METHOD)
|
||||||
|
@Retention(RetentionPolicy.RUNTIME)
|
||||||
|
public @interface DecryptAndVerify {
|
||||||
|
/** 解密后的参数类型 */
|
||||||
|
Class<?> decryptedClass();
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,50 @@
|
||||||
|
package com.bonus.nxdt.energy.manager.config.aes;
|
||||||
|
|
||||||
|
import com.alibaba.fastjson.JSON;
|
||||||
|
import com.bonus.nxdt.energy.manager.utils.AesCbcUtils;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.aspectj.lang.ProceedingJoinPoint;
|
||||||
|
import org.aspectj.lang.annotation.Around;
|
||||||
|
import org.aspectj.lang.annotation.Aspect;
|
||||||
|
import org.aspectj.lang.annotation.Pointcut;
|
||||||
|
import org.aspectj.lang.reflect.MethodSignature;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
|
||||||
|
@Slf4j
|
||||||
|
@Aspect
|
||||||
|
@Component
|
||||||
|
public class DecryptAndVerifyAspect {
|
||||||
|
@Pointcut("@annotation(com.bonus.nxdt.energy.manager.config.aes.DecryptAndVerify)")
|
||||||
|
public void pointCut() {}
|
||||||
|
@Around("pointCut()")
|
||||||
|
public Object around(ProceedingJoinPoint joinPoint) throws Throwable {
|
||||||
|
Object[] args = joinPoint.getArgs();
|
||||||
|
if (args == null || args.length == 0) {
|
||||||
|
throw new DecryptAndVerifyException(joinPoint.getSignature().getName() + ",参数为空");
|
||||||
|
}
|
||||||
|
EncryptedReq encryptedReq = null;
|
||||||
|
for (Object obj : args) {
|
||||||
|
if (obj instanceof EncryptedReq) {
|
||||||
|
encryptedReq = (EncryptedReq) obj;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (encryptedReq == null) {
|
||||||
|
// throw new DecryptAndVerifyException(joinPoint.getSignature().getName() + ",参数中无待解密类");
|
||||||
|
}
|
||||||
|
String decryptedData = decryptAndVerify(encryptedReq);
|
||||||
|
MethodSignature methodSignature = (MethodSignature) joinPoint.getSignature();
|
||||||
|
DecryptAndVerify annotation = methodSignature.getMethod().getAnnotation(DecryptAndVerify.class);
|
||||||
|
if (annotation == null || annotation.decryptedClass() == null) {
|
||||||
|
throw new DecryptAndVerifyException(joinPoint.getSignature().getName() + ",未指定解密类型");
|
||||||
|
}
|
||||||
|
encryptedReq.setData(JSON.parseObject(decryptedData, annotation.decryptedClass()));
|
||||||
|
return joinPoint.proceed();
|
||||||
|
}
|
||||||
|
|
||||||
|
private String decryptAndVerify(EncryptedReq encryptedReq) {
|
||||||
|
return AesCbcUtils.decrypt(encryptedReq.getEncryptedData());
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,9 @@
|
||||||
|
package com.bonus.nxdt.energy.manager.config.aes;
|
||||||
|
|
||||||
|
public class DecryptAndVerifyException extends RuntimeException {
|
||||||
|
|
||||||
|
public DecryptAndVerifyException(String message) {
|
||||||
|
super(message);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,19 @@
|
||||||
|
package com.bonus.nxdt.energy.manager.config.aes;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class EncryptedReq<T> {
|
||||||
|
/** 签名 */
|
||||||
|
|
||||||
|
private String sign;
|
||||||
|
/** 加密请求数据 */
|
||||||
|
|
||||||
|
private String encryptedData;
|
||||||
|
/** 原始请求数据(解密后回填到对象) */
|
||||||
|
private T data;
|
||||||
|
/** 请求的时间戳 */
|
||||||
|
|
||||||
|
private Long timestamp;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
@ -8,17 +8,13 @@ import com.bonus.nxdt.energy.GetResponsibleFor.service.GetResponsibleForService;
|
||||||
import com.bonus.nxdt.energy.constrator.entity.*;
|
import com.bonus.nxdt.energy.constrator.entity.*;
|
||||||
import com.bonus.nxdt.energy.manager.config.MessageSender;
|
import com.bonus.nxdt.energy.manager.config.MessageSender;
|
||||||
import com.bonus.nxdt.energy.manager.config.RabbitMQConfig;
|
import com.bonus.nxdt.energy.manager.config.RabbitMQConfig;
|
||||||
|
import com.bonus.nxdt.energy.manager.config.aes.DecryptAndVerify;
|
||||||
|
import com.bonus.nxdt.energy.manager.config.aes.EncryptedReq;
|
||||||
import com.bonus.nxdt.energy.manager.table.PageTableHandler;
|
import com.bonus.nxdt.energy.manager.table.PageTableHandler;
|
||||||
import com.bonus.nxdt.energy.manager.table.PageTableRequest;
|
import com.bonus.nxdt.energy.manager.table.PageTableRequest;
|
||||||
import com.bonus.nxdt.energy.manager.table.PageTableResponse;
|
import com.bonus.nxdt.energy.manager.table.PageTableResponse;
|
||||||
import com.bonus.nxdt.energy.manager.utils.AjaxRes;
|
import com.bonus.nxdt.energy.manager.utils.*;
|
||||||
import com.bonus.nxdt.energy.manager.utils.DateTimeHelper;
|
import com.bonus.nxdt.energy.material.entity.*;
|
||||||
import com.bonus.nxdt.energy.manager.utils.GlobalConst;
|
|
||||||
import com.bonus.nxdt.energy.manager.utils.StringHelper;
|
|
||||||
import com.bonus.nxdt.energy.material.entity.FileUpBean;
|
|
||||||
import com.bonus.nxdt.energy.material.entity.HistoryBean;
|
|
||||||
import com.bonus.nxdt.energy.material.entity.MaterialBean;
|
|
||||||
import com.bonus.nxdt.energy.material.entity.PersonBean;
|
|
||||||
import com.bonus.nxdt.energy.material.service.MaterialUploadService;
|
import com.bonus.nxdt.energy.material.service.MaterialUploadService;
|
||||||
import com.bonus.nxdt.energy.newSubApply.dao.NewsConsDao;
|
import com.bonus.nxdt.energy.newSubApply.dao.NewsConsDao;
|
||||||
import com.bonus.nxdt.energy.newSubApply.entity.SubEntranceBean;
|
import com.bonus.nxdt.energy.newSubApply.entity.SubEntranceBean;
|
||||||
|
|
@ -67,6 +63,25 @@ public class MaterialUploadController {
|
||||||
private MessageSender messageSender;
|
private MessageSender messageSender;
|
||||||
|
|
||||||
|
|
||||||
|
// @SupportFieldEncrypt
|
||||||
|
@GetMapping("/encrypt")
|
||||||
|
public FieldAopDemo encrypt(FieldAopDemo demo){
|
||||||
|
System.out.println(demo);
|
||||||
|
String ss = AesCbcUtils.encrypt("{\"name\":\"hellow\",\"id\":\"hellow\",\"sex\":\"hellow\"}");
|
||||||
|
System.out.println("22"+ss);
|
||||||
|
return demo;
|
||||||
|
}
|
||||||
|
|
||||||
|
@DecryptAndVerify(decryptedClass = FieldAopDemo.class)//加解密统一管理
|
||||||
|
@GetMapping("/decrypt")
|
||||||
|
public FieldAopDemo decrypt(EncryptedReq<FieldAopDemo> demo){
|
||||||
|
System.out.println("11"+demo);
|
||||||
|
// String name = demo.getName();
|
||||||
|
// String encrypt = AesCbcUtils.decrypt(name);
|
||||||
|
// System.out.println(encrypt);
|
||||||
|
// demo.setName(encrypt);
|
||||||
|
return demo.getData();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 测试
|
* 测试
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,16 @@
|
||||||
|
package com.bonus.nxdt.energy.material.entity;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author xliu
|
||||||
|
* @date 2024/6/11 11:21
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
public class FieldAopDemo {
|
||||||
|
private String name;
|
||||||
|
|
||||||
|
private String id;
|
||||||
|
|
||||||
|
private String sex;
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue