Search in sources :

Example 56 with DBWHandlerConfiguration

use of org.jkiss.dbeaver.model.net.DBWHandlerConfiguration in project dbeaver by serge-rider.

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 57 with DBWHandlerConfiguration

use of org.jkiss.dbeaver.model.net.DBWHandlerConfiguration in project dbeaver by dbeaver.

the class DBExecUtils method startContextInitiation.

public static void startContextInitiation(DBPDataSourceContainer context) {
    ACTIVE_CONTEXT.set(context);
    synchronized (ACTIVE_CONTEXTS) {
        ACTIVE_CONTEXTS.add(context);
    }
    // Set proxy auth (if required)
    // Note: authenticator may be changed by Eclipse frameword on startup or later.
    // That's why we set new default authenticator on connection initiation
    boolean hasProxy = false;
    for (DBWHandlerConfiguration handler : context.getConnectionConfiguration().getHandlers()) {
        if (handler.isEnabled() && handler.getType() == DBWHandlerType.PROXY) {
            hasProxy = true;
            break;
        }
    }
    if (hasProxy) {
        Authenticator.setDefault(new GlobalProxyAuthenticator());
    }
}
Also used : DBWHandlerConfiguration(org.jkiss.dbeaver.model.net.DBWHandlerConfiguration) GlobalProxyAuthenticator(org.jkiss.dbeaver.runtime.net.GlobalProxyAuthenticator)

Example 58 with DBWHandlerConfiguration

use of org.jkiss.dbeaver.model.net.DBWHandlerConfiguration in project dbeaver by dbeaver.

the class DBPConnectionConfiguration method resolveDynamicVariables.

public void resolveDynamicVariables(IVariableResolver variableResolver) {
    hostName = GeneralUtils.replaceVariables(hostName, variableResolver);
    hostPort = GeneralUtils.replaceVariables(hostPort, variableResolver);
    serverName = GeneralUtils.replaceVariables(serverName, variableResolver);
    databaseName = GeneralUtils.replaceVariables(databaseName, variableResolver);
    userName = GeneralUtils.replaceVariables(userName, variableResolver);
    userPassword = GeneralUtils.replaceVariables(userPassword, variableResolver);
    url = GeneralUtils.replaceVariables(url, variableResolver);
    resolveDynamicVariablesInMap(this.properties, variableResolver);
    resolveDynamicVariablesInMap(this.authProperties, variableResolver);
    resolveDynamicVariablesInMap(this.providerProperties, variableResolver);
    for (DBWHandlerConfiguration handler : handlers) {
        if (handler.isEnabled()) {
            handler.resolveDynamicVariables(variableResolver);
        }
    }
    bootstrap.resolveDynamicVariables(variableResolver);
}
Also used : DBWHandlerConfiguration(org.jkiss.dbeaver.model.net.DBWHandlerConfiguration)

Example 59 with DBWHandlerConfiguration

use of org.jkiss.dbeaver.model.net.DBWHandlerConfiguration in project dbeaver by dbeaver.

the class DataSourceSerializerModern method parseNetworkHandlerConfig.

@Nullable
private DBWHandlerConfiguration parseNetworkHandlerConfig(@Nullable DataSourceDescriptor dataSource, @Nullable DBWNetworkProfile profile, @NotNull Map.Entry<String, Map<String, Object>> handlerObject) {
    String handlerId = handlerObject.getKey();
    Map<String, Object> handlerCfg = handlerObject.getValue();
    NetworkHandlerDescriptor handlerDescriptor = NetworkHandlerRegistry.getInstance().getDescriptor(handlerId);
    if (handlerDescriptor == null) {
        log.warn("Can't find network handler '" + handlerId + "'");
        return null;
    } else {
        DBWHandlerConfiguration curNetworkHandler = new DBWHandlerConfiguration(handlerDescriptor, dataSource);
        curNetworkHandler.setEnabled(JSONUtils.getBoolean(handlerCfg, RegistryConstants.ATTR_ENABLED));
        curNetworkHandler.setSavePassword(JSONUtils.getBoolean(handlerCfg, RegistryConstants.ATTR_SAVE_PASSWORD));
        if (!passwordReadCanceled) {
            final SecureCredentials creds = readSecuredCredentials(dataSource, profile, "network/" + handlerId + (profile == null ? "" : "/profile/" + profile.getProfileName()));
            curNetworkHandler.setUserName(creds.getUserName());
            if (curNetworkHandler.isSavePassword()) {
                curNetworkHandler.setPassword(creds.getUserPassword());
            }
        }
        {
            // Still try to read credentials directly from configuration (#6564)
            String userName = JSONUtils.getString(handlerCfg, RegistryConstants.ATTR_USER);
            if (!CommonUtils.isEmpty(userName))
                curNetworkHandler.setUserName(userName);
            String userPassword = JSONUtils.getString(handlerCfg, RegistryConstants.ATTR_PASSWORD);
            if (!CommonUtils.isEmpty(userPassword))
                curNetworkHandler.setPassword(userPassword);
        }
        Map<String, Object> properties = JSONUtils.deserializeProperties(handlerCfg, RegistryConstants.TAG_PROPERTIES);
        if (properties != null) {
            curNetworkHandler.setProperties(properties);
        }
        return curNetworkHandler;
    }
}
Also used : DBWHandlerConfiguration(org.jkiss.dbeaver.model.net.DBWHandlerConfiguration) NetworkHandlerDescriptor(org.jkiss.dbeaver.registry.network.NetworkHandlerDescriptor) Nullable(org.jkiss.code.Nullable)

Example 60 with DBWHandlerConfiguration

use of org.jkiss.dbeaver.model.net.DBWHandlerConfiguration in project dbeaver by dbeaver.

the class PostgreDataSource method getInternalConnectionProperties.

@Override
protected Map<String, String> getInternalConnectionProperties(DBRProgressMonitor monitor, DBPDriver driver, JDBCExecutionContext context, String purpose, DBPConnectionConfiguration connectionInfo) throws DBCException {
    Map<String, String> props = new LinkedHashMap<>(PostgreDataSourceProvider.getConnectionsProps());
    final DBWHandlerConfiguration sslConfig = getContainer().getActualConnectionConfiguration().getHandler(PostgreConstants.HANDLER_SSL);
    if (sslConfig != null && sslConfig.isEnabled()) {
        try {
            boolean useProxy = sslConfig.getBooleanProperty(PostgreConstants.PROP_SSL_PROXY);
            if (useProxy) {
                initProxySSL(props, sslConfig);
            } else {
                initServerSSL(props, sslConfig);
            }
        } catch (Exception e) {
            throw new DBCException("Error configuring SSL certificates", e);
        }
    } else {
        getServerType().initDefaultSSLConfig(connectionInfo, props);
    }
    return props;
}
Also used : DBWHandlerConfiguration(org.jkiss.dbeaver.model.net.DBWHandlerConfiguration) SQLException(java.sql.SQLException) DBException(org.jkiss.dbeaver.DBException)

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