|
|
@ -120,6 +120,36 @@ public class ApiCryptoAsymmetricAop {
|
|
|
|
// 1. 拆解请求数据
|
|
|
|
// 1. 拆解请求数据
|
|
|
|
// request 解密
|
|
|
|
// request 解密
|
|
|
|
if (annotation.enable() && annotation.requestDecrypt()){
|
|
|
|
if (annotation.enable() && annotation.requestDecrypt()){
|
|
|
|
|
|
|
|
enterDecrypt(args, method, asymmetric, cryptoModel);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 2. 执行方法
|
|
|
|
|
|
|
|
returnValue = point.proceed(args);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 3. 返回响应数据
|
|
|
|
|
|
|
|
// response 加密
|
|
|
|
|
|
|
|
if (annotation.enable() && annotation.responseEncrypt()){
|
|
|
|
|
|
|
|
returnValue = resultEncrypt(returnValue, asymmetric, cryptoModel);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return returnValue;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}else{
|
|
|
|
|
|
|
|
returnValue = point.proceed(args);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return returnValue;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* 入参解密
|
|
|
|
|
|
|
|
* @param args 入参(集合)
|
|
|
|
|
|
|
|
* @param method 方法
|
|
|
|
|
|
|
|
* @param asymmetric 非对称加解密执行器
|
|
|
|
|
|
|
|
* @param cryptoModel 非对称加解密模型
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
private void enterDecrypt(Object[] args, Method method, CryptoAsymmetricService asymmetric, CryptoAsymmetric cryptoModel) {
|
|
|
|
for (int i = 0; i < args.length; i++) {
|
|
|
|
for (int i = 0; i < args.length; i++) {
|
|
|
|
Object arg = args[i];
|
|
|
|
Object arg = args[i];
|
|
|
|
// 参数校验
|
|
|
|
// 参数校验
|
|
|
@ -152,16 +182,20 @@ public class ApiCryptoAsymmetricAop {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 2. 执行方法
|
|
|
|
|
|
|
|
returnValue = point.proceed(args);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 3. 返回响应数据
|
|
|
|
/**
|
|
|
|
// response 加密
|
|
|
|
* 出参加密
|
|
|
|
if (annotation.enable() && annotation.responseEncrypt()){
|
|
|
|
* @param returnValue 出参(对象)
|
|
|
|
|
|
|
|
* @param asymmetric 非对称加解密执行器
|
|
|
|
|
|
|
|
* @param cryptoModel 非对称加解密模型
|
|
|
|
|
|
|
|
* @return Object
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
private Object resultEncrypt(Object returnValue, CryptoAsymmetricService asymmetric, CryptoAsymmetric cryptoModel) {
|
|
|
|
if(returnValue != null){
|
|
|
|
if(returnValue != null){
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
// 执行加密过程
|
|
|
|
// 执行加密过程
|
|
|
|
if(returnValue instanceof ResultVo){
|
|
|
|
if(returnValue instanceof ResultVo){
|
|
|
|
|
|
|
|
// 重新赋值 data
|
|
|
|
ResultVo<Object> ret = (ResultVo<Object>) returnValue;
|
|
|
|
ResultVo<Object> ret = (ResultVo<Object>) returnValue;
|
|
|
|
ret.setData(
|
|
|
|
ret.setData(
|
|
|
|
asymmetric.encrypt(cryptoModel, ret.getData())
|
|
|
|
asymmetric.encrypt(cryptoModel, ret.getData())
|
|
|
@ -176,16 +210,7 @@ public class ApiCryptoAsymmetricAop {
|
|
|
|
throw new ServiceException(CoreMsg.OTHER_EXCEPTION_CRYPTO_EN);
|
|
|
|
throw new ServiceException(CoreMsg.OTHER_EXCEPTION_CRYPTO_EN);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return returnValue;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}else{
|
|
|
|
|
|
|
|
returnValue = point.proceed(args);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return returnValue;
|
|
|
|
return returnValue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// ===============================
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|