Search in sources :

Example 1 with SSHImplementationDescriptor

use of org.jkiss.dbeaver.model.net.ssh.registry.SSHImplementationDescriptor in project dbeaver by dbeaver.

the class SSHTunnelConfiguratorUI method createControl.

@Override
public void createControl(Composite parent) {
    final Composite composite = new Composite(parent, SWT.NONE);
    GridData gd = new GridData(GridData.FILL_BOTH);
    // gd.minimumHeight = 200;
    composite.setLayoutData(gd);
    composite.setLayout(new GridLayout(1, false));
    {
        Group settingsGroup = UIUtils.createControlGroup(composite, SSHUIMessages.model_ssh_configurator_group_settings, 2, GridData.FILL_HORIZONTAL, SWT.DEFAULT);
        // $NON-NLS-2$
        hostText = UIUtils.createLabelText(settingsGroup, SSHUIMessages.model_ssh_configurator_label_host_ip, null, SWT.BORDER, new GridData(GridData.FILL_HORIZONTAL));
        portText = UIUtils.createLabelSpinner(settingsGroup, SSHUIMessages.model_ssh_configurator_label_port, SSHConstants.DEFAULT_SSH_PORT, 0, 65535);
        // $NON-NLS-2$
        userNameText = UIUtils.createLabelText(settingsGroup, SSHUIMessages.model_ssh_configurator_label_user_name, null, SWT.BORDER, new GridData(GridData.FILL_HORIZONTAL));
        authMethodCombo = UIUtils.createLabelCombo(settingsGroup, SSHUIMessages.model_ssh_configurator_combo_auth_method, SWT.DROP_DOWN | SWT.READ_ONLY);
        authMethodCombo.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING));
        authMethodCombo.add(SSHUIMessages.model_ssh_configurator_combo_password);
        authMethodCombo.add(SSHUIMessages.model_ssh_configurator_combo_pub_key);
        privateKeyLabel = UIUtils.createControlLabel(settingsGroup, SSHUIMessages.model_ssh_configurator_label_private_key);
        privateKeyLabel.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING));
        privateKeyText = new TextWithOpenFile(settingsGroup, SSHUIMessages.model_ssh_configurator_dialog_choose_private_key, new String[] { "*", "*.ssh", "*.pem", "*.*" });
        privateKeyText.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
        {
            pwdLabel = UIUtils.createControlLabel(settingsGroup, SSHUIMessages.model_ssh_configurator_label_password);
            passwordText = new Text(settingsGroup, SWT.BORDER | SWT.PASSWORD);
            passwordText.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
            savePasswordCheckbox = UIUtils.createLabelCheckbox(settingsGroup, SSHUIMessages.model_ssh_configurator_checkbox_save_pass, false);
        }
    }
    {
        Group advancedGroup = UIUtils.createControlGroup(composite, SSHUIMessages.model_ssh_configurator_group_advanced, 2, GridData.FILL_HORIZONTAL, SWT.DEFAULT);
        tunnelImplCombo = UIUtils.createLabelCombo(advancedGroup, SSHUIMessages.model_ssh_configurator_label_implementation, SWT.DROP_DOWN | SWT.READ_ONLY);
        tunnelImplCombo.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING));
        for (SSHImplementationDescriptor it : SSHImplementationRegistry.getInstance().getDescriptors()) {
            tunnelImplCombo.add(it.getLabel());
        }
        localPortSpinner = UIUtils.createLabelSpinner(advancedGroup, SSHUIMessages.model_ssh_configurator_label_local_port, 0, Integer.MIN_VALUE, Integer.MAX_VALUE);
        localPortSpinner.setToolTipText(SSHUIMessages.model_ssh_configurator_label_local_port_description);
        keepAliveText = UIUtils.createLabelSpinner(advancedGroup, SSHUIMessages.model_ssh_configurator_label_keep_alive, 0, 0, Integer.MAX_VALUE);
        tunnelTimeout = UIUtils.createLabelSpinner(advancedGroup, SSHUIMessages.model_ssh_configurator_label_tunnel_timeout, SSHConstants.DEFAULT_CONNECT_TIMEOUT, 0, 300000);
    }
    authMethodCombo.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            updatePrivateKeyVisibility();
        }
    });
}
Also used : SSHImplementationDescriptor(org.jkiss.dbeaver.model.net.ssh.registry.SSHImplementationDescriptor) GridLayout(org.eclipse.swt.layout.GridLayout) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) GridData(org.eclipse.swt.layout.GridData) SelectionEvent(org.eclipse.swt.events.SelectionEvent) TextWithOpenFile(org.jkiss.dbeaver.ui.controls.TextWithOpenFile)

Example 2 with SSHImplementationDescriptor

use of org.jkiss.dbeaver.model.net.ssh.registry.SSHImplementationDescriptor in project dbeaver by serge-rider.

the class SSHTunnelImpl method initializeHandler.

