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);
}
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;
}
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);
}
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);
}
}
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);
}
}
}
Aggregations