Search in sources :

Example 61 with DBWHandlerConfiguration

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()));
    }
}
Also used : DBPConnectionConfiguration(org.jkiss.dbeaver.model.connection.DBPConnectionConfiguration) SSHTunnelImpl(org.jkiss.dbeaver.model.net.ssh.SSHTunnelImpl) DBWHandlerConfiguration(org.jkiss.dbeaver.model.net.DBWHandlerConfiguration) DBPDataSourceContainer(org.jkiss.dbeaver.model.DBPDataSourceContainer) DataSourceVariableResolver(org.jkiss.dbeaver.model.connection.DataSourceVariableResolver) InvocationTargetException(java.lang.reflect.InvocationTargetException) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 62 with DBWHandlerConfiguration

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()));
    }
}
Also used : SSHImplementationDescriptor(org.jkiss.dbeaver.model.net.ssh.registry.SSHImplementationDescriptor) DBWHandlerConfiguration(org.jkiss.dbeaver.model.net.DBWHandlerConfiguration) SSHConstants(org.jkiss.dbeaver.model.net.ssh.SSHConstants) DBPDataSourceContainer(org.jkiss.dbeaver.model.DBPDataSourceContainer) DataSourceVariableResolver(org.jkiss.dbeaver.model.connection.DataSourceVariableResolver)

Example 63 with DBWHandlerConfiguration

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;
}
Also used : DBWHandlerConfiguration(org.jkiss.dbeaver.model.net.DBWHandlerConfiguration) Nullable(org.jkiss.code.Nullable)

Example 64 with DBWHandlerConfiguration

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();
}
Also used : DBWHandlerConfiguration(org.jkiss.dbeaver.model.net.DBWHandlerConfiguration) DBNDataSource(org.jkiss.dbeaver.model.navigator.DBNDataSource)

Aggregations

DBWHandlerConfiguration (org.jkiss.dbeaver.model.net.DBWHandlerConfiguration)64 DBException (org.jkiss.dbeaver.DBException)20 DBPDataSourceContainer (org.jkiss.dbeaver.model.DBPDataSourceContainer)12 DBPConnectionConfiguration (org.jkiss.dbeaver.model.connection.DBPConnectionConfiguration)12 NetworkHandlerDescriptor (org.jkiss.dbeaver.registry.network.NetworkHandlerDescriptor)12 SQLException (java.sql.SQLException)8 DBWNetworkProfile (org.jkiss.dbeaver.model.net.DBWNetworkProfile)8 DBRShellCommand (org.jkiss.dbeaver.model.runtime.DBRShellCommand)8 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)6 SelectionEvent (org.eclipse.swt.events.SelectionEvent)6 GridData (org.eclipse.swt.layout.GridData)6 GridLayout (org.eclipse.swt.layout.GridLayout)6 Nullable (org.jkiss.code.Nullable)6 DBPDataSourceOrigin (org.jkiss.dbeaver.model.DBPDataSourceOrigin)6 DBPDriver (org.jkiss.dbeaver.model.connection.DBPDriver)6 SimplePreferenceStore (org.jkiss.dbeaver.model.impl.preferences.SimplePreferenceStore)6 UIPropertyConfiguratorDescriptor (org.jkiss.dbeaver.registry.configurator.UIPropertyConfiguratorDescriptor)6 TypeToken (com.google.gson.reflect.TypeToken)4 MalformedURLException (java.net.MalformedURLException)4 ArrayList (java.util.ArrayList)4