Subject: [PATCH] Fix #22497: Add a setting opposite to proxy.exceptions
---
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(); |
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 | /** |
| | 47 | * Property key for hosts that should be proxied (if this is set, only specified hosts should be proxied) |
| | 48 | * @since xxx |
| | 49 | */ |
| | 50 | public static final String PROXY_INCLUDES = "proxy.includes.hosts"; |
| 46 | 51 | |
| 47 | 52 | private static final List<Proxy> NO_PROXY_LIST = Collections.singletonList(Proxy.NO_PROXY); |
| 48 | 53 | |
| … |
… |
|
| 86 | 91 | private final Set<String> errorResources = new HashSet<>(); |
| 87 | 92 | private final Set<String> errorMessages = new HashSet<>(); |
| 88 | 93 | private Set<String> proxyExceptions; |
| | 94 | private Set<String> proxyIncludes; |
| 89 | 95 | |
| 90 | 96 | /** |
| 91 | 97 | * A typical example is: |
| … |
… |
|
| 161 | 167 | } |
| 162 | 168 | } |
| 163 | 169 | proxyExceptions = new HashSet<>( |
| 164 | | Config.getPref().getList(PROXY_EXCEPTIONS, |
| 165 | | Arrays.asList("localhost", IPV4_LOOPBACK, IPV6_LOOPBACK)) |
| | 170 | Config.getPref().getList(PROXY_EXCEPTIONS, |
| | 171 | Arrays.asList("localhost", IPV4_LOOPBACK, IPV6_LOOPBACK)) |
| 166 | 172 | ); |
| | 173 | proxyIncludes = new HashSet<>( |
| | 174 | Config.getPref().getList(PROXY_INCLUDES, |
| | 175 | Collections.emptyList()) |
| | 176 | ); |
| 167 | 177 | } |
| 168 | 178 | |
| 169 | 179 | @Override |
| … |
… |
|
| 214 | 224 | |
| 215 | 225 | @Override |
| 216 | 226 | public List<Proxy> select(URI uri) { |
| 217 | | if (uri != null && proxyExceptions.contains(uri.getHost())) { |
| | 227 | // This is specified in ProxySelector#select, "@throws IllegalArgumentException if the argument is null" |
| | 228 | if (uri == null) { |
| | 229 | throw new IllegalArgumentException("URI cannot be null"); |
| | 230 | } |
| | 231 | if (proxyExceptions.contains(uri.getHost())) { |
| 218 | 232 | return NO_PROXY_LIST; |
| 219 | 233 | } |
| 220 | | switch(proxyPolicy) { |
| | 234 | switch (proxyPolicy) { |
| 221 | 235 | case USE_SYSTEM_SETTINGS: |
| 222 | 236 | if (!jvmWillUseSystemProxies) { |
| 223 | | Logging.warn(tr("The JVM is not configured to lookup proxies from the system settings. "+ |
| | 237 | Logging.warn(tr("The JVM is not configured to lookup proxies from the system settings. " + |
| 224 | 238 | "The property ''java.net.useSystemProxies'' was missing at startup time. Will not use a proxy.")); |
| 225 | 239 | return NO_PROXY_LIST; |
| 226 | 240 | } |
| | 241 | if (!proxyIncludes.isEmpty() && !proxyIncludes.contains(uri.getHost())) { |
| | 242 | return NO_PROXY_LIST; |
| | 243 | } |
| 227 | 244 | // delegate to the former proxy selector |
| 228 | 245 | return delegate.select(uri); |
| 229 | 246 | case NO_PROXY: |
| 230 | 247 | return NO_PROXY_LIST; |
| 231 | 248 | case USE_HTTP_PROXY: |
| 232 | | if (httpProxySocketAddress == null) |
| | 249 | if (httpProxySocketAddress == null || (!proxyIncludes.isEmpty() && !proxyIncludes.contains(uri.getHost()))) { |
| 233 | 250 | return NO_PROXY_LIST; |
| | 251 | } |
| 234 | 252 | return Collections.singletonList(new Proxy(Type.HTTP, httpProxySocketAddress)); |
| 235 | 253 | case USE_SOCKS_PROXY: |
| 236 | | if (socksProxySocketAddress == null) |
| | 254 | if (socksProxySocketAddress == null || (!proxyIncludes.isEmpty() && !proxyIncludes.contains(uri.getHost()))) { |
| 237 | 255 | return NO_PROXY_LIST; |
| | 256 | } |
| 238 | 257 | return Collections.singletonList(new Proxy(Type.SOCKS, socksProxySocketAddress)); |
| 239 | 258 | } |
| 240 | 259 | // should not happen |
| 241 | | return null; |
| | 260 | return Collections.emptyList(); |
| 242 | 261 | } |
| 243 | 262 | } |