Ticket #22497: Include_proxy_hosts.patch
File Include_proxy_hosts.patch, 9.8 KB (added by , 2 years ago) |
---|
-
src/org/openstreetmap/josm/gui/preferences/server/ProxyPreferencesPanel.java
IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 diff --git a/src/org/openstreetmap/josm/gui/preferences/server/ProxyPreferencesPanel.java b/src/org/openstreetmap/josm/gui/preferences/server/ProxyPreferencesPanel.java
a b 19 19 import java.util.EnumMap; 20 20 import java.util.Map; 21 21 import java.util.Optional; 22 import java.util.ArrayList; 22 23 23 24 import javax.swing.BorderFactory; 24 25 import javax.swing.Box; … … 31 32 import org.openstreetmap.josm.gui.widgets.JosmPasswordField; 32 33 import org.openstreetmap.josm.gui.widgets.JosmTextField; 33 34 import org.openstreetmap.josm.gui.widgets.VerticallyScrollablePanel; 35 import org.openstreetmap.josm.gui.widgets.EditableList; 34 36 import org.openstreetmap.josm.io.DefaultProxySelector; 35 37 import org.openstreetmap.josm.io.ProxyPolicy; 36 38 import org.openstreetmap.josm.io.auth.CredentialsAgent; … … 64 66 private final JosmTextField tfProxySocksPort = new JosmTextField(5); 65 67 private final JosmTextField tfProxyHttpUser = new JosmTextField(20); 66 68 private final JosmPasswordField tfProxyHttpPassword = new JosmPasswordField(20); 69 private final EditableList tfExceptionHosts = new EditableList(tr("No proxy for")); 70 private final EditableList tfIncludeHosts = new EditableList(tr("Proxy only for")); 67 71 68 72 private JPanel pnlHttpProxyConfigurationPanel; 69 73 private JPanel pnlSocksProxyConfigurationPanel; 74 private JPanel pnlExceptionIncludesHostsProxyConfigurationPanel; 70 75 71 76 /** 72 77 * Builds the panel for the HTTP proxy configuration … … 179 184 return pnl; 180 185 } 181 186 187 protected final JPanel buildExceptionIncludesHostsProxyConfigurationPanel() { 188 JPanel pnl = new AutoSizePanel(); 189 GridBagConstraints gc = new GridBagConstraints(); 190 gc.anchor = GridBagConstraints.LINE_START; 191 gc.insets = new Insets(5, 5, 0, 0); 192 gc.weightx = 0.0; 193 pnl.add(new JLabel(tr("No proxy for (hosts):")), gc); 194 195 gc.gridx = 1; 196 gc.weightx = 0.0; 197 gc.fill = GridBagConstraints.NONE; 198 pnl.add(new JLabel(tr("Proxy only for (hosts):")), gc); 199 200 gc.gridy = 1; 201 gc.gridx = 0; 202 gc.weightx = 1.0; 203 gc.fill = HORIZONTAL; 204 tfExceptionHosts.setMinimumSize(tfExceptionHosts.getPreferredSize()); 205 pnl.add(tfExceptionHosts, gc); 206 207 gc.gridx = 1; 208 gc.weightx = 1.0; 209 gc.fill = HORIZONTAL; 210 tfIncludeHosts.setMinimumSize(tfIncludeHosts.getPreferredSize()); 211 pnl.add(tfIncludeHosts, gc); 212 213 // add an extra spacer, otherwise the layout is broken 214 gc.gridy = 2; 215 gc.gridx = 0; 216 gc.gridwidth = 2; 217 gc.fill = GridBagConstraints.BOTH; 218 gc.weightx = 1.0; 219 gc.weighty = 1.0; 220 pnl.add(new JPanel(), gc); 221 return pnl; 222 } 223 182 224 protected final JPanel buildProxySettingsPanel() { 183 225 JPanel pnl = new JPanel(new GridBagLayout()); 184 226 … … 217 259 218 260 pnl.add(Box.createVerticalGlue(), GBC.eol().fill()); 219 261 262 // the panel with the exception and includes hosts 263 pnlExceptionIncludesHostsProxyConfigurationPanel = buildExceptionIncludesHostsProxyConfigurationPanel(); 264 pnl.add(pnlExceptionIncludesHostsProxyConfigurationPanel, GBC.eop().fill(HORIZONTAL)); 265 266 pnl.add(Box.createVerticalGlue(), GBC.eol().fill()); 267 220 268 return pnl; 221 269 } 222 270 … … 238 286 tfProxyHttpPort.setText(pref.get(DefaultProxySelector.PROXY_HTTP_PORT, "")); 239 287 tfProxySocksHost.setText(pref.get(DefaultProxySelector.PROXY_SOCKS_HOST, "")); 240 288 tfProxySocksPort.setText(pref.get(DefaultProxySelector.PROXY_SOCKS_PORT, "")); 289 tfExceptionHosts.setItems(pref.getList(DefaultProxySelector.PROXY_EXCEPTIONS, new ArrayList<String>())); 290 tfIncludeHosts.setItems(pref.getList(DefaultProxySelector.PROXY_INCLUDES, new ArrayList<String>())); 241 291 242 292 if (pp == ProxyPolicy.USE_SYSTEM_SETTINGS && !DefaultProxySelector.willJvmRetrieveSystemProxies()) { 243 293 Logging.warn(tr("JOSM is configured to use proxies from the system setting, but the JVM is not configured to retrieve them. " + … … 277 327 } 278 328 279 329 rbProxyPolicy.get(ProxyPolicy.USE_SYSTEM_SETTINGS).setEnabled(DefaultProxySelector.willJvmRetrieveSystemProxies()); 330 331 boolean proxyEnabled = !rbProxyPolicy.get(ProxyPolicy.NO_PROXY).isSelected(); 332 for (Component c : pnlExceptionIncludesHostsProxyConfigurationPanel.getComponents()) { 333 c.setEnabled(proxyEnabled); 334 } 280 335 } 281 336 282 337 class ProxyPolicyChangeListener implements ItemListener { … … 311 366 pref.put(DefaultProxySelector.PROXY_HTTP_PORT, tfProxyHttpPort.getText()); 312 367 pref.put(DefaultProxySelector.PROXY_SOCKS_HOST, tfProxySocksHost.getText()); 313 368 pref.put(DefaultProxySelector.PROXY_SOCKS_PORT, tfProxySocksPort.getText()); 369 pref.putList(DefaultProxySelector.PROXY_EXCEPTIONS, tfExceptionHosts.getItems()); 370 pref.putList(DefaultProxySelector.PROXY_INCLUDES, tfIncludeHosts.getItems()); 371 314 372 315 373 // update the proxy selector 316 374 ProxySelector selector = ProxySelector.getDefault(); -
src/org/openstreetmap/josm/io/DefaultProxySelector.java
IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 diff --git a/src/org/openstreetmap/josm/io/DefaultProxySelector.java b/src/org/openstreetmap/josm/io/DefaultProxySelector.java
a b 43 43 public static final String PROXY_PASS = "proxy.pass"; 44 44 /** Property key for proxy exceptions list */ 45 45 public static final String PROXY_EXCEPTIONS = "proxy.exceptions"; 46 /** Property key for proxy include list */ 47 public static final String PROXY_INCLUDES = "proxy.includes"; 46 48 47 49 private static final List<Proxy> NO_PROXY_LIST = Collections.singletonList(Proxy.NO_PROXY); 48 50 … … 86 88 private final Set<String> errorResources = new HashSet<>(); 87 89 private final Set<String> errorMessages = new HashSet<>(); 88 90 private Set<String> proxyExceptions; 91 private Set<String> proxyIncludes; 89 92 90 93 /** 91 94 * A typical example is: … … 161 164 } 162 165 } 163 166 proxyExceptions = new HashSet<>( 164 Config.getPref().getList(PROXY_EXCEPTIONS,165 Arrays.asList("localhost", IPV4_LOOPBACK, IPV6_LOOPBACK))167 Config.getPref().getList(PROXY_EXCEPTIONS, 168 Arrays.asList("localhost", IPV4_LOOPBACK, IPV6_LOOPBACK)) 166 169 ); 170 proxyIncludes = new HashSet<>( 171 Config.getPref().getList(PROXY_INCLUDES, 172 Arrays.asList()) 173 ); 167 174 } 168 175 169 176 @Override … … 217 224 if (uri != null && proxyExceptions.contains(uri.getHost())) { 218 225 return NO_PROXY_LIST; 219 226 } 220 switch(proxyPolicy) { 221 case USE_SYSTEM_SETTINGS: 222 if (!jvmWillUseSystemProxies) { 223 Logging.warn(tr("The JVM is not configured to lookup proxies from the system settings. "+ 224 "The property ''java.net.useSystemProxies'' was missing at startup time. Will not use a proxy.")); 225 return NO_PROXY_LIST; 226 } 227 // delegate to the former proxy selector 228 return delegate.select(uri); 229 case NO_PROXY: 230 return NO_PROXY_LIST; 231 case USE_HTTP_PROXY: 232 if (httpProxySocketAddress == null) 233 return NO_PROXY_LIST; 234 return Collections.singletonList(new Proxy(Type.HTTP, httpProxySocketAddress)); 235 case USE_SOCKS_PROXY: 236 if (socksProxySocketAddress == null) 237 return NO_PROXY_LIST; 238 return Collections.singletonList(new Proxy(Type.SOCKS, socksProxySocketAddress)); 227 switch (proxyPolicy) { 228 case USE_SYSTEM_SETTINGS: 229 if (!jvmWillUseSystemProxies) { 230 Logging.warn(tr("The JVM is not configured to lookup proxies from the system settings. " + 231 "The property ''java.net.useSystemProxies'' was missing at startup time. Will not use a proxy.")); 232 return NO_PROXY_LIST; 233 } 234 if (!proxyIncludes.isEmpty() && !proxyIncludes.contains(uri.getHost())){ 235 return NO_PROXY_LIST; 236 } 237 // delegate to the former proxy selector 238 return delegate.select(uri); 239 case NO_PROXY: 240 return NO_PROXY_LIST; 241 case USE_HTTP_PROXY: 242 if (httpProxySocketAddress == null) 243 return NO_PROXY_LIST; 244 if (!proxyIncludes.isEmpty() && !proxyIncludes.contains(uri.getHost())){ 245 return NO_PROXY_LIST; 246 } 247 return Collections.singletonList(new Proxy(Type.HTTP, httpProxySocketAddress)); 248 case USE_SOCKS_PROXY: 249 if (socksProxySocketAddress == null) 250 return NO_PROXY_LIST; 251 if (!proxyIncludes.isEmpty() && !proxyIncludes.contains(uri.getHost())){ 252 return NO_PROXY_LIST; 253 } 254 return Collections.singletonList(new Proxy(Type.SOCKS, socksProxySocketAddress)); 239 255 } 240 256 // should not happen 241 257 return null;