From 8921c37da6e3277cc42fdf2debda39e5b1531719 Mon Sep 17 00:00:00 2001 From: "1437892690@qq.com" <1437892690@qq.com> Date: Wed, 16 Oct 2024 17:22:47 +0800 Subject: [PATCH] =?UTF-8?q?[=E5=8A=9F=E8=83=BD]=20=E5=90=8E=E7=AB=AF-?= =?UTF-8?q?=E8=A1=A8=E5=8D=95-=E5=AF=86=E7=A0=81=E6=8E=A7=E4=BB=B6?= =?UTF-8?q?=E6=9F=A5=E7=9C=8B=E5=8E=9F=E5=AF=86=E7=A0=81=E6=8E=88=E6=9D=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 关联 #[1268877969817600]后端-表单-密码控件查看原密码授权 http://192.168.0.96:8090/demo/rdm.html#/task-detail/939050947543040/939050947543050/1268877969817600 --- .../IFormAttributeDataConversionHandler.java | 10 ++ .../framework/form/dto/FormVersionVo.java | 5 + .../FormAttributeNotFoundException.java | 4 +- .../neatlogic/framework/util/FormUtil.java | 4 + .../attribute/handler/PasswordHandler.java | 11 ++ .../attribute/handler/SubassemblyHandler.java | 110 ++++++++++++++++++ .../handler/TableInputerHandler.java | 55 +++++++++ 7 files changed, 197 insertions(+), 2 deletions(-) diff --git a/src/main/java/neatlogic/framework/form/attribute/core/IFormAttributeDataConversionHandler.java b/src/main/java/neatlogic/framework/form/attribute/core/IFormAttributeDataConversionHandler.java index fbda551ea..47b479379 100644 --- a/src/main/java/neatlogic/framework/form/attribute/core/IFormAttributeDataConversionHandler.java +++ b/src/main/java/neatlogic/framework/form/attribute/core/IFormAttributeDataConversionHandler.java @@ -124,4 +124,14 @@ public interface IFormAttributeDataConversionHandler { return source; } + /** + * 密码解密 + * @param source 属性原始数据 + * @param configObj 属性配置信息 + * @return 返回解密后的数据 + */ + default String passwordDecryption(Object source, JSONObject configObj, String attributeUuid, JSONObject otherParamConfig) { + return null; + } + } diff --git a/src/main/java/neatlogic/framework/form/dto/FormVersionVo.java b/src/main/java/neatlogic/framework/form/dto/FormVersionVo.java index b5e61b037..0dfe88418 100644 --- a/src/main/java/neatlogic/framework/form/dto/FormVersionVo.java +++ b/src/main/java/neatlogic/framework/form/dto/FormVersionVo.java @@ -19,6 +19,7 @@ import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.annotation.JSONField; import neatlogic.framework.common.dto.BaseEditorVo; +import neatlogic.framework.form.constvalue.FormHandler; import neatlogic.framework.util.UuidUtil; import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.collections4.MapUtils; @@ -255,6 +256,10 @@ public class FormVersionVo extends BaseEditorVo { String label = componentObj.getString("label"); String type = componentObj.getString("type"); String handler = componentObj.getString("handler"); + if (Objects.equals(handler, FormHandler.FORMSUBASSEMBLY.getHandler())) { + JSONObject formData = componentObj.getJSONObject("formData"); + config.put("formData", formData); + } boolean isRequired = config.getBooleanValue("isRequired"); String defaultValue = config.getString("defaultValue"); return new FormAttributeVo(this.getFormUuid(), this.getUuid(), uuid, key, label, type, handler, isRequired, config, defaultValue); diff --git a/src/main/java/neatlogic/framework/form/exception/FormAttributeNotFoundException.java b/src/main/java/neatlogic/framework/form/exception/FormAttributeNotFoundException.java index 49e201e4c..2b1fc353d 100644 --- a/src/main/java/neatlogic/framework/form/exception/FormAttributeNotFoundException.java +++ b/src/main/java/neatlogic/framework/form/exception/FormAttributeNotFoundException.java @@ -22,10 +22,10 @@ public class FormAttributeNotFoundException extends ApiRuntimeException { private static final long serialVersionUID = -2778517020600259453L; public FormAttributeNotFoundException(String attributeUuid) { - super("表单属性:“{0}”不存在", attributeUuid); + super("nffe.formattributenotfoundexception.formattributenotfoundexception_a", attributeUuid); } public FormAttributeNotFoundException(String formName, String attributeUuid) { - super("表单”{0}“中找不到“{1}”属性", formName, attributeUuid); + super("nffe.formattributenotfoundexception.formattributenotfoundexception_b", formName, attributeUuid); } } diff --git a/src/main/java/neatlogic/framework/util/FormUtil.java b/src/main/java/neatlogic/framework/util/FormUtil.java index 6625fcab5..fb4c2cc5c 100644 --- a/src/main/java/neatlogic/framework/util/FormUtil.java +++ b/src/main/java/neatlogic/framework/util/FormUtil.java @@ -514,6 +514,10 @@ public class FormUtil { formAttributeVo.setType(type); JSONObject config = componentObj.getJSONObject("config"); if (MapUtils.isNotEmpty(config)) { + if (Objects.equals(handler, FormHandler.FORMSUBASSEMBLY.getHandler())) { + JSONObject formData = componentObj.getJSONObject("formData"); + config.put("formData", formData); + } boolean isRequired = config.getBooleanValue("isRequired"); formAttributeVo.setRequired(isRequired); String defaultValue = config.getString("defaultValue"); diff --git a/src/main/java/neatlogic/module/framework/form/attribute/handler/PasswordHandler.java b/src/main/java/neatlogic/module/framework/form/attribute/handler/PasswordHandler.java index b445d40e5..92b3b4148 100644 --- a/src/main/java/neatlogic/module/framework/form/attribute/handler/PasswordHandler.java +++ b/src/main/java/neatlogic/module/framework/form/attribute/handler/PasswordHandler.java @@ -162,4 +162,15 @@ public class PasswordHandler extends FormHandlerBase { } return source; } + + @Override + public String passwordDecryption(Object source, JSONObject configObj, String attributeUuid, JSONObject otherParamConfig) { + if (source == null) { + return null; + } + if (source instanceof String) { + return RC4Util.decrypt((String) source); + } + return null; + } } diff --git a/src/main/java/neatlogic/module/framework/form/attribute/handler/SubassemblyHandler.java b/src/main/java/neatlogic/module/framework/form/attribute/handler/SubassemblyHandler.java index a5e6f780b..b8cf55b83 100644 --- a/src/main/java/neatlogic/module/framework/form/attribute/handler/SubassemblyHandler.java +++ b/src/main/java/neatlogic/module/framework/form/attribute/handler/SubassemblyHandler.java @@ -1,15 +1,22 @@ package neatlogic.module.framework.form.attribute.handler; +import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; import neatlogic.framework.common.constvalue.ParamType; +import neatlogic.framework.form.attribute.core.FormAttributeDataConversionHandlerFactory; import neatlogic.framework.form.attribute.core.FormHandlerBase; +import neatlogic.framework.form.attribute.core.IFormAttributeDataConversionHandler; import neatlogic.framework.form.constvalue.FormConditionModel; import neatlogic.framework.form.constvalue.FormHandler; import neatlogic.framework.form.dto.AttributeDataVo; import neatlogic.framework.form.dto.FormAttributeVo; import neatlogic.framework.form.exception.AttributeValidException; +import org.apache.commons.collections4.CollectionUtils; +import org.apache.commons.collections4.MapUtils; import org.springframework.stereotype.Component; +import java.util.Objects; + @Component public class SubassemblyHandler extends FormHandlerBase { @Override @@ -95,4 +102,107 @@ public class SubassemblyHandler extends FormHandlerBase { public void makeupFormAttribute(FormAttributeVo formAttributeVo) { super.makeupFormAttribute(formAttributeVo); } + + @Override + public Object passwordEncryption(Object source, JSONObject configObj) { + JSONArray dataArray = null; + if (source instanceof JSONArray) { + dataArray = (JSONArray) source; + } + if (CollectionUtils.isEmpty(dataArray)) { + return source; + } + JSONObject formData = configObj.getJSONObject("formData"); + if (MapUtils.isNotEmpty(formData)) { + JSONObject formConfig = formData.getJSONObject("formConfig"); + if (MapUtils.isNotEmpty(formConfig)) { + JSONArray tableList = formConfig.getJSONArray("tableList"); + if (CollectionUtils.isNotEmpty(tableList)) { + for (int i = 0; i < tableList.size(); i++) { + JSONObject tableObj = tableList.getJSONObject(i); + if (MapUtils.isNotEmpty(tableObj)) { + JSONObject component = tableObj.getJSONObject("component"); + if (MapUtils.isNotEmpty(component)) { + String handler = component.getString("handler"); + if (Objects.equals(handler, FormHandler.FORMPASSWORD.getHandler()) + || Objects.equals(handler, FormHandler.FORMTABLEINPUTER.getHandler()) + || Objects.equals(handler, FormHandler.FORMSUBASSEMBLY.getHandler())) { + String uuid = component.getString("uuid"); + JSONObject config = component.getJSONObject("config"); + IFormAttributeDataConversionHandler formAttributeDataConversionHandler = FormAttributeDataConversionHandlerFactory.getHandler(handler); + if (Objects.equals(handler, FormHandler.FORMSUBASSEMBLY.getHandler())) { + JSONObject formData1 = component.getJSONObject("formData"); + config.put("formData", formData1); + } + for (int j = 0; j < dataArray.size(); j++) { + JSONObject dataObj = dataArray.getJSONObject(j); + if (MapUtils.isNotEmpty(dataObj)) { + Object data = dataObj.get(uuid); + if (data != null) { + dataObj.put(uuid, formAttributeDataConversionHandler.passwordEncryption(data, config)); + } + } + } + } + } + } + } + } + } + } + return dataArray; + } + + @Override + public String passwordDecryption(Object source, JSONObject configObj, String attributeUuid, JSONObject otherParamConfig) { + JSONArray dataArray = null; + if (source instanceof JSONArray) { + dataArray = (JSONArray) source; + } + if (CollectionUtils.isEmpty(dataArray)) { + return null; + } + JSONObject formData = configObj.getJSONObject("formData"); + if (MapUtils.isNotEmpty(formData)) { + JSONObject formConfig = formData.getJSONObject("formConfig"); + if (MapUtils.isNotEmpty(formConfig)) { + JSONArray tableList = formConfig.getJSONArray("tableList"); + if (CollectionUtils.isNotEmpty(tableList)) { + for (int i = 0; i < tableList.size(); i++) { + JSONObject tableObj = tableList.getJSONObject(i); + if (MapUtils.isNotEmpty(tableObj)) { + JSONObject component = tableObj.getJSONObject("component"); + if (MapUtils.isNotEmpty(component)) { + String handler = component.getString("handler"); + if (Objects.equals(handler, FormHandler.FORMPASSWORD.getHandler()) + || Objects.equals(handler, FormHandler.FORMTABLEINPUTER.getHandler()) + || Objects.equals(handler, FormHandler.FORMSUBASSEMBLY.getHandler())) { + String uuid = component.getString("uuid"); + JSONObject config = component.getJSONObject("config"); + IFormAttributeDataConversionHandler formAttributeDataConversionHandler = FormAttributeDataConversionHandlerFactory.getHandler(handler); + if (Objects.equals(handler, FormHandler.FORMSUBASSEMBLY.getHandler())) { + JSONObject formData1 = component.getJSONObject("formData"); + config.put("formData", formData1); + } + for (int j = 0; j < dataArray.size(); j++) { + JSONObject dataObj = dataArray.getJSONObject(j); + if (MapUtils.isNotEmpty(dataObj)) { + Object data = dataObj.get(uuid); + if (data != null) { + String result = formAttributeDataConversionHandler.passwordDecryption(data, config, attributeUuid, otherParamConfig); + if (result != null) { + return result; + } + } + } + } + } + } + } + } + } + } + } + return null; + } } diff --git a/src/main/java/neatlogic/module/framework/form/attribute/handler/TableInputerHandler.java b/src/main/java/neatlogic/module/framework/form/attribute/handler/TableInputerHandler.java index f5eff8e91..ad0b25b4d 100644 --- a/src/main/java/neatlogic/module/framework/form/attribute/handler/TableInputerHandler.java +++ b/src/main/java/neatlogic/module/framework/form/attribute/handler/TableInputerHandler.java @@ -898,4 +898,59 @@ public class TableInputerHandler extends FormHandlerBase { } return dataArray; } + + @Override + public String passwordDecryption(Object source, JSONObject configObj, String attributeUuid, JSONObject otherParamConfig) { + JSONArray dataArray = null; + if (source instanceof JSONArray) { + dataArray = (JSONArray) source; + } + if (CollectionUtils.isEmpty(dataArray)) { + return null; + } + String rowUuid = otherParamConfig.getString("rowUuid"); + JSONArray dataConfig = configObj.getJSONArray("dataConfig"); + if (CollectionUtils.isNotEmpty(dataConfig)) { + for (int i = 0; i < dataConfig.size(); i++) { + JSONObject attr = dataConfig.getJSONObject(i); + String handler = attr.getString("handler"); + if (Objects.equals(handler, FormHandler.FORMPASSWORD.getHandler())) { + String uuid = attr.getString("uuid"); + if (Objects.equals(uuid, attributeUuid)) { + for (int j = 0; j < dataArray.size(); j++) { + JSONObject dataObj = dataArray.getJSONObject(j); + if (MapUtils.isNotEmpty(dataObj)) { + if (Objects.equals(dataObj.getString("uuid"), rowUuid)) { + String data = dataObj.getString(uuid); + if (StringUtils.isNotBlank(data)) { +// dataObj.put(uuid, RC4Util.encrypt(data)); + return RC4Util.decrypt(data); + } + } + } + } + } + } else if (Objects.equals(handler, "formtable")) { + JSONObject config = attr.getJSONObject("config"); + if (MapUtils.isEmpty(config)) { + continue; + } + String uuid = attr.getString("uuid"); + for (int j = 0; j < dataArray.size(); j++) { + JSONObject dataObj = dataArray.getJSONObject(j); + if (MapUtils.isNotEmpty(dataObj)) { + JSONArray data = dataObj.getJSONArray(uuid); + if (CollectionUtils.isNotEmpty(data)) { + String result = this.passwordDecryption(data, config, attributeUuid, otherParamConfig); + if (result != null) { + return result; + } + } + } + } + } + } + } + return null; + } } -- Gitee