From ff0cee0c639178688ab0c8e69b3d14fe21f4e7e9 Mon Sep 17 00:00:00 2001 From: "Destiny.Lin" Date: Thu, 25 Jul 2024 12:33:02 +0800 Subject: [PATCH] =?UTF-8?q?REPORT-114392=20FR-FBP=E7=89=88=E6=9C=AC?= =?UTF-8?q?=E6=9C=AC=E5=9C=B0=E8=AE=BE=E8=AE=A1=E9=80=82=E9=85=8D=20?= =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E6=95=B0=E6=8D=AE=E8=BF=9E=E6=8E=A5=E4=BF=9D?= =?UTF-8?q?=E5=AD=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../datapane/connect/ConnectionListPane.java | 105 ++++++++++++++++-- 1 file changed, 96 insertions(+), 9 deletions(-) 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 94debc6c5b..72f948648a 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 @@ -3,11 +3,25 @@ package com.fr.design.data.datapane.connect; import com.fanruan.config.impl.data.ConnectionConfigProviderFactory; import com.fanruan.config.impl.data.ConnectionConfigWriterFactory; import com.fr.config.remote.RemoteConfigEvent; +import com.fr.data.auth.AuthenticationType; +import com.fr.data.auth.kerberos.KerberosAuthentication; +import com.fr.data.auth.kerberos.KerberosUtils; import com.fr.data.impl.Connection; import com.fr.data.impl.JDBCDatabaseConnection; import com.fr.data.impl.JNDIDatabaseConnection; +import com.fr.data.pool.DBCPConnectionPoolAttr; +import com.fr.data.security.ssh.BaseSsh; +import com.fr.data.security.ssh.SshType; +import com.fr.data.security.ssh.impl.KeyVerifySsh; +import com.fr.data.security.ssl.BaseSsl; +import com.fr.data.security.ssl.SslType; +import com.fr.data.security.ssl.impl.NormalSsl; +import com.fr.decision.privilege.TransmissionTool; import com.fr.decision.webservice.bean.datasource.ConnectionInfoBean; +import com.fr.decision.webservice.bean.datasource.JDBCConnectionBean; +import com.fr.decision.webservice.utils.DecisionServiceConstants; import com.fr.decision.webservice.v10.datasource.connection.processor.impl.ConnectionProcessorFactory; +import com.fr.decision.webservice.v10.datasource.connection.processor.impl.JDBCConnectionProcessor; import com.fr.design.ExtraDesignClassManager; import com.fr.design.data.MapCompareUtils; import com.fr.design.dialog.BasicDialog; @@ -24,10 +38,12 @@ import com.fr.license.database.DBTypes; import com.fr.license.database.DataBaseTypePointManager; import com.fr.license.exception.DataBaseNotSupportedException; import com.fr.log.FineLoggerFactory; +import com.fr.security.encryption.transmission.TransmissionEncryptors; import com.fr.stable.ArrayUtils; import com.fr.stable.Nameable; import com.fr.stable.StringUtils; import com.fr.stable.core.PropertyChangeAdapter; +import com.fr.third.fasterxml.jackson.databind.ObjectMapper; import com.fr.workspace.WorkContext; import com.fr.workspace.server.database.DataBaseTypeOperator; import com.fr.workspace.server.entity.connection.BatchConnectionModifyBean; @@ -58,6 +74,7 @@ public class ConnectionListPane extends JListControlPane implements ConnectionSh private final HashMap renameMap = new HashMap<>(); private final Map populatedConnectionsSnapshot = new LinkedHashMap<>(); private static List supportedDatabaseTypes = new ArrayList<>(); + private static ObjectMapper objectMapper = new ObjectMapper(); public ConnectionListPane() { renameMap.clear(); @@ -220,6 +237,7 @@ public class ConnectionListPane extends JListControlPane implements ConnectionSh List removedConnNames = new ArrayList<>(); List addConnections = new ArrayList<>(); List updateConnection = new ArrayList<>(); + List validConnection = new ArrayList<>(); MapCompareUtils.contrastMapEntries(populatedConnectionsSnapshot, updatedMap, (entryEventKind, s, connection) -> { try { switch (entryEventKind) { @@ -227,10 +245,12 @@ public class ConnectionListPane extends JListControlPane implements ConnectionSh removedConnNames.add(s); break; case ADDED: - addConnections.add(ConnectionProcessorFactory.createConnectionInfoBean(s, connection)); + addConnections.add(createConnectionInfoBean(s, connection)); + validConnection.add(connection); break; case UPDATED: - updateConnection.add(ConnectionProcessorFactory.createConnectionInfoBean(s, connection)); + updateConnection.add(createConnectionInfoBean(s, connection)); + validConnection.add(connection); break; default: break; @@ -266,21 +286,17 @@ public class ConnectionListPane extends JListControlPane implements ConnectionSh } }); - List validateBeans = new ArrayList<>(); - validateBeans.addAll(addConnections); - validateBeans.addAll(updateConnection); - this.validateDatabaseType(validateBeans); + this.validateDatabaseType(validConnection); this.alterConnections(addConnections, removedConnNames, updateConnection); } /** * 校验是否支持所有新增和修改数据连接的数据库类型 */ - public void validateDatabaseType(@NotNull List addedOrUpdatedConnections) throws Exception { + public void validateDatabaseType(@NotNull List addedOrUpdatedConnections) throws Exception { Set notSupportedConnections = new HashSet<>(); if (!addedOrUpdatedConnections.isEmpty()) { - for (ConnectionInfoBean bean : addedOrUpdatedConnections) { - Connection connection = ConnectionProcessorFactory.createConnection(bean); + for (Connection connection : addedOrUpdatedConnections) { // 仅校验jdbc连接,其他插件数据连接不进行校验; if (connection instanceof JDBCDatabaseConnection) { DBTypes dataBaseTypePoint = DataBaseTypePointManager.getInstance().getDataBaseTypePoint(connection.getDriver(), connection.feature()); @@ -317,6 +333,19 @@ public class ConnectionListPane extends JListControlPane implements ConnectionSh return false; } + private ConnectionInfoBean createConnectionInfoBean(String name, Connection connection) throws Exception { + if (JDBCConnectionProcessor.KEY.acceptConnections().contains(connection.getClass())) { + ConnectionInfoBean bean = new ConnectionInfoBean(); + bean.setConnectionData(objectMapper.writeValueAsString(convertToJDBCConnectionBean(connection, true))); + bean.setConnectionType(JDBCConnectionProcessor.CONNECTION_TYPE); + bean.setConnectionType(JDBCConnectionProcessor.KEY.getConnectionType(connection)); + bean.setConnectionName(name); + bean.setCreator(connection.getCreator()); + return bean; + } else { + return ConnectionProcessorFactory.createConnectionInfoBean(name, connection); + } + } private void alterConnections(List addConnections, List removedConnNames, List updateConnection) { @@ -385,4 +414,62 @@ public class ConnectionListPane extends JListControlPane implements ConnectionSh } } } + + /** + * jdbc的特殊处理 + */ + private JDBCConnectionBean convertToJDBCConnectionBean(Connection connection, boolean withPassword) { + JDBCDatabaseConnection jdbcConnection = (JDBCDatabaseConnection) connection; + JDBCConnectionBean jdbcConnectionBean = new JDBCConnectionBean(); + DBCPConnectionPoolAttr poolAttr = new DBCPConnectionPoolAttr(); + try { + poolAttr = (DBCPConnectionPoolAttr) jdbcConnection.getDbcpAttr().clone(); + } catch (CloneNotSupportedException ignore) { + } + poolAttr.setValidationQuery(TransmissionTool.encrypt(poolAttr.getValidationQuery())); + KerberosAuthentication kerberosAuthentication = null; + if (jdbcConnection.getAuthentication().type() == AuthenticationType.KERBEROS) { + //获取数据连接信息的时候,做一下兼容处理(兼容旧的kerberos形式) + KerberosUtils.compatibilityProcess(((KerberosAuthentication) jdbcConnection.getAuthentication())); + kerberosAuthentication = ((KerberosAuthentication) jdbcConnection.getAuthentication()); + } + //因为设计器创建连接时database属性为空,所以这里直接取数据库保存的fetchSize值,默认值为-1 + return jdbcConnectionBean + .newCharsetName(jdbcConnection.getNewCharsetName()) + .originalCharsetName(jdbcConnection.getOriginalCharsetName()) + .database(jdbcConnection.getDatabase()) + .user(jdbcConnection.getUser()) + .driver(jdbcConnection.getDriver()) + // 关键中的关键,由设计器发出的请求如果要携带密码,不能传明文,必须必须必须传加密后的密码 + .password(withPassword ? TransmissionEncryptors.getInstance().encrypt(jdbcConnection.getPassword()) : DecisionServiceConstants.DEFAULT_PASSWORD) + .schema(jdbcConnection.getSchema()) + .url(jdbcConnection.getURL()) + .creator(jdbcConnection.getCreator()) + .source(jdbcConnection.getDriverSource()) + .connectionPoolAttr(poolAttr.create()) + .authType(kerberosAuthentication != null ? "kerberos" : StringUtils.EMPTY) + .principal(kerberosAuthentication != null ? kerberosAuthentication.getPrincipal() : StringUtils.EMPTY) + .keyPath(kerberosAuthentication != null ? kerberosAuthentication.getKeyPath() : StringUtils.EMPTY) + .krb5Path(kerberosAuthentication != null ? KerberosUtils.getKrb5Path(kerberosAuthentication.getKeyPath(), kerberosAuthentication.getPrincipal()) : StringUtils.EMPTY) + .useJaas(jdbcConnection.getAuthentication().type() == AuthenticationType.KERBEROS && ((KerberosAuthentication) jdbcConnection.getAuthentication()).getUseJaas()) + .fetchSize(jdbcConnection.getFetchSize()).identity(connection.getIdentity()) + .sshType(jdbcConnection.getSsh().getSshType().toString()) + .sshIp(((BaseSsh) jdbcConnection.getSsh()).getIp()) + .usingSsh(jdbcConnection.getSsh().isUsingSsh()) + .sshUser(((BaseSsh) jdbcConnection.getSsh()).getUser()) + .sshPort(((BaseSsh) jdbcConnection.getSsh()).getPort()) + .redirectPort(jdbcConnection.getSsh().getRedirectPort()) + .redirectIp((jdbcConnection.getSsh()).getRedirectIp()) + .sshTimeOut(((BaseSsh) jdbcConnection.getSsh()).getTimeOut()) + .sshSecret(withPassword ? ((BaseSsh) jdbcConnection.getSsh()).getSecret() : DecisionServiceConstants.DEFAULT_PASSWORD) + .sshPrivateKeyPath(jdbcConnection.getSsh().getSshType() == SshType.KEY ? ((KeyVerifySsh) jdbcConnection.getSsh()).getPrivateKeyPath() : StringUtils.EMPTY) + .usingSsl((jdbcConnection.getSsl()).isUsingSsl()) + .sslType(jdbcConnection.getSsl().getSslType().toString()) + .sslClientCertificate(((BaseSsl) jdbcConnection.getSsl()).getClientCertificate()) + .sslClientPrivateKey(((BaseSsl) jdbcConnection.getSsl()).getClientPrivateKey()) + .caCertificate(((BaseSsl) jdbcConnection.getSsl()).getCaCertificate()) + .properties(jdbcConnection.getProperties()) + .verifyCa(jdbcConnection.getSsl().getSslType() == SslType.NORMAL && ((NormalSsl) jdbcConnection.getSsl()).isVerifyCa()); + } + }