Search in sources :

Example 1 with AuthProxy

use of com.zimbra.common.net.AuthProxy in project zm-mailbox by Zimbra.

the class HttpProxyConfig method getProxyConfig.

public static ProxyHostConfiguration getProxyConfig(HostConfiguration hc, String uriStr) {
    if (!LC.client_use_system_proxy.booleanValue())
        return null;
    URI uri = null;
    try {
        uri = new URI(uriStr);
    } catch (URISyntaxException x) {
        ZimbraLog.net.info(uriStr, x);
        return null;
    }
    //no need to filter out localhost as the DefaultProxySelector will do that.
    List<Proxy> proxies = ProxySelectors.defaultProxySelector().select(uri);
    for (Proxy proxy : proxies) {
        switch(proxy.type()) {
            case DIRECT:
                return null;
            case HTTP:
                InetSocketAddress addr = (InetSocketAddress) proxy.address();
                if (ZimbraLog.net.isDebugEnabled()) {
                    ZimbraLog.net.debug("URI %s to use HTTP proxy %s", safePrint(uri), addr.toString());
                }
                ProxyHostConfiguration nhc = new ProxyHostConfiguration(hc);
                nhc.setProxy(addr.getHostName(), addr.getPort());
                if (proxy instanceof AuthProxy) {
                    nhc.setUsername(((AuthProxy) proxy).getUsername());
                    nhc.setPassword(((AuthProxy) proxy).getPassword());
                }
                return nhc;
            //socks proxy can be handled at socket factory level
            case SOCKS:
            default:
                continue;
        }
    }
    return null;
}
Also used : AuthProxy(com.zimbra.common.net.AuthProxy) Proxy(java.net.Proxy) InetSocketAddress(java.net.InetSocketAddress) AuthProxy(com.zimbra.common.net.AuthProxy) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI) ProxyHostConfiguration(com.zimbra.common.net.ProxyHostConfiguration)

Aggregations

AuthProxy (com.zimbra.common.net.AuthProxy)1 ProxyHostConfiguration (com.zimbra.common.net.ProxyHostConfiguration)1 InetSocketAddress (java.net.InetSocketAddress)1 Proxy (java.net.Proxy)1 URI (java.net.URI)1 URISyntaxException (java.net.URISyntaxException)1