@Override
public DBPConnectionConfiguration initializeHandler(DBRProgressMonitor monitor, DBPPlatform platform, DBWHandlerConfiguration configuration, DBPConnectionConfiguration connectionInfo) throws DBException, IOException {
    this.configuration = configuration;
    String implId = configuration.getStringProperty(SSHConstants.PROP_IMPLEMENTATION);
    if (CommonUtils.isEmpty(implId)) {
        // Backward compatibility
        implId = DEF_IMPLEMENTATION;
    }
    try {
        SSHImplementationDescriptor implDesc = SSHImplementationRegistry.getInstance().getDescriptor(implId);
        if (implDesc == null) {
            implDesc = SSHImplementationRegistry.getInstance().getDescriptor(DEF_IMPLEMENTATION);
        }
        if (implDesc == null) {
            throw new DBException("Can't find SSH tunnel implementation '" + implId + "'");
        }
        if (implementation == null || implementation.getClass() != implDesc.getImplClass().getObjectClass()) {
            implementation = implDesc.getImplClass().createInstance(SSHImplementation.class);
        }
    } catch (Throwable e) {
        throw new DBException("Can't create SSH tunnel implementation '" + implId + "'", e);
    }
    return implementation.initTunnel(monitor, platform, configuration, connectionInfo);
}
Also used : SSHImplementationDescriptor(org.jkiss.dbeaver.model.net.ssh.registry.SSHImplementationDescriptor) DBException(org.jkiss.dbeaver.DBException)

Example 3 with SSHImplementationDescriptor

use of org.jkiss.dbeaver.model.net.ssh.registry.SSHImplementationDescriptor in project dbeaver by dbeaver.

the class SSHTunnelConfiguratorUI method saveSettings.

@Override
public void saveSettings(DBWHandlerConfiguration configuration) {
    configuration.setProperty(DBWHandlerConfiguration.PROP_HOST, hostText.getText().trim());
    configuration.setProperty(DBWHandlerConfiguration.PROP_PORT, portText.getSelection());
    switch(authMethodCombo.getSelectionIndex()) {
        case 0:
            configuration.setProperty(SSHConstants.PROP_AUTH_TYPE, SSHConstants.AuthType.PASSWORD.name());
            break;
        case 1:
            configuration.setProperty(SSHConstants.PROP_AUTH_TYPE, SSHConstants.AuthType.PUBLIC_KEY.name());
            break;
        case 2:
            configuration.setProperty(SSHConstants.PROP_AUTH_TYPE, SSHConstants.AuthType.AGENT.name());
            break;
    }
    configuration.setProperty(SSHConstants.PROP_KEY_PATH, privateKeyText.getText().trim());
    configuration.setUserName(userNameText.getText().trim());
    configuration.setPassword(passwordText.getText());
    configuration.setSavePassword(savePasswordCheckbox.getSelection());
    String implLabel = tunnelImplCombo.getText();
    for (SSHImplementationDescriptor it : SSHImplementationRegistry.getInstance().getDescriptors()) {
        if (it.getLabel().equals(implLabel)) {
            configuration.setProperty(SSHConstants.PROP_IMPLEMENTATION, it.getId());
            break;
        }
    }
    configuration.setProperty(SSHConstants.PROP_LOCAL_HOST, localHostText.getText().trim());
    int localPort = localPortSpinner.getSelection();
    if (localPort <= 0) {
        configuration.setProperty(SSHConstants.PROP_LOCAL_PORT, null);
    } else {
        configuration.setProperty(SSHConstants.PROP_LOCAL_PORT, localPort);
    }
    configuration.setProperty(SSHConstants.PROP_REMOTE_HOST, remoteHostText.getText().trim());
    int remotePort = remotePortSpinner.getSelection();
    if (remotePort <= 0) {
        configuration.setProperty(SSHConstants.PROP_REMOTE_PORT, null);
    } else {
        configuration.setProperty(SSHConstants.PROP_REMOTE_PORT, remotePort);
    }
    int kaInterval = keepAliveText.getSelection();
    if (kaInterval <= 0) {
        configuration.setProperty(SSHConstants.PROP_ALIVE_INTERVAL, null);
    } else {
        configuration.setProperty(SSHConstants.PROP_ALIVE_INTERVAL, kaInterval);
    }
    int conTimeout = tunnelTimeout.getSelection();
    if (conTimeout != 0 && conTimeout != SSHConstants.DEFAULT_CONNECT_TIMEOUT) {
        configuration.setProperty(SSHConstants.PROP_CONNECT_TIMEOUT, conTimeout);
    }
}
Also used : SSHImplementationDescriptor(org.jkiss.dbeaver.model.net.ssh.registry.SSHImplementationDescriptor)

Example 4 with SSHImplementationDescriptor

use of org.jkiss.dbeaver.model.net.ssh.registry.SSHImplementationDescriptor in project dbeaver by dbeaver.

the class SSHTunnelImpl method initializeTunnel.

