+ try
+ {
+ Authenticator.setDefault(new Authenticator()
+ {
+ @Override
+ protected PasswordAuthentication getPasswordAuthentication()
+ {
+ Cache.debug(
+ "*** START PasswordAuthentication.getPasswordAuthentication()");
+ Cache.debug("*** getRequestorType()=" + getRequestorType());
+ if (getRequestorType() == RequestorType.PROXY)
+ {
+ String protocol = getRequestingProtocol();
+ boolean needProxyPasswordSet = false;
+ Cache.debug("*** customProxySet = " + customProxySet);
+ Cache.debug("*** protocol = " + protocol);
+ Cache.debug("*** httpUser = " + httpUser);
+ Cache.debug(
+ "*** httpPassword = \"" + (httpPassword == null ? null
+ : new String(httpPassword)) + "\"");
+ Cache.debug("*** httpsUser = " + httpsUser);
+ Cache.debug("*** httpsPassword = \""
+ + (httpsPassword == null ? null
+ : new String(httpsPassword))
+ + "\"");
+ if (customProxySet &&
+ // we have a username but no password for the scheme being
+ // requested
+ (protocol.equalsIgnoreCase("http")
+ && (httpUser != null && httpUser.length() > 0
+ && (httpPassword == null
+ || httpPassword.length == 0)))
+ || (protocol.equalsIgnoreCase("https")
+ && (httpsUser != null
+ && httpsUser.length() > 0
+ && (httpsPassword == null
+ || httpsPassword.length == 0))))
+ {
+ // open Preferences -> Connections
+ String message = MessageManager
+ .getString("label.proxy_password_required");
+ Cache.debug("***+ TRYING TO OPEN PREFERENCES");
+ openPreferencesConnectionsForProxyPassword(message);
+ Cache.debug("***+ AFTER TRYING TO OPEN PREFERENCES");
+ }
+ else
+ {
+ Cache.debug("***+ TRYING TO GET PASSWORDAUTHENTICATION");
+ try
+ {
+ if (protocol.equalsIgnoreCase("http")
+ && getRequestingHost().equalsIgnoreCase(httpHost)
+ && getRequestingPort() == Integer
+ .valueOf(httpPort))
+ {
+ Cache.debug("***+ RETURNING PasswordAuthentication(\""
+ + httpUser + "\", \"" + new String(httpPassword)
+ + "\"");
+ return new PasswordAuthentication(httpUser,
+ httpPassword);
+ }
+ if (protocol.equalsIgnoreCase("https")
+ && getRequestingHost().equalsIgnoreCase(httpsHost)
+ && getRequestingPort() == Integer
+ .valueOf(httpsPort))
+ {
+ Cache.debug("***+ RETURNING PasswordAuthentication(\""
+ + httpsUser + "\", \"" + httpsPassword + "\"");
+ return new PasswordAuthentication(httpsUser,
+ httpsPassword);
+ }
+ } catch (NumberFormatException e)
+ {
+ Cache.error("Problem with proxy port values [http:"
+ + httpPort + ", https:" + httpsPort + "]");
+ }
+ Cache.debug(
+ "***+ AFTER TRYING TO GET PASSWORDAUTHENTICATION");
+ }
+ }
+ // non proxy request
+ Cache.debug("***+ Returning null");
+ return null;
+ }
+ });
+ // required to re-enable basic authentication (should be okay for a
+ // local proxy)
+ Cache.debug(
+ "***+ Setting jdk.http.auth.tunneling.disabledSchemes to ''");
+ System.setProperty("jdk.http.auth.tunneling.disabledSchemes", "");
+ } catch (SecurityException e)
+ {
+ Cache.error("Could not set default Authenticator");
+ Cache.debug(getStackTraceString(e));
+ }