mirror of
https://gitee.com/dromara/RuoYi-Vue-Plus.git
synced 2026-04-11 21:13:16 +08:00
update 优化 翻译处理器 避免多次序列化 实现类增加缓存避免重复解析
This commit is contained in:
@@ -2,13 +2,12 @@ package org.dromara.common.sensitive.handler;
|
||||
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.dromara.common.core.utils.SpringUtils;
|
||||
import org.dromara.common.json.enhance.JsonEnhancementContext;
|
||||
import org.dromara.common.json.enhance.JsonFieldContext;
|
||||
import org.dromara.common.json.enhance.JsonFieldProcessor;
|
||||
import org.dromara.common.sensitive.annotation.Sensitive;
|
||||
import org.dromara.common.sensitive.core.SensitiveService;
|
||||
import org.springframework.beans.BeansException;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.core.annotation.Order;
|
||||
|
||||
/**
|
||||
@@ -18,22 +17,19 @@ import org.springframework.core.annotation.Order;
|
||||
@Order(100)
|
||||
public class SensitiveJsonFieldProcessor implements JsonFieldProcessor {
|
||||
|
||||
@Autowired(required = false)
|
||||
private SensitiveService sensitiveService;
|
||||
|
||||
@Override
|
||||
public Object process(JsonFieldContext fieldContext, Object value, JsonEnhancementContext context) {
|
||||
Sensitive sensitive = fieldContext.getAnnotation(Sensitive.class);
|
||||
if (sensitive == null || !(value instanceof String text)) {
|
||||
return value;
|
||||
}
|
||||
try {
|
||||
SensitiveService sensitiveService = SpringUtils.getBean(SensitiveService.class);
|
||||
if (ObjectUtil.isNotNull(sensitiveService) && sensitiveService.isSensitive(sensitive.roleKey(), sensitive.perms())) {
|
||||
return sensitive.strategy().desensitizer().apply(text);
|
||||
}
|
||||
return text;
|
||||
} catch (BeansException e) {
|
||||
log.error("脱敏实现不存在, 采用默认处理 => {}", e.getMessage());
|
||||
return text;
|
||||
if (ObjectUtil.isNotNull(sensitiveService) && sensitiveService.isSensitive(sensitive.roleKey(), sensitive.perms())) {
|
||||
return sensitive.strategy().desensitizer().apply(text);
|
||||
}
|
||||
return text;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user