use of org.jkiss.dbeaver.model.net.DBWHandlerConfiguration in project dbeaver by dbeaver.
the class SSHTunnelConfiguratorUI method testTunnelConnection.
private void testTunnelConnection() {
DBWHandlerConfiguration configuration = new DBWHandlerConfiguration(savedConfiguration);
configuration.setProperties(Collections.emptyMap());
saveSettings(configuration);
DBPDataSourceContainer dataSource = configuration.getDataSource();
if (dataSource != null) {
configuration.resolveDynamicVariables(new DataSourceVariableResolver(dataSource, dataSource.getConnectionConfiguration()));
} else {
configuration.resolveDynamicVariables(SystemVariablesResolver.INSTANCE);
}
try {
final String[] tunnelVersions = new String[2];
UIUtils.runInProgressDialog(monitor -> {
monitor.beginTask("Instantiate SSH tunnel", 2);
SSHTunnelImpl tunnel = new SSHTunnelImpl();
DBPConnectionConfiguration connectionConfig = new DBPConnectionConfiguration();
connectionConfig.setHostName("localhost");
connectionConfig.setHostPort(configuration.getStringProperty(DBWHandlerConfiguration.PROP_PORT));
try {
monitor.subTask("Initialize tunnel");
tunnel.initializeHandler(monitor, DBWorkbench.getPlatform(), configuration, connectionConfig);
monitor.worked(1);
// Get info
tunnelVersions[0] = tunnel.getImplementation().getClientVersion();
tunnelVersions[1] = tunnel.getImplementation().getServerVersion();
// Close it
monitor.subTask("Close tunnel");
tunnel.closeTunnel(monitor);
monitor.worked(1);
} catch (Exception e) {
throw new InvocationTargetException(e);
}
monitor.done();
});
MessageDialog.openInformation(hostText.getShell(), ModelMessages.dialog_connection_wizard_start_connection_monitor_success, "Connected!\n\nClient version: " + tunnelVersions[0] + "\nServer version: " + tunnelVersions[1]);
} catch (InvocationTargetException ex) {
DBWorkbench.getPlatformUI().showError(CoreMessages.dialog_connection_wizard_start_dialog_error_title, null, GeneralUtils.makeExceptionStatus(ex.getTargetException()));
}
}
use of org.jkiss.dbeaver.model.net.DBWHandlerConfiguration in project dbeaver by dbeaver.
the class SSHTunnelConfiguratorUI method loadSettings.
@Override
public void loadSettings(DBWHandlerConfiguration configuration) {
hostText.setText(CommonUtils.notEmpty(configuration.getStringProperty(DBWHandlerConfiguration.PROP_HOST)));
int portString = configuration.getIntProperty(DBWHandlerConfiguration.PROP_PORT);
if (portString != 0) {
portText.setSelection(portString);
} else {
portText.setSelection(SSHConstants.DEFAULT_SSH_PORT);
}
userNameText.setText(CommonUtils.notEmpty(configuration.getUserName()));
SSHConstants.AuthType authType = SSHConstants.AuthType.PASSWORD;
String authTypeName = configuration.getStringProperty(SSHConstants.PROP_AUTH_TYPE);
if (!CommonUtils.isEmpty(authTypeName)) {
authType = SSHConstants.AuthType.valueOf(authTypeName);
}
if (SSHConstants.AuthType.PASSWORD.equals(authType)) {
authMethodCombo.select(0);
} else if (SSHConstants.AuthType.PUBLIC_KEY.equals(authType)) {
authMethodCombo.select(1);
} else {
authMethodCombo.select(2);
}
privateKeyText.setText(CommonUtils.notEmpty(configuration.getStringProperty(SSHConstants.PROP_KEY_PATH)));
passwordText.setText(CommonUtils.notEmpty(configuration.getPassword()));
savePasswordCheckbox.setSelection(configuration.isSavePassword());
String implType = configuration.getStringProperty(SSHConstants.PROP_IMPLEMENTATION);
if (CommonUtils.isEmpty(implType)) {
tunnelImplCombo.select(0);
} else {
SSHImplementationDescriptor desc = SSHImplementationRegistry.getInstance().getDescriptor(implType);
if (desc != null) {
tunnelImplCombo.setText(desc.getLabel());
} else {
tunnelImplCombo.select(0);
}
}
localHostText.setText(CommonUtils.notEmpty(configuration.getStringProperty(SSHConstants.PROP_LOCAL_HOST)));
int lpValue = configuration.getIntProperty(SSHConstants.PROP_LOCAL_PORT);
if (lpValue != 0) {
localPortSpinner.setSelection(lpValue);
}
remoteHostText.setText(CommonUtils.notEmpty(configuration.getStringProperty(SSHConstants.PROP_REMOTE_HOST)));
int rpValue = configuration.getIntProperty(SSHConstants.PROP_REMOTE_PORT);
if (rpValue != 0) {
remotePortSpinner.setSelection(rpValue);
}
int kaValue = configuration.getIntProperty(SSHConstants.PROP_ALIVE_INTERVAL);
if (kaValue != 0) {
keepAliveText.setSelection(kaValue);
}
int timeoutValue = configuration.getIntProperty(SSHConstants.PROP_CONNECT_TIMEOUT);
if (timeoutValue != 0) {
tunnelTimeout.setSelection(timeoutValue);
}
updateAuthMethodVisibility();
savedConfiguration = new DBWHandlerConfiguration(configuration);
DBPDataSourceContainer dataSource = savedConfiguration.getDataSource();
if (dataSource != null) {
variablesHintLabel.setResolver(new DataSourceVariableResolver(dataSource, dataSource.getConnectionConfiguration()));
}
}
use of org.jkiss.dbeaver.model.net.DBWHandlerConfiguration in project dbeaver by dbeaver.
the class GlobalProxySelector method getProxiesForDataSource.
@Nullable
protected List<Proxy> getProxiesForDataSource(@NotNull URI uri, @NotNull DBPDataSourceContainer dataSourceContainer) {
if (SocksConstants.SOCKET_SCHEME.equals(uri.getScheme())) {
// 2. Check for connections' proxy config
List<Proxy> proxies = null;
for (DBWHandlerConfiguration networkHandler : dataSourceContainer.getConnectionConfiguration().getHandlers()) {
if (networkHandler.isEnabled() && networkHandler.getType() == DBWHandlerType.PROXY) {
String proxyHost = networkHandler.getStringProperty(SocksConstants.PROP_HOST);
int proxyPort = networkHandler.getIntProperty(SocksConstants.PROP_PORT);
if (!CommonUtils.isEmpty(proxyHost) && proxyPort != 0) {
InetSocketAddress proxyAddr = new InetSocketAddress(proxyHost, proxyPort);
Proxy proxy = new Proxy(Proxy.Type.SOCKS, proxyAddr);
if (proxies == null) {
proxies = new ArrayList<>();
}
proxies.add(proxy);
log.debug("Use SOCKS proxy [" + proxyAddr + "]");
}
}
}
if (proxies != null) {
return proxies;
}
}
return null;
}
use of org.jkiss.dbeaver.model.net.DBWHandlerConfiguration in project dbeaver by dbeaver.
the class NNAHDataSourceTunnel method getNodeActionToolTip.
@Override
public String getNodeActionToolTip(INavigatorModelView view, DBNNode node) {
StringBuilder tip = new StringBuilder("Network handlers enabled:");
for (DBWHandlerConfiguration handler : ((DBNDataSource) node).getDataSourceContainer().getConnectionConfiguration().getHandlers()) {
if (handler.isEnabled()) {
tip.append("\n -").append(handler.getHandlerDescriptor().getLabel());
String hostName = handler.getStringProperty(DBWHandlerConfiguration.PROP_HOST);
if (!CommonUtils.isEmpty(hostName)) {
tip.append(": ").append(hostName);
}
}
}
return tip.toString();
}
Aggregations