@Override
public DBPConnectionConfiguration initializeTunnel(DBRProgressMonitor monitor, DBPPlatform platform, DBWHandlerConfiguration configuration, DBPConnectionConfiguration connectionInfo) throws DBException, IOException {
    Map<String, String> properties = configuration.getProperties();
    String implId = properties.get(SSHConstants.PROP_IMPLEMENTATION);
    if (CommonUtils.isEmpty(implId)) {
        // Backward compatibility
        implId = DEF_IMPLEMENTATION;
    }
    try {
        SSHImplementationDescriptor implDesc = SSHImplementationRegistry.getInstance().getDescriptor(implId);
        if (implDesc == null) {
            implDesc = SSHImplementationRegistry.getInstance().getDescriptor(DEF_IMPLEMENTATION);
        }
        implementation = implDesc.getImplClass().createInstance(SSHImplementation.class);
    } catch (Throwable e) {
        throw new DBException("Can't create SSH tunnel implementation", e);
    }
    return implementation.initTunnel(monitor, platform, configuration, connectionInfo);
}
Also used : SSHImplementationDescriptor(org.jkiss.dbeaver.model.net.ssh.registry.SSHImplementationDescriptor) DBException(org.jkiss.dbeaver.DBException)

Example 5 with SSHImplementationDescriptor

use of org.jkiss.dbeaver.model.net.ssh.registry.SSHImplementationDescriptor in project dbeaver by serge-rider.

the class SSHTunnelConfiguratorUI method saveSettings.

@Override
public void saveSettings(DBWHandlerConfiguration configuration) {
    configuration.setProperty(DBWHandlerConfiguration.PROP_HOST, hostText.getText().trim());
    configuration.setProperty(DBWHandlerConfiguration.PROP_PORT, portText.getSelection());
    switch(authMethodCombo.getSelectionIndex()) {
        case 0:
            configuration.setProperty(SSHConstants.PROP_AUTH_TYPE, SSHConstants.AuthType.PASSWORD.name());
            break;
        case 1:
            configuration.setProperty(SSHConstants.PROP_AUTH_TYPE, SSHConstants.AuthType.PUBLIC_KEY.name());
            break;
        case 2:
            configuration.setProperty(SSHConstants.PROP_AUTH_TYPE, SSHConstants.AuthType.AGENT.name());
            break;
    }
    configuration.setProperty(SSHConstants.PROP_KEY_PATH, privateKeyText.getText().trim());
    configuration.setUserName(userNameText.getText().trim());
    configuration.setPassword(passwordText.getText());
    configuration.setSavePassword(savePasswordCheckbox.getSelection());
    String implLabel = tunnelImplCombo.getText();
    for (SSHImplementationDescriptor it : SSHImplementationRegistry.getInstance().getDescriptors()) {
        if (it.getLabel().equals(implLabel)) {
            configuration.setProperty(SSHConstants.PROP_IMPLEMENTATION, it.getId());
            break;
        }
    }
    configuration.setProperty(SSHConstants.PROP_LOCAL_HOST, localHostText.getText().trim());
    int localPort = localPortSpinner.getSelection();
    if (localPort <= 0) {
        configuration.setProperty(SSHConstants.PROP_LOCAL_PORT, null);
    } else {
        configuration.setProperty(SSHConstants.PROP_LOCAL_PORT, localPort);
    }
    configuration.setProperty(SSHConstants.PROP_REMOTE_HOST, remoteHostText.getText().trim());
    int remotePort = remotePortSpinner.getSelection();
    if (remotePort <= 0) {
        configuration.setProperty(SSHConstants.PROP_REMOTE_PORT, null);
    } else {
        configuration.setProperty(SSHConstants.PROP_REMOTE_PORT, remotePort);
    }
    int kaInterval = keepAliveText.getSelection();
    if (kaInterval <= 0) {
        configuration.setProperty(SSHConstants.PROP_ALIVE_INTERVAL, null);
    } else {
        configuration.setProperty(SSHConstants.PROP_ALIVE_INTERVAL, kaInterval);
    }
    int conTimeout = tunnelTimeout.getSelection();
    if (conTimeout != 0 && conTimeout != SSHConstants.DEFAULT_CONNECT_TIMEOUT) {
        configuration.setProperty(SSHConstants.PROP_CONNECT_TIMEOUT, conTimeout);
    }
}
Also used : SSHImplementationDescriptor(org.jkiss.dbeaver.model.net.ssh.registry.SSHImplementationDescriptor)

Aggregations

SSHImplementationDescriptor (org.jkiss.dbeaver.model.net.ssh.registry.SSHImplementationDescriptor)10 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)3 SelectionEvent (org.eclipse.swt.events.SelectionEvent)3 GridData (org.eclipse.swt.layout.GridData)3 GridLayout (org.eclipse.swt.layout.GridLayout)3 DBException (org.jkiss.dbeaver.DBException)3 TextWithOpenFile (org.jkiss.dbeaver.ui.controls.TextWithOpenFile)3 DBPDataSourceContainer (org.jkiss.dbeaver.model.DBPDataSourceContainer)2 DataSourceVariableResolver (org.jkiss.dbeaver.model.connection.DataSourceVariableResolver)2 DBWHandlerConfiguration (org.jkiss.dbeaver.model.net.DBWHandlerConfiguration)2 SSHConstants (org.jkiss.dbeaver.model.net.ssh.SSHConstants)2 VariablesHintLabel (org.jkiss.dbeaver.ui.controls.VariablesHintLabel)2