use of org.sagacity.sqltoy.config.annotation.Secure in project sagacity-sqltoy by chenrenfei.
the class EntityManager method parseSecureConfig.
/**
* @todo 解析加解密配置
* @param entityMeta
* @param entityClass
*/
private void parseSecureConfig(EntityMeta entityMeta, Class entityClass) {
Class classType = entityClass;
SecureConfig secureConfig = null;
// 增加递归对父类检测
while (classType != null && !classType.equals(Object.class)) {
secureConfig = (SecureConfig) classType.getAnnotation(SecureConfig.class);
if (secureConfig != null) {
break;
}
classType = classType.getSuperclass();
}
// 不存在加解密配置
if (secureConfig == null) {
return;
}
Secure[] secures = secureConfig.secures();
if (secures != null && secures.length > 0) {
IgnoreCaseSet secureColumns = new IgnoreCaseSet();
String field;
FieldMeta fieldMeta;
for (Secure secure : secures) {
field = secure.field();
fieldMeta = entityMeta.getFieldMeta(field);
if (fieldMeta != null) {
// 加密
if (secure.secureType().equals(SecureType.ENCRYPT)) {
secureColumns.add(fieldMeta.getColumnName());
entityMeta.addSecureField(new FieldSecureConfig(field, SecureType.ENCRYPT, null, null, 0, 0, 0));
} else {
// 依据加密字段进行脱敏保存
entityMeta.addSecureField(new FieldSecureConfig(field, secure.secureType(), secure.sourceField(), secure.maskCode(), secure.headSize(), secure.tailSize(), secure.maskRate()));
}
}
}
// 加密字段
if (!secureColumns.isEmpty()) {
entityMeta.setSecureColumns(secureColumns);
}
}
}
Aggregations