diff --git a/src/main/java/neatlogic/framework/form/attribute/core/FormHandlerBase.java b/src/main/java/neatlogic/framework/form/attribute/core/FormHandlerBase.java index 72ba229ce9c0299071680eb62d16dde3a120d790..5c89800373270ccd96f1a289c2422b187144461b 100644 --- a/src/main/java/neatlogic/framework/form/attribute/core/FormHandlerBase.java +++ b/src/main/java/neatlogic/framework/form/attribute/core/FormHandlerBase.java @@ -18,16 +18,20 @@ package neatlogic.framework.form.attribute.core; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; +import neatlogic.framework.common.util.RC4Util; import neatlogic.framework.form.dto.AttributeDataVo; import neatlogic.framework.form.exception.AttributeValidException; import neatlogic.framework.form.exception.FormExtendAttributeConfigIllegalException; import neatlogic.framework.matrix.dao.mapper.MatrixMapper; import neatlogic.framework.util.$; import org.apache.commons.collections4.CollectionUtils; +import org.apache.commons.collections4.MapUtils; import javax.annotation.Resource; import java.util.Collections; import java.util.List; +import java.util.Map; +import java.util.Objects; public abstract class FormHandlerBase implements IFormAttributeHandler, IFormAttributeDataConversionHandler { @@ -184,4 +188,55 @@ public abstract class FormHandlerBase implements IFormAttributeHandler, IFormAtt protected void myValidateExtendAttributeConfig(String key, JSONObject config) { } + + /** + * 组件内部密码组件密码解密 + * @param source + * @param attributeUuid + * @param otherParamConfig + * @return + */ + protected JSONObject withinPasswordDecryption(Object source, String attributeUuid, JSONObject otherParamConfig) { + JSONObject resultObj = new JSONObject(); + JSONArray dataArray = null; + if (source instanceof JSONArray) { + dataArray = (JSONArray) source; + } + if (CollectionUtils.isEmpty(dataArray)) { + return resultObj; + } + String rowUuid = otherParamConfig.getString("rowUuid"); + for (Object obj : dataArray) { + if (obj instanceof JSONObject) { + JSONObject dataObj = (JSONObject) obj; + if (MapUtils.isNotEmpty(dataObj)) { + for (Map.Entry entry : dataObj.entrySet()) { + if (Objects.equals(entry.getKey(), "uuid")) { + continue; + } + if (Objects.equals(entry.getKey(), attributeUuid)) { + if (Objects.equals(dataObj.getString("uuid"), rowUuid)) { + String password = RC4Util.decrypt((String) entry.getValue()); + resultObj.put("password", password); + } + } else { + if (entry.getValue() instanceof JSONArray) { + JSONObject passwordDecryptionObj = withinPasswordDecryption(entry.getValue(), attributeUuid, otherParamConfig); + if (MapUtils.isNotEmpty(passwordDecryptionObj)) { + JSONArray parentUuidList = passwordDecryptionObj.getJSONArray("parentUuidList"); + if (parentUuidList == null) { + parentUuidList = new JSONArray(); + passwordDecryptionObj.put("parentUuidList", parentUuidList); + } + parentUuidList.add(entry.getKey()); + return passwordDecryptionObj; + } + } + } + } + } + } + } + return resultObj; + } } 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 47b47937901596b08f6237238bcbd8383198cb67..ac2f07b55f9c9f81fa02eb3ee010e8fce645900e 100644 --- a/src/main/java/neatlogic/framework/form/attribute/core/IFormAttributeDataConversionHandler.java +++ b/src/main/java/neatlogic/framework/form/attribute/core/IFormAttributeDataConversionHandler.java @@ -124,13 +124,24 @@ public interface IFormAttributeDataConversionHandler { return source; } +// /** +// * 密码解密 +// * @param source 属性原始数据 +// * @param configObj 属性配置信息 +// * @return 返回解密后的数据 +// */ +// default String passwordDecryption(Object source, JSONObject configObj, String attributeUuid, JSONObject otherParamConfig) { +// return null; +// } + /** * 密码解密 * @param source 属性原始数据 - * @param configObj 属性配置信息 + * @param attributeUuid 属性UUID + * @param otherParamConfig 其他参数信息 * @return 返回解密后的数据 */ - default String passwordDecryption(Object source, JSONObject configObj, String attributeUuid, JSONObject otherParamConfig) { + default JSONObject passwordDecryption(Object source, String attributeUuid, JSONObject otherParamConfig) { return null; } 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 92b3b4148be8466a1ed365d9c59f566305423184..80c4b2f07df27098ca5d837d0c60c36156747476 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 @@ -163,14 +163,27 @@ 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; +// } + @Override - public String passwordDecryption(Object source, JSONObject configObj, String attributeUuid, JSONObject otherParamConfig) { + public JSONObject passwordDecryption(Object source, String attributeUuid, JSONObject otherParamConfig) { + JSONObject resultObj = new JSONObject(); if (source == null) { - return null; + return resultObj; } if (source instanceof String) { - return RC4Util.decrypt((String) source); + String password = RC4Util.decrypt((String) source); + resultObj.put("password", password); } - return null; + return resultObj; } } 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 854171ee181982cd2cb703c07c8cee3ac1dea409..e6e2de24a847a5dc5850100268e1907cfb975370 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 @@ -153,77 +153,82 @@ public class SubassemblyHandler 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; - } - 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.FORMPASSWORD.getHandler())) { - if (Objects.equals(uuid, attributeUuid)) { - String rowUuid = otherParamConfig.getString("rowUuid"); - for (int j = 0; j < dataArray.size(); j++) { - JSONObject dataObj = dataArray.getJSONObject(j); - if (MapUtils.isNotEmpty(dataObj)) { - if (Objects.equals(dataObj.getString("uuid"), rowUuid)) { - Object data = dataObj.get(uuid); - if (data != null) { - String result = formAttributeDataConversionHandler.passwordDecryption(data, config, attributeUuid, otherParamConfig); - if (result != null) { - return result; - } - } - } - } - } - } - - } else { - 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; +// @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.FORMPASSWORD.getHandler())) { +// if (Objects.equals(uuid, attributeUuid)) { +// String rowUuid = otherParamConfig.getString("rowUuid"); +// for (int j = 0; j < dataArray.size(); j++) { +// JSONObject dataObj = dataArray.getJSONObject(j); +// if (MapUtils.isNotEmpty(dataObj)) { +// if (Objects.equals(dataObj.getString("uuid"), rowUuid)) { +// Object data = dataObj.get(uuid); +// if (data != null) { +// String result = formAttributeDataConversionHandler.passwordDecryption(data, config, attributeUuid, otherParamConfig); +// if (result != null) { +// return result; +// } +// } +// } +// } +// } +// } +// +// } else { +// 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; +// } + + @Override + public JSONObject passwordDecryption(Object source, String attributeUuid, JSONObject otherParamConfig) { + return withinPasswordDecryption(source, attributeUuid, otherParamConfig); } } 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 ad0b25b4d9b5014eee6618ebbce5e6a01ac7c52e..6043a12c1806fe9d2ece59dde7ae31d081691327 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 @@ -899,58 +899,63 @@ 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; +// } + @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; + public JSONObject passwordDecryption(Object source, String attributeUuid, JSONObject otherParamConfig) { + return withinPasswordDecryption(source, attributeUuid, otherParamConfig); } }