hc-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject svn commit: r1724610 - in /httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http: conn/ impl/auth/ impl/client/ impl/conn/
Date Thu, 14 Jan 2016 13:49:23 GMT
Author: olegk
Date: Thu Jan 14 13:49:23 2016
New Revision: 1724610

URL: http://svn.apache.org/viewvc?rev=1724610&view=rev
Log:
Added #resolveCanonicalHostname to DnsResolver; GGS schemes to use DnsResolver when resolving
to canonical hostname

Modified:
    httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/conn/DnsResolver.java
    httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/auth/GGSSchemeBase.java
    httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/auth/KerberosScheme.java
    httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/auth/KerberosSchemeFactory.java
    httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/auth/SPNegoScheme.java
    httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/auth/SPNegoSchemeFactory.java
    httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/HttpClientBuilder.java
    httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/ProxyClient.java
    httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/InMemoryDnsResolver.java
    httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/SystemDefaultDnsResolver.java

Modified: httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/conn/DnsResolver.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/conn/DnsResolver.java?rev=1724610&r1=1724609&r2=1724610&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/conn/DnsResolver.java
(original)
+++ httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/conn/DnsResolver.java
Thu Jan 14 13:49:23 2016
@@ -51,4 +51,10 @@ public interface DnsResolver {
      */
     InetAddress[] resolve(String host) throws UnknownHostException;
 
+    /**
+     * Gets the fully qualified domain name for given host name.
+     * @since 5.0
+     */
+    String resolveCanonicalHostname(String host) throws UnknownHostException;
+
 }

Modified: httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/auth/GGSSchemeBase.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/auth/GGSSchemeBase.java?rev=1724610&r1=1724609&r2=1724610&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/auth/GGSSchemeBase.java
(original)
+++ httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/auth/GGSSchemeBase.java
Thu Jan 14 13:49:23 2016
@@ -26,7 +26,6 @@
  */
 package org.apache.http.impl.auth;
 
-import java.net.InetAddress;
 import java.net.UnknownHostException;
 import java.security.Principal;
 
@@ -47,6 +46,8 @@ import org.apache.http.auth.CredentialsP
 import org.apache.http.auth.InvalidCredentialsException;
 import org.apache.http.auth.KerberosCredentials;
 import org.apache.http.auth.MalformedChallengeException;
+import org.apache.http.conn.DnsResolver;
+import org.apache.http.impl.conn.SystemDefaultDnsResolver;
 import org.ietf.jgss.GSSContext;
 import org.ietf.jgss.GSSCredential;
 import org.ietf.jgss.GSSException;
@@ -69,6 +70,7 @@ public abstract class GGSSchemeBase impl
 
     private final Log log = LogFactory.getLog(getClass());
 
+    private final DnsResolver dnsResolver;
     private final boolean stripPort;
     private final boolean useCanonicalHostname;
 
@@ -78,19 +80,23 @@ public abstract class GGSSchemeBase impl
     private String challenge;
     private byte[] token;
 
