use of org.jkiss.dbeaver.model.net.DBWHandlerConfiguration in project dbeaver by serge-rider.
the class ConnectionPageNetwork method createHandlerTab.
private void createHandlerTab(final NetworkHandlerDescriptor descriptor) throws DBException {
IObjectPropertyConfigurator<DBWHandlerConfiguration> configurator;
try {
configurator = descriptor.createConfigurator();
} catch (DBException e) {
log.error("Can't create network configurator '" + descriptor.getId() + "'", e);
return;
}
TabItem tabItem = new TabItem(handlersFolder, SWT.NONE);
tabItem.setText(descriptor.getLabel());
tabItem.setToolTipText(descriptor.getDescription());
Composite composite = new Composite(handlersFolder, SWT.NONE);
tabItem.setControl(composite);
composite.setLayout(new GridLayout(1, false));
composite.setLayoutData(new GridData(GridData.FILL_BOTH));
final Button useHandlerCheck = UIUtils.createCheckbox(composite, NLS.bind(CoreMessages.dialog_tunnel_checkbox_use_handler, descriptor.getLabel()), false);
useHandlerCheck.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
HandlerBlock handlerBlock = configurations.get(descriptor);
DBWHandlerConfiguration handlerConfiguration = handlerBlock.loadedConfigs.get(wizard.getPageSettings().getActiveDataSource().getId());
handlerConfiguration.setEnabled(useHandlerCheck.getSelection());
enableHandlerContent(descriptor);
}
});
Composite handlerComposite = UIUtils.createPlaceholder(composite, 1);
configurations.put(descriptor, new HandlerBlock(configurator, handlerComposite, useHandlerCheck, tabItem));
handlerComposite.setLayoutData(new GridData(GridData.FILL_BOTH));
configurator.createControl(handlerComposite);
}
use of org.jkiss.dbeaver.model.net.DBWHandlerConfiguration in project dbeaver by serge-rider.
the class ConnectionPageNetwork method saveConfigurations.
void saveConfigurations(DataSourceDescriptor dataSource) {
boolean foundHandlers = false;
java.util.List<DBWHandlerConfiguration> handlers = new ArrayList<>();
for (HandlerBlock handlerBlock : configurations.values()) {
DBWHandlerConfiguration configuration = handlerBlock.loadedConfigs.get(dataSource.getId());
if (configuration != null) {
foundHandlers = true;
handlerBlock.configurator.saveSettings(configuration);
handlers.add(configuration);
}
}
if (foundHandlers) {
dataSource.getConnectionConfiguration().setHandlers(handlers);
}
}
use of org.jkiss.dbeaver.model.net.DBWHandlerConfiguration in project dbeaver by serge-rider.
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);
}
}
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);
}
Aggregations