+ try
+ {
+ Authenticator.setDefault(new Authenticator()
+ {
+ @Override
+ protected PasswordAuthentication getPasswordAuthentication()
+ {
+ if (getRequestorType() == RequestorType.PROXY)
+ {
+ try
+ {
+ if (getRequestingScheme().equalsIgnoreCase("http")
+ && getRequestingHost().equalsIgnoreCase(httpHost)
+ && getRequestingPort() == Integer.valueOf(httpPort))
+ {
+ return new PasswordAuthentication(httpUser,
+ httpPassword == null ? new char[] {}
+ : httpPassword.toCharArray());
+ }
+ if (getRequestingScheme().equalsIgnoreCase("https")
+ && getRequestingHost().equalsIgnoreCase(httpsHost)
+ && getRequestingPort() == Integer
+ .valueOf(httpsPort))
+ {
+ return new PasswordAuthentication(httpsUser,
+ httpsPassword == null ? new char[] {}
+ : httpsPassword.toCharArray());
+ }
+ } catch (NumberFormatException e)
+ {
+ Cache.error("Problem with proxy port values [http:"
+ + httpPort + ", https:" + httpsPort + "]");
+ }
+ }
+ // non proxy request
+ return null;
+ }
+ });
+ // required to re-enable basic authentication (should be okay for a
+ // local proxy)
+ System.setProperty("jdk.http.auth.tunneling.disabledSchemes", "");
+ } catch (SecurityException e)
+ {
+ Cache.error("Could not set default Authenticator");
+ Cache.debug(getStackTraceString(e));
+ }