1 19 20 package com.sslexplorer.server; 21 22 import java.net.Authenticator ; 23 import java.net.PasswordAuthentication ; 24 25 import org.apache.commons.logging.Log; 26 import org.apache.commons.logging.LogFactory; 27 28 import com.sslexplorer.boot.ContextHolder; 29 import com.sslexplorer.boot.ContextKey; 30 import com.sslexplorer.boot.PropertyClass; 31 32 39 40 public class ProxyAuthenticator extends Authenticator { 41 final static Log log = LogFactory.getLog(ProxyAuthenticator.class); 42 43 46 public PasswordAuthentication getPasswordAuthentication() { 47 if (log.isInfoEnabled()) 48 log.info("Requesting " + getRequestingProtocol() + " proxy authentication for " + getRequestingSite() + " (" 49 + getRequestingHost() + ":" + getRequestingPort() + "), prompt = " + getRequestingPrompt()); 50 String user = null; 51 String pass = null; 52 try { 53 PropertyClass contextConfiguration = ContextHolder.getContext().getConfig(); 54 if (getRequestingProtocol().startsWith("SOCKS")) { 55 user = contextConfiguration.retrieveProperty(new ContextKey("proxies.socksProxyUser")); 56 pass = contextConfiguration.retrieveProperty(new ContextKey("proxies.socksProxyPassword")); 57 } else { 58 user = contextConfiguration.retrieveProperty(new ContextKey("proxies.http.proxyUser")); 59 pass = contextConfiguration.retrieveProperty(new ContextKey("proxies.http.proxyPassword")); 60 } 61 } catch (Exception e) { 62 log.error("Failed to get proxy authentication details."); 63 return null; 64 } 65 return new PasswordAuthentication (user, pass.toCharArray()); 66 } 67 68 } 69 | Popular Tags |