提交 8a860112 authored 作者:  狄熙卜's avatar 狄熙卜

单独string作为参数和单独string作为返回值的加解密(原注解方式),支持通过配置实现

上级 d76905dd
......@@ -35,6 +35,10 @@ public class CryptProperties {
private List<Map> sqlDecryptFileds;
//实体加解密字段
private List<Map> entityFileds;
//sql参数为单独的string,对参数加密(等价于注解)
private List<String> sqlSingleEncryptFileds;
//sql返回值为单独的string,对返回值加密(等价于注解)
private List<String> sqlSingleDecryptFileds;
public CryptProperties(boolean cryptEnable) {
this.cryptEnable = cryptEnable;
}
......@@ -43,6 +47,22 @@ public class CryptProperties {
this.cryptType = cryptType;
}
public List<String> getSqlSingleEncryptFileds() {
return sqlSingleEncryptFileds;
}
public void setSqlSingleEncryptFileds(List<String> sqlSingleEncryptFileds) {
this.sqlSingleEncryptFileds = sqlSingleEncryptFileds;
}
public List<String> getSqlSingleDecryptFileds() {
return sqlSingleDecryptFileds;
}
public void setSqlSingleDecryptFileds(List<String> sqlSingleDecryptFileds) {
this.sqlSingleDecryptFileds = sqlSingleDecryptFileds;
}
public boolean isUserSm4KeyEnable() {
return isUserSm4KeyEnable;
}
......
......@@ -40,6 +40,10 @@ public class DbEncryptXmlConfig {
private List<Map> sqlDecryptFileds;
//实体加解密字段
private List<Map> entityFileds;
//sql参数为单独的string,对参数加密(等价于注解)
private List<String> sqlSingleEncryptFileds;
//sql返回值为单独的string,对返回值加密(等价于注解)
private List<String> sqlSingleDecryptFileds;
//接口加解密列表
private List<String> interfaceEncryptList;
private String interfaceSm2DecodeKey;//接口加解密时,sm2解密的私钥
......@@ -79,6 +83,22 @@ public class DbEncryptXmlConfig {
return list;
}
}
public List<String> getSqlSingleEncryptFileds(){
if(CollectionUtils.isNotEmpty(this.sqlSingleEncryptFileds)){
return this.sqlSingleEncryptFileds;
}else{
this.sqlSingleEncryptFileds = getArrFields("SqlSingleEncryptFileds");
return this.sqlSingleEncryptFileds;
}
}
public List<String> getSqlSingleDecryptFileds(){
if(CollectionUtils.isNotEmpty(this.sqlSingleDecryptFileds)){
return this.sqlSingleDecryptFileds;
}else{
this.sqlSingleDecryptFileds = getArrFields("SqlSingleDecryptFileds");
return this.sqlSingleDecryptFileds;
}
}
public void setConfigUrl(Resource configUrl) {
this.configUrl = configUrl;
......
......@@ -11,7 +11,9 @@ import cn.gtmap.bdcdj.core.encrypt.adapter.encrypt.EmptyEncryptAdapter;
import cn.gtmap.bdcdj.core.encrypt.adapter.encrypt.EncryptAdapter;
import cn.gtmap.bdcdj.core.encrypt.adapter.encrypt.SimpleEncryptAdapter;
import cn.gtmap.bdcdj.core.encrypt.annotation.EncryptField;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.ArrayUtils;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
......@@ -120,6 +122,14 @@ public class EncryptAdapterBuilder {
}
}
}
if(CollectionUtils.isNotEmpty(cryptProperties.getSqlSingleEncryptFileds())){
for (String filed : cryptProperties.getSqlSingleEncryptFileds()) {
String name = method.getName();
if(StringUtils.isNotBlank(name) && name.endsWith(filed)){
return true;
}
}
}
return false;
}
}
......@@ -153,6 +163,17 @@ public class EncryptAdapterBuilder {
private boolean hasMethodEnctyptAnnotation(Method method){
EncryptField annotation = method.getAnnotation(EncryptField.class);
return annotation != null;
if(annotation != null){
return true;
}
if(CollectionUtils.isNotEmpty(cryptProperties.getSqlSingleDecryptFileds())){
for (String filed : cryptProperties.getSqlSingleDecryptFileds()) {
String name = method.getName();
if(StringUtils.isNotBlank(name) && name.endsWith(filed)){
return true;
}
}
}
return false;
}
}
......@@ -114,6 +114,8 @@ public class EncryptInterceptor implements Interceptor {
dbEncryptXmlConfig.getSqlEncryptFileds();
dbEncryptXmlConfig.getSqlDecryptFileds();
dbEncryptXmlConfig.getEntityFileds();
dbEncryptXmlConfig.getSqlSingleEncryptFileds();
dbEncryptXmlConfig.getSqlSingleDecryptFileds();
//添加预置的字段
dbEncryptXmlConfig.setBaseConfigFileds();
this.cryptProperties.setGlobalEnableFields(dbEncryptXmlConfig.getGlobalEnableFields());
......@@ -123,5 +125,7 @@ public class EncryptInterceptor implements Interceptor {
this.cryptProperties.setSqlEncryptFileds(dbEncryptXmlConfig.getSqlEncryptFileds());
this.cryptProperties.setSqlDecryptFileds(dbEncryptXmlConfig.getSqlDecryptFileds());
this.cryptProperties.setEntityFileds(dbEncryptXmlConfig.getEntityFileds());
this.cryptProperties.setSqlSingleEncryptFileds(dbEncryptXmlConfig.getSqlSingleEncryptFileds());
this.cryptProperties.setSqlSingleDecryptFileds(dbEncryptXmlConfig.getSqlSingleDecryptFileds());
}
}
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论