19 package com.basistech.df.cybertriage.autopsy.ctapi;
23 import java.util.logging.Level;
24 import java.util.logging.Logger;
25 import java.util.prefs.PreferenceChangeListener;
26 import java.util.prefs.Preferences;
27 import org.netbeans.api.keyring.Keyring;
28 import org.openide.util.*;
29 import org.openide.util.lookup.ServiceProvider;
49 public static final String
DIRECT =
"DIRECT";
50 public static final String
PAC =
"PAC";
136 int type =
getPreferences ().getInt (PROXY_TYPE, AUTO_DETECT_PROXY);
137 if (AUTO_DETECT_PROXY == type) {
187 return getPreferences ().getBoolean (USE_PROXY_AUTHENTICATION,
false);
191 return getPreferences ().getBoolean (USE_PROXY_ALL_PROTOCOLS,
false);
199 String old =
getPreferences().get(PROXY_AUTHENTICATION_PASSWORD, null);
204 char[] pwd = Keyring.read(PROXY_AUTHENTICATION_PASSWORD);
205 return pwd != null ? pwd :
new char[0];
211 NbBundle.getMessage(
ProxySettings.class,
"ProxySettings.password.description"));
223 if (presetNonProxyHosts == null) {
224 presetNonProxyHosts = System.getProperty (
"http.nonProxyHosts",
"");
235 StringBuilder sb =
new StringBuilder();
236 for (String n : proxies) {
244 if (sb.length() > 0 && sb.charAt(sb.length() - 1) !=
'|') {
245 if (!n.startsWith(
"|")) {
251 return sb.toString();
255 String fromSystem = systemPreset.replace (
";",
"|").replace (
",",
"|");
257 if (Utilities.isWindows ()) {
260 final String staticNonProxyHosts = NbBundle.getMessage(
ProxySettings.class,
"StaticNonProxyHosts");
261 String nonProxy =
concatProxies(fromUser, fromSystem, staticNonProxyHosts);
264 localhost = InetAddress.getLocalHost().getHostName();
265 if (!
"localhost".equals(localhost)) {
266 nonProxy = nonProxy +
"|" + localhost;
272 catch (UnknownHostException e) {
301 StringTokenizer st =
new StringTokenizer(hosts,
",");
302 StringBuilder nonProxyHosts =
new StringBuilder();
303 while (st.hasMoreTokens()) {
304 String h = st.nextToken().trim();
305 if (h.length() == 0) {
308 if (nonProxyHosts.length() > 0) {
309 nonProxyHosts.append(
"|");
311 nonProxyHosts.append(h);
313 st =
new StringTokenizer (nonProxyHosts.toString(),
"|");
314 Set<String> set =
new HashSet<String> ();
315 StringBuilder compactedProxyHosts =
new StringBuilder();
316 while (st.hasMoreTokens ()) {
317 String t = st.nextToken ();
318 if (set.add (t.toLowerCase (Locale.US))) {
319 if (compactedProxyHosts.length() > 0) {
320 compactedProxyHosts.append(
'|');
322 compactedProxyHosts.append(t);
325 return compactedProxyHosts.toString();
329 StringTokenizer st =
new StringTokenizer (nonProxyHost,
"|");
330 StringBuilder reguralProxyHosts =
new StringBuilder();
331 while (st.hasMoreTokens ()) {
332 String t = st.nextToken ();
333 if (t.indexOf (
'*') == -1) {
336 if (reguralProxyHosts.length() > 0)
337 reguralProxyHosts.append(
'|');
338 reguralProxyHosts.append(t);
341 return reguralProxyHosts.toString();
345 if (proxyHost.toLowerCase (Locale.US).startsWith (
"http://")) {
346 return proxyHost.substring (7, proxyHost.length ());
353 Parameters.notNull(
"uri", uri);
354 List<Proxy> proxies = ProxySelector.getDefault().select(uri);
355 assert proxies != null :
"ProxySelector cannot return null for " + uri;
356 assert !proxies.isEmpty() :
"ProxySelector cannot return empty list for " + uri;
357 String protocol = uri.getScheme();
358 Proxy p = proxies.get(0);
359 if (Proxy.Type.DIRECT == p.type()) {
364 || ((protocol.startsWith(
"http") || protocol.equals(
"ftp")) && Proxy.Type.HTTP == p.type())
365 || !(protocol.startsWith(
"http") || protocol.equals(
"ftp"))) {
366 if (p.address() instanceof InetSocketAddress) {
369 return (InetSocketAddress) p.address();
371 LOGGER.log(Level.INFO, p.address() +
" is not instanceof InetSocketAddress but " + p.address().getClass());
384 @ServiceProvider(service = NetworkSettings.ProxyCredentialsProvider.class, position = 1000)
393 return sa == null ? null : sa.getHostName();
402 return sa == null ? null : Integer.toString(sa.getPort());
426 return getPreferences().getBoolean(USE_PROXY_AUTHENTICATION,
false);
444 public abstract void reload();
static final String PROXY_HTTPS_HOST
static char[] getAuthenticationPassword()
static boolean useProxyAllProtocols()
static String getHttpPort()
static final Logger LOGGER
static final String SYSTEM_PROXY_HTTPS_PORT
static void addPreferenceChangeListener(PreferenceChangeListener l)
static final String PROXY_AUTHENTICATION_USERNAME
static String addReguralToNonProxyHosts(String nonProxyHost)
static final String PROXY_AUTHENTICATION_PASSWORD
boolean isProxyAuthentication(URI u)
String getProxyHost(URI u)
static final String SYSTEM_PROXY_SOCKS_PORT
static final int DIRECT_CONNECTION
static String getSocksPort()
static final String PROXY_HTTP_PORT
static int getProxyType()
static final String USE_PROXY_ALL_PROTOCOLS
static final String PROXY_HTTPS_PORT
static String getSystemSocksPort()
static final String SYSTEM_PROXY_HTTP_HOST
static final String TEST_SYSTEM_PROXY_HTTP_HOST
static String getSystemNonProxyHosts()
static String getSystemHttpHost()
static String getHttpHost()
String getProxyPort(URI u)
static String getTestSystemHttpPort()
static final String SYSTEM_NON_PROXY_HOSTS
static final String USE_PROXY_AUTHENTICATION
static String getAuthenticationUsername()
static String compactNonProxyHosts(String hosts)
static final int AUTO_DETECT_PAC
static final String PROXY_SOCKS_PORT
static InetSocketAddress analyzeProxy(URI uri)
static String getPresetNonProxyHosts()
static void setAuthenticationPassword(char[] password)
static final String NOT_PROXY_HOSTS
String getProxyUserName(URI u)
static final String PROXY_SOCKS_HOST
static final String SYSTEM_PROXY_SOCKS_HOST
static String getDefaultUserNonProxyHosts()
static final String TEST_SYSTEM_PROXY_HTTP_PORT
static void removePreferenceChangeListener(PreferenceChangeListener l)
static String getSystemHttpsPort()
static String getNonProxyHosts()
static boolean useAuthentication()
static final int AUTO_DETECT_PROXY
static String getModifiedNonProxyHosts(String systemPreset)
static final String PROXY_HTTP_HOST
static final String SYSTEM_PROXY_HTTPS_HOST
static final String SYSTEM_PROXY_HTTP_PORT
static final String SYSTEM_PAC
static String getSystemHttpPort()
static String getSystemPac()
char[] getProxyPassword(URI u)
static String normalizeProxyHost(String proxyHost)
static String presetNonProxyHosts
static String concatProxies(String...proxies)
synchronized static Logger getLogger(String name)
static String getTestSystemHttpHost()
static Preferences getPreferences()
static final String HTTP_CONNECTION_TEST_URL
static String getHttpsHost()
static String getSocksHost()
static final int MANUAL_SET_PAC
static final int MANUAL_SET_PROXY
static String getSystemHttpsHost()
static String getSystemSocksHost()
static final String PROXY_TYPE
static String getHttpsPort()
static final String DIRECT