Search in sources :

Example 36 with DBWHandlerConfiguration

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

the class GlobalProxySelector method select.

@Override
public List<Proxy> select(URI uri) {
    String scheme = uri.getScheme();
    if (CommonUtils.isEmpty(scheme)) {
        return parent.select(uri);
    }
    if (scheme.startsWith("http")) {
    // 1. Check for drivers download proxy
    }
    if (SocksConstants.SOCKET_SCHEME.equals(scheme)) {
        // 2. Check for connections' proxy config
        DBCExecutionContext activeContext = DBExecUtils.findConnectionContext(uri.getHost(), uri.getPort(), uri.getPath());
        if (activeContext != null) {
            List<Proxy> proxies = null;
            DBPDataSourceContainer container = activeContext.getDataSource().getContainer();
            for (DBWHandlerConfiguration networkHandler : container.getConnectionConfiguration().getDeclaredHandlers()) {
                if (networkHandler.isEnabled() && networkHandler.getType() == DBWHandlerType.PROXY) {
                    Map<String, String> proxyProps = networkHandler.getProperties();
                    String proxyHost = proxyProps.get(SocksConstants.PROP_HOST);
                    String proxyPort = proxyProps.get(SocksConstants.PROP_PORT);
                    if (!CommonUtils.isEmpty(proxyHost)) {
                        int portNumber = SocksConstants.DEFAULT_SOCKS_PORT;
                        if (!CommonUtils.isEmpty(proxyPort)) {
                            try {
                                portNumber = Integer.parseInt(proxyPort);
                            } catch (NumberFormatException e) {
                                log.warn("Bad proxy port number", e);
                            }
                        }
                        InetSocketAddress proxyAddr = new InetSocketAddress(proxyHost, portNumber);
                        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 parent.select(uri);
}
Also used : DBCExecutionContext(org.jkiss.dbeaver.model.exec.DBCExecutionContext) DBWHandlerConfiguration(org.jkiss.dbeaver.model.net.DBWHandlerConfiguration) DBPDataSourceContainer(org.jkiss.dbeaver.model.DBPDataSourceContainer)

Example 37 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, String purpose, DBPConnectionConfiguration connectionInfo) throws DBCException {
    Map<String, String> props = new LinkedHashMap<>(PostgreDataSourceProvider.getConnectionsProps());
    final DBWHandlerConfiguration sslConfig = getContainer().getActualConnectionConfiguration().getDeclaredHandler(PostgreConstants.HANDLER_SSL);
    if (sslConfig != null && sslConfig.isEnabled()) {
        try {
            initSSL(props, sslConfig);
        } catch (Exception e) {
            throw new DBCException("Error configuring SSL certificates", e);
        }
    }
    return props;
}
Also used : DBWHandlerConfiguration(org.jkiss.dbeaver.model.net.DBWHandlerConfiguration) SQLException(java.sql.SQLException) DBException(org.jkiss.dbeaver.DBException)

Example 38 with DBWHandlerConfiguration

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

the class GlobalProxySelector method select.

@Override
public List<Proxy> select(URI uri) {
    String scheme = uri.getScheme();
    if (CommonUtils.isEmpty(scheme)) {
        return parent.select(uri);
    }
    if (scheme.startsWith("http")) {
    // 1. Check for drivers download proxy
    }
    if (SocksConstants.SOCKET_SCHEME.equals(scheme)) {
        // 2. Check for connections' proxy config
        DBCExecutionContext activeContext = DBExecUtils.findConnectionContext(uri.getHost(), uri.getPort(), uri.getPath());
        if (activeContext != null) {
            List<Proxy> proxies = null;
            DBPDataSourceContainer container = activeContext.getDataSource().getContainer();
            for (DBWHandlerConfiguration networkHandler : container.getConnectionConfiguration().getDeclaredHandlers()) {
                if (networkHandler.isEnabled() && networkHandler.getType() == DBWHandlerType.PROXY) {
                    Map<String, String> proxyProps = networkHandler.getProperties();
                    String proxyHost = proxyProps.get(SocksConstants.PROP_HOST);
                    String proxyPort = proxyProps.get(SocksConstants.PROP_PORT);
                    if (!CommonUtils.isEmpty(proxyHost)) {
                        int portNumber = SocksConstants.DEFAULT_SOCKS_PORT;
                        if (!CommonUtils.isEmpty(proxyPort)) {
                            try {
                                portNumber = Integer.parseInt(proxyPort);
                            } catch (NumberFormatException e) {
                                log.warn("Bad proxy port number", e);
                            }
                        }
                        InetSocketAddress proxyAddr = new InetSocketAddress(proxyHost, portNumber);
                        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 parent.select(uri);
}
Also used : DBCExecutionContext(org.jkiss.dbeaver.model.exec.DBCExecutionContext) DBWHandlerConfiguration(org.jkiss.dbeaver.model.net.DBWHandlerConfiguration) DBPDataSourceContainer(org.jkiss.dbeaver.model.DBPDataSourceContainer)

Example 39 with DBWHandlerConfiguration

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

the class ConnectionPageNetwork method enableHandlerContent.

protected void enableHandlerContent(NetworkHandlerDescriptor descriptor) {
    HandlerBlock handlerBlock = configurations.get(descriptor);
    DBWHandlerConfiguration handlerConfiguration = handlerBlock.loadedConfigs.get(wizard.getPageSettings().getActiveDataSource().getId());
    handlerBlock.useHandlerCheck.setSelection(handlerConfiguration.isEnabled());
    if (handlerConfiguration.isEnabled()) {
        if (handlerBlock.blockEnableState != null) {
            handlerBlock.blockEnableState.restore();
            handlerBlock.blockEnableState = null;
        }
    } else if (handlerBlock.blockEnableState == null) {
        handlerBlock.blockEnableState = ControlEnableState.disable(handlerBlock.blockControl);
    }
}
Also used : DBWHandlerConfiguration(org.jkiss.dbeaver.model.net.DBWHandlerConfiguration)

Example 40 with DBWHandlerConfiguration

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

the class PrefPageProjectNetworkProfiles method saveHandlerSettings.

/**
 * Saves state of UI controls to handler configuration
 */
private void saveHandlerSettings() {
    if (selectedProfile == null) {
        return;
    }
    for (TabItem handlerTab : handlersFolder.getItems()) {
        NetworkHandlerDescriptor handler = (NetworkHandlerDescriptor) handlerTab.getData();
        HandlerBlock handlerBlock = configurations.get(handler);
        DBWHandlerConfiguration handlerConfiguration = handlerBlock.loadedConfigs.get(selectedProfile);
        if (handlerBlock.useHandlerCheck.getSelection()) {
            if (handlerConfiguration == null) {
                handlerConfiguration = new DBWHandlerConfiguration(handler, null);
            }
            handlerConfiguration.setProperties(Collections.emptyMap());
            handlerBlock.configurator.saveSettings(handlerConfiguration);
        }
    }
}
Also used : DBWHandlerConfiguration(org.jkiss.dbeaver.model.net.DBWHandlerConfiguration) NetworkHandlerDescriptor(org.jkiss.dbeaver.registry.network.NetworkHandlerDescriptor)

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