|
|
@ -3,11 +3,25 @@ package com.fr.design.data.datapane.connect; |
|
|
|
import com.fanruan.config.impl.data.ConnectionConfigProviderFactory; |
|
|
|
import com.fanruan.config.impl.data.ConnectionConfigProviderFactory; |
|
|
|
import com.fanruan.config.impl.data.ConnectionConfigWriterFactory; |
|
|
|
import com.fanruan.config.impl.data.ConnectionConfigWriterFactory; |
|
|
|
import com.fr.config.remote.RemoteConfigEvent; |
|
|
|
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.Connection; |
|
|
|
import com.fr.data.impl.JDBCDatabaseConnection; |
|
|
|
import com.fr.data.impl.JDBCDatabaseConnection; |
|
|
|
import com.fr.data.impl.JNDIDatabaseConnection; |
|
|
|
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.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.ConnectionProcessorFactory; |
|
|
|
|
|
|
|
import com.fr.decision.webservice.v10.datasource.connection.processor.impl.JDBCConnectionProcessor; |
|
|
|
import com.fr.design.ExtraDesignClassManager; |
|
|
|
import com.fr.design.ExtraDesignClassManager; |
|
|
|
import com.fr.design.data.MapCompareUtils; |
|
|
|
import com.fr.design.data.MapCompareUtils; |
|
|
|
import com.fr.design.dialog.BasicDialog; |
|
|
|
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.database.DataBaseTypePointManager; |
|
|
|
import com.fr.license.exception.DataBaseNotSupportedException; |
|
|
|
import com.fr.license.exception.DataBaseNotSupportedException; |
|
|
|
import com.fr.log.FineLoggerFactory; |
|
|
|
import com.fr.log.FineLoggerFactory; |
|
|
|
|
|
|
|
import com.fr.security.encryption.transmission.TransmissionEncryptors; |
|
|
|
import com.fr.stable.ArrayUtils; |
|
|
|
import com.fr.stable.ArrayUtils; |
|
|
|
import com.fr.stable.Nameable; |
|
|
|
import com.fr.stable.Nameable; |
|
|
|
import com.fr.stable.StringUtils; |
|
|
|
import com.fr.stable.StringUtils; |
|
|
|
import com.fr.stable.core.PropertyChangeAdapter; |
|
|
|
import com.fr.stable.core.PropertyChangeAdapter; |
|
|
|
|
|
|
|
import com.fr.third.fasterxml.jackson.databind.ObjectMapper; |
|
|
|
import com.fr.workspace.WorkContext; |
|
|
|
import com.fr.workspace.WorkContext; |
|
|
|
import com.fr.workspace.server.database.DataBaseTypeOperator; |
|
|
|
import com.fr.workspace.server.database.DataBaseTypeOperator; |
|
|
|
import com.fr.workspace.server.entity.connection.BatchConnectionModifyBean; |
|
|
|
import com.fr.workspace.server.entity.connection.BatchConnectionModifyBean; |
|
|
@ -58,6 +74,7 @@ public class ConnectionListPane extends JListControlPane implements ConnectionSh |
|
|
|
private final HashMap<String, String> renameMap = new HashMap<>(); |
|
|
|
private final HashMap<String, String> renameMap = new HashMap<>(); |
|
|
|
private final Map<String, Connection> populatedConnectionsSnapshot = new LinkedHashMap<>(); |
|
|
|
private final Map<String, Connection> populatedConnectionsSnapshot = new LinkedHashMap<>(); |
|
|
|
private static List<String> supportedDatabaseTypes = new ArrayList<>(); |
|
|
|
private static List<String> supportedDatabaseTypes = new ArrayList<>(); |
|
|
|
|
|
|
|
private static ObjectMapper objectMapper = new ObjectMapper(); |
|
|
|
|
|
|
|
|
|
|
|
public ConnectionListPane() { |
|
|
|
public ConnectionListPane() { |
|
|
|
renameMap.clear(); |
|
|
|
renameMap.clear(); |
|
|
@ -220,6 +237,7 @@ public class ConnectionListPane extends JListControlPane implements ConnectionSh |
|
|
|
List<String> removedConnNames = new ArrayList<>(); |
|
|
|
List<String> removedConnNames = new ArrayList<>(); |
|
|
|
List<ConnectionInfoBean> addConnections = new ArrayList<>(); |
|
|
|
List<ConnectionInfoBean> addConnections = new ArrayList<>(); |
|
|
|
List<ConnectionInfoBean> updateConnection = new ArrayList<>(); |
|
|
|
List<ConnectionInfoBean> updateConnection = new ArrayList<>(); |
|
|
|
|
|
|
|
List<Connection> validConnection = new ArrayList<>(); |
|
|
|
MapCompareUtils.contrastMapEntries(populatedConnectionsSnapshot, updatedMap, (entryEventKind, s, connection) -> { |
|
|
|
MapCompareUtils.contrastMapEntries(populatedConnectionsSnapshot, updatedMap, (entryEventKind, s, connection) -> { |
|
|
|
try { |
|
|
|
try { |
|
|
|
switch (entryEventKind) { |
|
|
|
switch (entryEventKind) { |
|
|
@ -227,10 +245,12 @@ public class ConnectionListPane extends JListControlPane implements ConnectionSh |
|
|
|
removedConnNames.add(s); |
|
|
|
removedConnNames.add(s); |
|
|
|
break; |
|
|
|
break; |
|
|
|
case ADDED: |
|
|
|
case ADDED: |
|
|
|
addConnections.add(ConnectionProcessorFactory.createConnectionInfoBean(s, connection)); |
|
|
|
addConnections.add(createConnectionInfoBean(s, connection)); |
|
|
|
|
|
|
|
validConnection.add(connection); |
|
|
|
break; |
|
|
|
break; |
|
|
|
case UPDATED: |
|
|
|
case UPDATED: |
|
|
|
updateConnection.add(ConnectionProcessorFactory.createConnectionInfoBean(s, connection)); |
|
|
|
updateConnection.add(createConnectionInfoBean(s, connection)); |
|
|
|
|
|
|
|
validConnection.add(connection); |
|
|
|
break; |
|
|
|
break; |
|
|
|
default: |
|
|
|
default: |
|
|
|
break; |
|
|
|
break; |
|
|
@ -266,21 +286,17 @@ public class ConnectionListPane extends JListControlPane implements ConnectionSh |
|
|
|
} |
|
|
|
} |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
List<ConnectionInfoBean> validateBeans = new ArrayList<>(); |
|
|
|
this.validateDatabaseType(validConnection); |
|
|
|
validateBeans.addAll(addConnections); |
|
|
|
|
|
|
|
validateBeans.addAll(updateConnection); |
|
|
|
|
|
|
|
this.validateDatabaseType(validateBeans); |
|
|
|
|
|
|
|
this.alterConnections(addConnections, removedConnNames, updateConnection); |
|
|
|
this.alterConnections(addConnections, removedConnNames, updateConnection); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* 校验是否支持所有新增和修改数据连接的数据库类型 |
|
|
|
* 校验是否支持所有新增和修改数据连接的数据库类型 |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public void validateDatabaseType(@NotNull List<ConnectionInfoBean> addedOrUpdatedConnections) throws Exception { |
|
|
|
public void validateDatabaseType(@NotNull List<Connection> addedOrUpdatedConnections) throws Exception { |
|
|
|
Set<String> notSupportedConnections = new HashSet<>(); |
|
|
|
Set<String> notSupportedConnections = new HashSet<>(); |
|
|
|
if (!addedOrUpdatedConnections.isEmpty()) { |
|
|
|
if (!addedOrUpdatedConnections.isEmpty()) { |
|
|
|
for (ConnectionInfoBean bean : addedOrUpdatedConnections) { |
|
|
|
for (Connection connection : addedOrUpdatedConnections) { |
|
|
|
Connection connection = ConnectionProcessorFactory.createConnection(bean); |
|
|
|
|
|
|
|
// 仅校验jdbc连接,其他插件数据连接不进行校验;
|
|
|
|
// 仅校验jdbc连接,其他插件数据连接不进行校验;
|
|
|
|
if (connection instanceof JDBCDatabaseConnection) { |
|
|
|
if (connection instanceof JDBCDatabaseConnection) { |
|
|
|
DBTypes dataBaseTypePoint = DataBaseTypePointManager.getInstance().getDataBaseTypePoint(connection.getDriver(), connection.feature()); |
|
|
|
DBTypes dataBaseTypePoint = DataBaseTypePointManager.getInstance().getDataBaseTypePoint(connection.getDriver(), connection.feature()); |
|
|
@ -317,6 +333,19 @@ public class ConnectionListPane extends JListControlPane implements ConnectionSh |
|
|
|
return false; |
|
|
|
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<ConnectionInfoBean> addConnections, List<String> removedConnNames, List<ConnectionInfoBean> updateConnection) { |
|
|
|
private void alterConnections(List<ConnectionInfoBean> addConnections, List<String> removedConnNames, List<ConnectionInfoBean> 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()); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|