From 6a0820c9e8d9ae271e6b2e6ea419d06d49d5dd15 Mon Sep 17 00:00:00 2001 From: Lanlan Date: Mon, 20 Jun 2022 14:52:14 +0800 Subject: [PATCH 1/3] =?UTF-8?q?REPORT-72595=20FR=E6=BA=90=E7=A0=81?= =?UTF-8?q?=E4=B8=AD=E5=AD=98=E5=9C=A8=E5=8A=A0=E5=AF=86=E5=AF=86=E9=92=A5?= =?UTF-8?q?=E7=A1=AC=E7=BC=96=E7=A0=81=EF=BC=8C=E5=BB=BA=E8=AE=AE=E6=94=BE?= =?UTF-8?q?=E5=88=B0=E9=85=8D=E7=BD=AE=E6=96=87=E4=BB=B6=E4=B8=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../login/utils/DesignerLoginUtils.java | 22 ++++++++++++++++--- .../resources/com/fr/design/config/default | 1 + 2 files changed, 20 insertions(+), 3 deletions(-) create mode 100644 designer-base/src/main/resources/com/fr/design/config/default diff --git a/designer-base/src/main/java/com/fr/design/login/utils/DesignerLoginUtils.java b/designer-base/src/main/java/com/fr/design/login/utils/DesignerLoginUtils.java index a39a0be4b..ca238d154 100644 --- a/designer-base/src/main/java/com/fr/design/login/utils/DesignerLoginUtils.java +++ b/designer-base/src/main/java/com/fr/design/login/utils/DesignerLoginUtils.java @@ -9,12 +9,16 @@ import com.fr.general.http.HttpToolbox; import com.fr.general.log.MessageFormatter; import com.fr.json.JSONObject; import com.fr.log.FineLoggerFactory; +import com.fr.security.encryption.storage.keys.DefaultKeys; import com.fr.stable.StringUtils; import com.fr.third.org.bouncycastle.util.encoders.Hex; import java.awt.Window; +import java.io.IOException; +import java.io.InputStream; import java.security.SecureRandom; import java.util.HashMap; import java.util.Map; +import java.util.Properties; import javax.crypto.Cipher; import javax.crypto.spec.IvParameterSpec; import javax.crypto.spec.SecretKeySpec; @@ -28,8 +32,6 @@ public class DesignerLoginUtils { private static final String PRODUCT_FINEREPORT = "product-finereport"; - private static final String KEY = "i7hP48WAcuTrmxfN"; - public static Map renderMap() { Map map4Tpl = new HashMap<>(); map4Tpl.put("language", GeneralContext.getLocale().toString()); @@ -85,8 +87,11 @@ public class DesignerLoginUtils { jo.put("uid", manager.getDesignerLoginUid()); jo.put("username", manager.getDesignerLoginUsername()); jo.put("source", PRODUCT_FINEREPORT); + + Properties properties = read("/default"); + byte[] iv = randomIv(); - return new String(Hex.encode(iv)) + encrypt(jo.toString(), KEY.getBytes(), iv); + return new String(Hex.encode(iv)) + encrypt(jo.toString(), properties.getProperty("Fine-Designer_Login").getBytes(), iv); } private static byte[] randomIv() { @@ -105,4 +110,15 @@ public class DesignerLoginUtils { byte[] resultBytes = cipher.doFinal(content.getBytes()); return new String(Hex.encode(resultBytes)); } + + private static Properties read(String fileName) { + fileName = "com/fr/design/config" + fileName; + Properties properties = new Properties(); + try (InputStream inputStream = DefaultKeys.class.getClassLoader().getResourceAsStream(fileName)){ + properties.load(inputStream); + } catch (IOException e) { + FineLoggerFactory.getLogger().error(e.getMessage(), e); + } + return properties; + } } diff --git a/designer-base/src/main/resources/com/fr/design/config/default b/designer-base/src/main/resources/com/fr/design/config/default new file mode 100644 index 000000000..f808a8237 --- /dev/null +++ b/designer-base/src/main/resources/com/fr/design/config/default @@ -0,0 +1 @@ +Fine-Designer_Login=i7hP48WAcuTrmxfN From 78218164b4ac454458eabefc7efe5c3be07538df Mon Sep 17 00:00:00 2001 From: Lanlan Date: Mon, 20 Jun 2022 15:10:08 +0800 Subject: [PATCH 2/3] =?UTF-8?q?=E5=8D=95=E7=8B=AC=E5=86=99=E4=B8=80?= =?UTF-8?q?=E4=B8=AA=20DefaultLoginKeys?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../design/login/config/DefaultLoginKeys.java | 48 +++++++++++++++++++ .../login/utils/DesignerLoginUtils.java | 25 +++------- 2 files changed, 54 insertions(+), 19 deletions(-) create mode 100644 designer-base/src/main/java/com/fr/design/login/config/DefaultLoginKeys.java diff --git a/designer-base/src/main/java/com/fr/design/login/config/DefaultLoginKeys.java b/designer-base/src/main/java/com/fr/design/login/config/DefaultLoginKeys.java new file mode 100644 index 000000000..36988aa5c --- /dev/null +++ b/designer-base/src/main/java/com/fr/design/login/config/DefaultLoginKeys.java @@ -0,0 +1,48 @@ +package com.fr.design.login.config; + +import com.fr.log.FineLoggerFactory; +import java.io.IOException; +import java.io.InputStream; +import java.util.HashMap; +import java.util.Map; +import java.util.Properties; + +/** + * @author Lanlan + * @version 10.0 + * Created by Lanlan on 2022/6/20 + */ +public class DefaultLoginKeys { + + private static final String FILENAME = "com/fr/design/config/default"; + + private static final DefaultLoginKeys INSTANCE = new DefaultLoginKeys(); + + public static DefaultLoginKeys getInstance() { + return INSTANCE; + } + + private final Map keys = new HashMap<>(); + + private DefaultLoginKeys() { + Properties properties = load(); + for (Map.Entry entry : properties.entrySet()) { + String name = entry.getKey().toString(); + keys.put(name, entry.getValue().toString()); + } + } + + public String getKey(String name) { + return keys.get(name); + } + + private Properties load() { + Properties properties = new Properties(); + try (InputStream inputStream = DefaultLoginKeys.class.getClassLoader().getResourceAsStream(FILENAME)) { + properties.load(inputStream); + } catch (IOException e) { + FineLoggerFactory.getLogger().error(e.getMessage(), e); + } + return properties; + } +} diff --git a/designer-base/src/main/java/com/fr/design/login/utils/DesignerLoginUtils.java b/designer-base/src/main/java/com/fr/design/login/utils/DesignerLoginUtils.java index ca238d154..8845f00e1 100644 --- a/designer-base/src/main/java/com/fr/design/login/utils/DesignerLoginUtils.java +++ b/designer-base/src/main/java/com/fr/design/login/utils/DesignerLoginUtils.java @@ -1,6 +1,7 @@ package com.fr.design.login.utils; import com.fr.design.DesignerEnvManager; +import com.fr.design.login.config.DefaultLoginKeys; import com.fr.design.mainframe.toast.DesignerToastMsgUtil; import com.fr.general.CloudCenter; import com.fr.general.CloudCenterConfig; @@ -9,16 +10,12 @@ import com.fr.general.http.HttpToolbox; import com.fr.general.log.MessageFormatter; import com.fr.json.JSONObject; import com.fr.log.FineLoggerFactory; -import com.fr.security.encryption.storage.keys.DefaultKeys; import com.fr.stable.StringUtils; import com.fr.third.org.bouncycastle.util.encoders.Hex; import java.awt.Window; -import java.io.IOException; -import java.io.InputStream; import java.security.SecureRandom; import java.util.HashMap; import java.util.Map; -import java.util.Properties; import javax.crypto.Cipher; import javax.crypto.spec.IvParameterSpec; import javax.crypto.spec.SecretKeySpec; @@ -87,11 +84,12 @@ public class DesignerLoginUtils { jo.put("uid", manager.getDesignerLoginUid()); jo.put("username", manager.getDesignerLoginUsername()); jo.put("source", PRODUCT_FINEREPORT); - - Properties properties = read("/default"); - byte[] iv = randomIv(); - return new String(Hex.encode(iv)) + encrypt(jo.toString(), properties.getProperty("Fine-Designer_Login").getBytes(), iv); + return new String(Hex.encode(iv)) + encrypt( + jo.toString(), + DefaultLoginKeys.getInstance().getKey("Fine-Designer_Login").getBytes(), + iv + ); } private static byte[] randomIv() { @@ -110,15 +108,4 @@ public class DesignerLoginUtils { byte[] resultBytes = cipher.doFinal(content.getBytes()); return new String(Hex.encode(resultBytes)); } - - private static Properties read(String fileName) { - fileName = "com/fr/design/config" + fileName; - Properties properties = new Properties(); - try (InputStream inputStream = DefaultKeys.class.getClassLoader().getResourceAsStream(fileName)){ - properties.load(inputStream); - } catch (IOException e) { - FineLoggerFactory.getLogger().error(e.getMessage(), e); - } - return properties; - } } From a919ce7c27804b3ca96bcc6d37424d5df5cc89cd Mon Sep 17 00:00:00 2001 From: Yvan Date: Mon, 1 Aug 2022 18:42:42 +0800 Subject: [PATCH 3/3] =?UTF-8?q?REPORT-77217=20ConnectionProvider-=E4=BF=AE?= =?UTF-8?q?=E6=94=B9=E4=B9=8B=E5=90=8E=E6=95=B0=E6=8D=AE=E8=BF=9E=E6=8E=A5?= =?UTF-8?q?=E4=BF=A1=E6=81=AF=E6=97=A0=E6=B3=95=E4=BF=9D=E5=AD=98=20?= =?UTF-8?q?=E5=90=8C=E6=AD=A510.0=20=E3=80=90=E9=97=AE=E9=A2=98=E5=8E=9F?= =?UTF-8?q?=E5=9B=A0=E3=80=91=E4=BA=A7=E7=94=9F=E5=81=87=E4=BF=9D=E5=AD=98?= =?UTF-8?q?=E7=9A=84=E5=8E=9F=E5=9B=A0=E6=98=AF=EF=BC=8C=E5=9C=A8=E4=BF=9D?= =?UTF-8?q?=E5=AD=98=E7=9A=84=E6=97=B6=E5=80=99=E4=BC=9A=E5=88=A4=E6=96=AD?= =?UTF-8?q?=E7=8E=B0=E6=9C=89=E7=9A=84Connection=E4=B8=8E=E4=BB=A5?= =?UTF-8?q?=E5=89=8D=E5=AD=98=E5=82=A8=E7=9A=84Connection=E6=98=AF?= =?UTF-8?q?=E5=90=A6=E6=9C=89=E4=B8=8D=E5=90=8C=EF=BC=8C=E5=A6=82=E6=9E=9C?= =?UTF-8?q?=E4=B8=8D=E5=90=8C=E5=B0=B1=E4=BB=A3=E8=A1=A8=E9=9C=80=E8=A6=81?= =?UTF-8?q?=E6=9B=B4=E6=96=B0=E3=80=82=E5=AE=9E=E9=99=85=E4=B8=8A=E6=8F=92?= =?UTF-8?q?=E4=BB=B6=E4=B8=AD=E7=9A=84Connection=E7=9B=B8=E5=85=B3?= =?UTF-8?q?=E7=B1=BB=E6=B2=A1=E6=9C=89=E5=86=99equals=E6=96=B9=E6=B3=95?= =?UTF-8?q?=EF=BC=8C=E7=84=B6=E5=90=8E=E6=96=B0=E6=97=A7Connection?= =?UTF-8?q?=E8=A2=AB=E8=AE=A4=E4=B8=BA=E6=98=AF=E7=9B=B8=E5=90=8C=E4=BA=86?= =?UTF-8?q?=EF=BC=8C=E5=B0=B1=E6=B2=A1=E6=9C=89=E8=B5=B0=E5=90=8E=E9=9D=A2?= =?UTF-8?q?=E7=9A=84=E6=9B=B4=E6=96=B0=E9=85=8D=E7=BD=AE=E7=9A=84=E9=80=BB?= =?UTF-8?q?=E8=BE=91=20=E3=80=90=E6=94=B9=E5=8A=A8=E6=96=B9=E6=A1=88?= =?UTF-8?q?=E3=80=91=E6=8B=89rinoux=E3=80=81vito=E3=80=81hugh=E4=B8=80?= =?UTF-8?q?=E8=B5=B7=E6=B2=9F=E9=80=9A=E4=BA=86=E4=B8=8B=E6=96=B9=E6=A1=88?= =?UTF-8?q?=EF=BC=8C=E6=9A=82=E6=97=B6=E4=B8=BB=E4=BB=A3=E7=A0=81=E9=87=8C?= =?UTF-8?q?=E5=81=9A=E4=B8=AA=E5=85=BC=E5=AE=B9=EF=BC=8C=E8=AE=A9=E4=B8=BB?= =?UTF-8?q?=E4=BB=A3=E7=A0=81=E5=86=85=E7=BD=AE=E7=9A=84=E4=B8=A4=E7=A7=8D?= =?UTF-8?q?Connection=E5=8E=BB=E5=88=A4=E6=96=AD=E6=98=AF=E5=90=A6?= =?UTF-8?q?=E8=A6=81=E6=9B=B4=E6=96=B0=EF=BC=8C=E5=85=B6=E4=BD=99=E7=9A=84?= =?UTF-8?q?Connection=EF=BC=88=E6=8F=92=E4=BB=B6Connection=EF=BC=89?= =?UTF-8?q?=E9=83=BD=E5=BF=85=E9=A1=BB=E6=9B=B4=E6=96=B0=20=E3=80=90review?= =?UTF-8?q?=E5=BB=BA=E8=AE=AE=E3=80=91=E5=90=8C=E6=AD=A510.0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/fr/design/data/MapCompareUtils.java | 42 ++++++++++++++++++- .../datapane/connect/ConnectionListPane.java | 26 ++++++++++++ 2 files changed, 67 insertions(+), 1 deletion(-) diff --git a/designer-base/src/main/java/com/fr/design/data/MapCompareUtils.java b/designer-base/src/main/java/com/fr/design/data/MapCompareUtils.java index f7492aefc..57fba6178 100644 --- a/designer-base/src/main/java/com/fr/design/data/MapCompareUtils.java +++ b/designer-base/src/main/java/com/fr/design/data/MapCompareUtils.java @@ -16,6 +16,8 @@ public final class MapCompareUtils { /** * 对比两个map 查找出相比orig,other中有哪些是新增的、删除的或者被修改的,并分别进行处理 * + * 对比时默认用equals方法来判断是否为 EntryEventKind#UPDATED + * * @param orig 原始map * @param other 参考的新map * @param eventHandler 有区别时的事件处理器 @@ -24,12 +26,29 @@ public final class MapCompareUtils { */ public static void contrastMapEntries(@NotNull Map orig, @NotNull Map other, @NotNull EventHandler eventHandler) { + contrastMapEntries(orig, other, eventHandler, UpdateRule.DEFAULT); + } + + /** + * 对比两个map 查找出相比orig,other中有哪些是新增的、删除的或者被修改的,并分别进行处理 + * + * 对比时用自定义的规则来判断是否为 EntryEventKind#UPDATED + * + * @param orig 原始map + * @param other 参考的新map + * @param eventHandler 有区别时的事件处理器 + * @param updateRule 自定义的Update事件判定规则 + * @param + * @param + */ + public static void contrastMapEntries(@NotNull Map orig, @NotNull Map other, @NotNull EventHandler eventHandler, @NotNull UpdateRule updateRule) { + Map copiedOrig = new LinkedHashMap<>(orig); other.forEach((k, v) -> { V existedV = copiedOrig.remove(k); if (existedV != null) { - if (!v.equals(existedV)) { + if (updateRule.needUpdate(existedV, v)) { eventHandler.on(EntryEventKind.UPDATED, k, v); } } else { @@ -41,10 +60,31 @@ public final class MapCompareUtils { } + /** + * 事件处理器,对应比较后的三种结果的事件处理 + * @param + * @param + */ public interface EventHandler { void on(EntryEventKind entryEventKind, K k, V v); } + /** + * 判定 数据被修改 的判定规则 + * @param + * @param + */ + public interface UpdateRule { + + EntryEventKind eventKind = EntryEventKind.UPDATED; + + UpdateRule DEFAULT = new UpdateRule() {}; + + default boolean needUpdate(V origin, V v) { + return !v.equals(origin); + } + } + public enum EntryEventKind { ADDED, REMOVED, diff --git a/designer-base/src/main/java/com/fr/design/data/datapane/connect/ConnectionListPane.java b/designer-base/src/main/java/com/fr/design/data/datapane/connect/ConnectionListPane.java index 9d18031b0..63a4a47cb 100644 --- a/designer-base/src/main/java/com/fr/design/data/datapane/connect/ConnectionListPane.java +++ b/designer-base/src/main/java/com/fr/design/data/datapane/connect/ConnectionListPane.java @@ -178,6 +178,32 @@ public class ConnectionListPane extends JListControlPane implements ConnectionSh default: break; } + }, new MapCompareUtils.UpdateRule() { + @Override + public boolean needUpdate(Connection origin, Connection connection) { + return needUpdate0(origin, connection); + } + + /** + * 是否需要更新处理 + * 1. Connection本身equals为false,代表字段修改 + * 2. 非内置的Connection,即插件提供的Connection + * todo 原本一个equals方法就可以搞定,但是插件里面没有实现equals,结果导致不能正确判断,只能主代码里做兼容,很恶心,先记个todo,以后看有没有办法改掉 + * @param origin + * @param connection + * @return + */ + private boolean needUpdate0(Connection origin, Connection connection) { + return !connection.equals(origin) || !isEmbedConnection(connection); + } + + /** + * 是否是主工程里内置的Connection + * @return + */ + private boolean isEmbedConnection(Connection connection) { + return connection instanceof JDBCDatabaseConnection || connection instanceof JNDIDatabaseConnection; + } }); this.validateConnections(addedOrUpdatedConnections);