-    GGSSchemeBase(final boolean stripPort, final boolean useCanonicalHostname) {
+    GGSSchemeBase(
+            final DnsResolver dnsResolver,
+            final boolean stripPort,
+            final boolean useCanonicalHostname) {
         super();
+        this.dnsResolver = dnsResolver != null ? dnsResolver : SystemDefaultDnsResolver.INSTANCE;
         this.stripPort = stripPort;
         this.useCanonicalHostname = useCanonicalHostname;
         this.state = State.UNINITIATED;
     }
 
     GGSSchemeBase(final boolean stripPort) {
-        this(stripPort, true);
+        this(null, stripPort, true);
     }
 
     GGSSchemeBase() {
-        this(true, true);
+        this(null, true, true);
     }
 
     @Override
@@ -189,15 +195,11 @@ public abstract class GGSSchemeBase impl
                 String hostname = host.getHostName();
                 if (this.useCanonicalHostname){
                     try {
-                         //TODO: uncomment this statement and delete the resolveCanonicalHostname,
-                         //TODO: as soon canonical hostname resolving is implemented in the
SystemDefaultDnsResolver
-                         //final DnsResolver dnsResolver = SystemDefaultDnsResolver.INSTANCE;
-                         //hostname = dnsResolver.resolveCanonicalHostname(host.getHostName());
-                         hostname = resolveCanonicalHostname(hostname);
+                         hostname = dnsResolver.resolveCanonicalHostname(host.getHostName());
                     } catch (UnknownHostException ignore){
                     }
                 }
-                if (this.stripPort) { // || host.getPort()==80 || host.getPort()==443) {
+                if (this.stripPort) {
                     authServer = hostname;
                 } else {
                     authServer = hostname + ":" + host.getPort();
@@ -237,15 +239,6 @@ public abstract class GGSSchemeBase impl
         }
     }
 
-    private String resolveCanonicalHostname(final String host) throws UnknownHostException
{
-        final InetAddress in = InetAddress.getByName(host);
-        final String canonicalServer = in.getCanonicalHostName();
-        if (in.getHostAddress().contentEquals(canonicalServer)) {
-            return host;
-        }
-        return canonicalServer;
-    }
-
     @Override
     public String toString() {
         return getName() + "{" + this.state + " " + challenge + '}';

Modified: httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/auth/KerberosScheme.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/auth/KerberosScheme.java?rev=1724610&r1=1724609&r2=1724610&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/auth/KerberosScheme.java
(original)
+++ httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/auth/KerberosScheme.java
Thu Jan 14 13:49:23 2016
@@ -27,6 +27,7 @@
 package org.apache.http.impl.auth;
 
 import org.apache.hc.core5.annotation.NotThreadSafe;
+import org.apache.http.conn.DnsResolver;
 import org.ietf.jgss.GSSException;
 import org.ietf.jgss.Oid;
 
@@ -43,8 +44,8 @@ public class KerberosScheme extends GGSS
     /**
      * @since 4.4
      */
-    public KerberosScheme(final boolean stripPort, final boolean useCanonicalHostname) {
-        super(stripPort, useCanonicalHostname);
+    public KerberosScheme(final DnsResolver dnsResolver, final boolean stripPort, final boolean
useCanonicalHostname) {
+        super(dnsResolver, stripPort, useCanonicalHostname);
     }
 
     public KerberosScheme(final boolean stripPort) {

Modified: httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/auth/KerberosSchemeFactory.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/auth/KerberosSchemeFactory.java?rev=1724610&r1=1724609&r2=1724610&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/auth/KerberosSchemeFactory.java
(original)
+++ httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/auth/KerberosSchemeFactory.java
Thu Jan 14 13:49:23 2016
@@ -30,6 +30,7 @@ import org.apache.hc.core5.annotation.Im
 import org.apache.hc.core5.http.protocol.HttpContext;
 import org.apache.http.auth.AuthScheme;
 import org.apache.http.auth.AuthSchemeProvider;
+import org.apache.http.conn.DnsResolver;
 
 /**
  * {@link AuthSchemeProvider} implementation that creates and initializes
@@ -40,39 +41,23 @@ import org.apache.http.auth.AuthSchemePr
 @Immutable
 public class KerberosSchemeFactory implements AuthSchemeProvider {
 
+    private final DnsResolver dnsResolver;
     private final boolean stripPort;
     private final boolean useCanonicalHostname;
 
     /**
      * @since 4.4
      */
-    public KerberosSchemeFactory(final boolean stripPort, final boolean useCanonicalHostname)
{
+    public KerberosSchemeFactory(final DnsResolver dnsResolver, final boolean stripPort,
final boolean useCanonicalHostname) {
         super();
+        this.dnsResolver = dnsResolver;
         this.stripPort = stripPort;
         this.useCanonicalHostname = useCanonicalHostname;
     }
 
-    public KerberosSchemeFactory(final boolean stripPort) {
-        super();
-        this.stripPort = stripPort;
-        this.useCanonicalHostname = true;
-    }
-
-    public KerberosSchemeFactory() {
-        this(true, true);
-    }
-
-    public boolean isStripPort() {
-        return stripPort;
-    }
-
-    public boolean isUseCanonicalHostname() {
-        return useCanonicalHostname;
-    }
-
     @Override
     public AuthScheme create(final HttpContext context) {
-        return new KerberosScheme(this.stripPort, this.useCanonicalHostname);
+        return new KerberosScheme(this.dnsResolver, this.stripPort, this.useCanonicalHostname);
     }
 
 }

Modified: httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/auth/SPNegoScheme.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/auth/SPNegoScheme.java?rev=1724610&r1=1724609&r2=1724610&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/auth/SPNegoScheme.java
(original)
+++ httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/auth/SPNegoScheme.java
Thu Jan 14 13:49:23 2016
@@ -27,6 +27,7 @@
 package org.apache.http.impl.auth;
 
 import org.apache.hc.core5.annotation.NotThreadSafe;
+import org.apache.http.conn.DnsResolver;
 import org.ietf.jgss.GSSException;
 import org.ietf.jgss.Oid;
 
@@ -44,8 +45,8 @@ public class SPNegoScheme extends GGSSch
     /**
      * @since 4.4
      */
-    public SPNegoScheme(final boolean stripPort, final boolean useCanonicalHostname) {
-        super(stripPort, useCanonicalHostname);
+    public SPNegoScheme(final DnsResolver dnsResolver, final boolean stripPort, final boolean
useCanonicalHostname) {
+        super(dnsResolver, stripPort, useCanonicalHostname);
     }
 
     public SPNegoScheme(final boolean stripPort) {

Modified: httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/auth/SPNegoSchemeFactory.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/auth/SPNegoSchemeFactory.java?rev=1724610&r1=1724609&r2=1724610&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/auth/SPNegoSchemeFactory.java
(original)
+++ httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/auth/SPNegoSchemeFactory.java
Thu Jan 14 13:49:23 2016
@@ -30,6 +30,7 @@ import org.apache.hc.core5.annotation.Im
 import org.apache.hc.core5.http.protocol.HttpContext;
 import org.apache.http.auth.AuthScheme;
 import org.apache.http.auth.AuthSchemeProvider;
+import org.apache.http.conn.DnsResolver;
 
 /**
  * {@link AuthSchemeProvider} implementation that creates and initializes
@@ -40,39 +41,23 @@ import org.apache.http.auth.AuthSchemePr
 @Immutable
 public class SPNegoSchemeFactory implements AuthSchemeProvider {
 
+    private final DnsResolver dnsResolver;
     private final boolean stripPort;
     private final boolean useCanonicalHostname;
 
     /**
      * @since 4.4
      */
-    public SPNegoSchemeFactory(final boolean stripPort, final boolean useCanonicalHostname)
{
+    public SPNegoSchemeFactory(final DnsResolver dnsResolver, final boolean stripPort, final
boolean useCanonicalHostname) {
         super();
+        this.dnsResolver = dnsResolver;
         this.stripPort = stripPort;
         this.useCanonicalHostname = useCanonicalHostname;
     }
 
-    public SPNegoSchemeFactory(final boolean stripPort) {
-        super();
-        this.stripPort = stripPort;
-        this.useCanonicalHostname = true;
-    }
-
-    public SPNegoSchemeFactory() {
-        this(true, true);
-    }
-
-    public boolean isStripPort() {
-        return stripPort;
-    }
-
-    public boolean isUseCanonicalHostname() {
-        return useCanonicalHostname;
-    }
-
     @Override
     public AuthScheme create(final HttpContext context) {
-        return new SPNegoScheme(this.stripPort, this.useCanonicalHostname);
+        return new SPNegoScheme(this.dnsResolver, this.stripPort, this.useCanonicalHostname);
     }
 
 }

Modified: httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/HttpClientBuilder.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/HttpClientBuilder.java?rev=1724610&r1=1724609&r2=1724610&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/HttpClientBuilder.java
(original)
+++ httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/HttpClientBuilder.java
Thu Jan 14 13:49:23 2016
@@ -108,6 +108,7 @@ import org.apache.http.impl.conn.Default
 import org.apache.http.impl.conn.DefaultRoutePlanner;
 import org.apache.http.impl.conn.DefaultSchemePortResolver;
 import org.apache.http.impl.conn.PoolingHttpClientConnectionManager;
+import org.apache.http.impl.conn.SystemDefaultDnsResolver;
 import org.apache.http.impl.conn.SystemDefaultRoutePlanner;
 import org.apache.http.impl.execchain.BackoffStrategyExec;
 import org.apache.http.impl.execchain.ClientExecChain;
@@ -1110,8 +1111,8 @@ public class HttpClientBuilder {
                 .register(AuthSchemes.BASIC, new BasicSchemeFactory())
                 .register(AuthSchemes.DIGEST, new DigestSchemeFactory())
                 .register(AuthSchemes.NTLM, new NTLMSchemeFactory())
-                .register(AuthSchemes.SPNEGO, new SPNegoSchemeFactory())
-                .register(AuthSchemes.KERBEROS, new KerberosSchemeFactory())
+                .register(AuthSchemes.SPNEGO, new SPNegoSchemeFactory(SystemDefaultDnsResolver.INSTANCE,
true, true))
+                .register(AuthSchemes.KERBEROS, new KerberosSchemeFactory(SystemDefaultDnsResolver.INSTANCE,
true, true))
                 .build();
         }
         Lookup<CookieSpecProvider> cookieSpecRegistryCopy = this.cookieSpecRegistry;

Modified: httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/ProxyClient.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/ProxyClient.java?rev=1724610&r1=1724609&r2=1724610&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/ProxyClient.java
(original)
+++ httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/ProxyClient.java
Thu Jan 14 13:49:23 2016
@@ -76,6 +76,7 @@ import org.apache.http.impl.auth.Kerbero
 import org.apache.http.impl.auth.NTLMSchemeFactory;
 import org.apache.http.impl.auth.SPNegoSchemeFactory;
 import org.apache.http.impl.conn.ManagedHttpClientConnectionFactory;
+import org.apache.http.impl.conn.SystemDefaultDnsResolver;
 import org.apache.http.impl.execchain.TunnelRefusedException;
 
 /**
@@ -115,8 +116,8 @@ public class ProxyClient {
                 .register(AuthSchemes.BASIC, new BasicSchemeFactory())
                 .register(AuthSchemes.DIGEST, new DigestSchemeFactory())
                 .register(AuthSchemes.NTLM, new NTLMSchemeFactory())
-                .register(AuthSchemes.SPNEGO, new SPNegoSchemeFactory())
-                .register(AuthSchemes.KERBEROS, new KerberosSchemeFactory())
+                .register(AuthSchemes.SPNEGO, new SPNegoSchemeFactory(SystemDefaultDnsResolver.INSTANCE,
true, true))
+                .register(AuthSchemes.KERBEROS, new KerberosSchemeFactory(SystemDefaultDnsResolver.INSTANCE,
true, true))
                 .build();
         this.reuseStrategy = new DefaultConnectionReuseStrategy();
     }

Modified: httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/InMemoryDnsResolver.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/InMemoryDnsResolver.java?rev=1724610&r1=1724609&r2=1724610&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/InMemoryDnsResolver.java
(original)
+++ httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/InMemoryDnsResolver.java
Thu Jan 14 13:49:23 2016
@@ -92,4 +92,12 @@ public class InMemoryDnsResolver impleme
         return resolvedAddresses;
     }
 
+    @Override
+    public String resolveCanonicalHostname(final String host) throws UnknownHostException
{
+        final InetAddress[] resolvedAddresses = resolve(host);
+        if (resolvedAddresses.length > 0) {
+            return resolvedAddresses[0].getCanonicalHostName();
+        }
+        return host;
+    }
 }

Modified: httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/SystemDefaultDnsResolver.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/SystemDefaultDnsResolver.java?rev=1724610&r1=1724609&r2=1724610&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/SystemDefaultDnsResolver.java
(original)
+++ httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/SystemDefaultDnsResolver.java
Thu Jan 14 13:49:23 2016
@@ -45,4 +45,16 @@ public class SystemDefaultDnsResolver im
         return InetAddress.getAllByName(host);
     }
 
+    @Override
+    public String resolveCanonicalHostname(final String host) throws UnknownHostException
{
+        if (host == null) {
+            return null;
+        }
+        final InetAddress in = InetAddress.getByName(host);
+        final String canonicalServer = in.getCanonicalHostName();
+        if (in.getHostAddress().contentEquals(canonicalServer)) {
+            return host;
+        }
+        return canonicalServer;
+    }
 }



Mime
View raw message