commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject cvs commit: jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/protocol ReflectionSocketFactory.java
Date Thu, 10 Jun 2004 18:25:24 GMT
olegk       2004/06/10 11:25:24

  Modified:    httpclient/src/contrib/org/apache/commons/httpclient/contrib/ssl
                        EasySSLProtocolSocketFactory.java
                        EasyX509TrustManager.java
                        StrictSSLProtocolSocketFactory.java
               httpclient/src/java/org/apache/commons/httpclient/protocol
                        ReflectionSocketFactory.java
  Added:       httpclient/src/contrib/org/apache/commons/httpclient/contrib/ssl
                        AuthSSLInitializationError.java
                        AuthSSLProtocolSocketFactory.java
                        AuthSSLX509TrustManager.java
  Log:
  Contribution of an SSL authenticating socket factory
  
  Contributed by Oleg Kalnichevski
  Reviewed by Michael Becke
  
  Revision  Changes    Path
  1.6       +43 -26    jakarta-commons/httpclient/src/contrib/org/apache/commons/httpclient/contrib/ssl/EasySSLProtocolSocketFactory.java
  
  Index: EasySSLProtocolSocketFactory.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/httpclient/src/contrib/org/apache/commons/httpclient/contrib/ssl/EasySSLProtocolSocketFactory.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- EasySSLProtocolSocketFactory.java	13 Apr 2004 21:47:28 -0000	1.5
  +++ EasySSLProtocolSocketFactory.java	10 Jun 2004 18:25:24 -0000	1.6
  @@ -1,4 +1,8 @@
   /*
  + * $Header$
  + * $Revision$
  + * $Date$
  + * 
    * ====================================================================
    *
    *  Copyright 2002-2004 The Apache Software Foundation
  @@ -21,8 +25,6 @@
    * information on the Apache Software Foundation, please see
    * <http://www.apache.org/>.
    *
  - * [Additional notices, if required by prior licensing conditions]
  - *
    */
   
   package org.apache.commons.httpclient.contrib.ssl;
  @@ -31,10 +33,6 @@
   import java.net.InetAddress;
   import java.net.Socket;
   import java.net.UnknownHostException;
  -import javax.net.ssl.SSLSocketFactory;
  -
  -import com.sun.net.ssl.SSLContext;
  -import com.sun.net.ssl.TrustManager; 
   
   import org.apache.commons.httpclient.ConnectTimeoutException;
   import org.apache.commons.httpclient.HttpClientError;
  @@ -45,6 +43,9 @@
   import org.apache.commons.logging.Log; 
   import org.apache.commons.logging.LogFactory;
   
  +import com.sun.net.ssl.SSLContext;
  +import com.sun.net.ssl.TrustManager;
  +
   /**
    * <p>
    * EasySSLProtocolSocketFactory can be used to creats SSL {@link Socket}s 
  @@ -56,12 +57,38 @@
    * you are perfectly aware of security implications of accepting 
    * self-signed certificates
    * </p>
  + *
  + * <p>
  + * Example of using custom protocol socket factory for a specific host:
  + *     <pre>
  + *     Protocol easyhttps = new Protocol("https", new EasySSLProtocolSocketFactory(), 443);
  + *
  + *     HttpClient client = new HttpClient();
  + *     client.getHostConfiguration().setHost("localhost", 443, easyhttps);
  + *     // use relative url only
  + *     GetMethod httpget = new GetMethod("/");
  + *     client.executeMethod(httpget);
  + *     </pre>
  + * </p>
  + * <p>
  + * Example of using custom protocol socket factory per default instead of the standard
one:
  + *     <pre>
  + *     Protocol easyhttps = new Protocol("https", new EasySSLProtocolSocketFactory(), 443);
  + *     Protocol.registerProtocol("https", easyhttps);
  + *
  + *     HttpClient client = new HttpClient();
  + *     GetMethod httpget = new GetMethod("https://localhost/");
  + *     client.executeMethod(httpget);
  + *     </pre>
  + * </p>
    * 
    * @author <a href="mailto:oleg@ural.ru">Oleg Kalnichevski</a>
    * 
  + * <p>
    * DISCLAIMER: HttpClient developers DO NOT actively support this component.
    * The component is provided as a reference material, which may be inappropriate
  - * to be used without additional customization.
  + * for use without additional customization.
  + * </p>
    */
   
   public class EasySSLProtocolSocketFactory implements SecureProtocolSocketFactory {
  @@ -69,19 +96,10 @@
       /** Log object for this class. */
       private static final Log LOG = LogFactory.getLog(EasySSLProtocolSocketFactory.class);
   
  -    private static SSLContext SSL_CONTEXT_SINGLETON = null;
  +    private SSLContext sslcontext = null;
  +
       /**
        * Constructor for EasySSLProtocolSocketFactory.
  -     * 
  -     * Code sample:
  -     *  
  -     *     <blockquote>
  -     *     Protocol easyhttps = new Protocol( 
  -     *         "https", new EasySSLProtocolSocketFactory(), 443);
  -     *
  -     *     HttpClient client = new HttpClient();
  -     *     client.getHostConfiguration().setHost("localhost", 443, easyhttps);
  -     *     </blockquote>
        */
       public EasySSLProtocolSocketFactory() {
           super();
  @@ -101,11 +119,11 @@
           }
       }
   
  -    private static SSLSocketFactory getEasySSLSocketFactory() {
  -        if (SSL_CONTEXT_SINGLETON == null) {
  -            SSL_CONTEXT_SINGLETON = createEasySSLContext();
  +    private SSLContext getSSLContext() {
  +        if (this.sslcontext == null) {
  +            this.sslcontext = createEasySSLContext();
           }
  -        return SSL_CONTEXT_SINGLETON.getSocketFactory();
  +        return this.sslcontext;
       }
   
       /**
  @@ -118,13 +136,12 @@
           int clientPort)
           throws IOException, UnknownHostException {
   
  -        Socket socket = getEasySSLSocketFactory().createSocket(
  +        return getSSLContext().getSocketFactory().createSocket(
               host,
               port,
               clientHost,
               clientPort
           );
  -        return socket;
       }
   
       /**
  @@ -180,7 +197,7 @@
        */
       public Socket createSocket(String host, int port)
           throws IOException, UnknownHostException {
  -        return getEasySSLSocketFactory().createSocket(
  +        return getSSLContext().getSocketFactory().createSocket(
               host,
               port
           );
  @@ -195,7 +212,7 @@
           int port,
           boolean autoClose)
           throws IOException, UnknownHostException {
  -        return getEasySSLSocketFactory().createSocket(
  +        return getSSLContext().getSocketFactory().createSocket(
               socket,
               host,
               port,
  
  
  
  1.4       +3 -3      jakarta-commons/httpclient/src/contrib/org/apache/commons/httpclient/contrib/ssl/EasyX509TrustManager.java
  
  Index: EasyX509TrustManager.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/httpclient/src/contrib/org/apache/commons/httpclient/contrib/ssl/EasyX509TrustManager.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- EasyX509TrustManager.java	22 Feb 2004 18:08:45 -0000	1.3
  +++ EasyX509TrustManager.java	10 Jun 2004 18:25:24 -0000	1.4
  @@ -21,8 +21,6 @@
    * information on the Apache Software Foundation, please see
    * <http://www.apache.org/>.
    *
  - * [Additional notices, if required by prior licensing conditions]
  - *
    */
   
   package org.apache.commons.httpclient.contrib.ssl;
  @@ -54,9 +52,11 @@
    * @author <a href="mailto:adrian.sutton@ephox.com">Adrian Sutton</a>
    * @author <a href="mailto:oleg@ural.ru">Oleg Kalnichevski</a>
    * 
  + * <p>
    * DISCLAIMER: HttpClient developers DO NOT actively support this component.
    * The component is provided as a reference material, which may be inappropriate
  - * to be used without additional customization.
  + * for use without additional customization.
  + * </p>
    */
   
   public class EasyX509TrustManager implements X509TrustManager
  
  
  
  1.5       +6 -6      jakarta-commons/httpclient/src/contrib/org/apache/commons/httpclient/contrib/ssl/StrictSSLProtocolSocketFactory.java
  
  Index: StrictSSLProtocolSocketFactory.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/httpclient/src/contrib/org/apache/commons/httpclient/contrib/ssl/StrictSSLProtocolSocketFactory.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- StrictSSLProtocolSocketFactory.java	13 Apr 2004 21:47:28 -0000	1.4
  +++ StrictSSLProtocolSocketFactory.java	10 Jun 2004 18:25:24 -0000	1.5
  @@ -73,11 +73,11 @@
    * server certificates "Common Name" field of the "SubjectDN" entry.
    *
    * @author <a href="mailto:hauer@psicode.com">Sebastian Hauer</a>
  - * @version 1.0
  - * 
  + * <p>
    * DISCLAIMER: HttpClient developers DO NOT actively support this component.
    * The component is provided as a reference material, which may be inappropriate
  - * to be used without additional customization.
  + * for use without additional customization.
  + * </p>
    */
   public class StrictSSLProtocolSocketFactory 
       implements SecureProtocolSocketFactory {
  
  
  
  1.2       +65 -0     jakarta-commons/httpclient/src/contrib/org/apache/commons/httpclient/contrib/ssl/AuthSSLInitializationError.java
  
  
  
  
  1.2       +414 -0    jakarta-commons/httpclient/src/contrib/org/apache/commons/httpclient/contrib/ssl/AuthSSLProtocolSocketFactory.java
  
  
  
  
  1.2       +113 -0    jakarta-commons/httpclient/src/contrib/org/apache/commons/httpclient/contrib/ssl/AuthSSLX509TrustManager.java
  
  
  
  
  1.3       +4 -3      jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/protocol/ReflectionSocketFactory.java
  
  Index: ReflectionSocketFactory.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/protocol/ReflectionSocketFactory.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- ReflectionSocketFactory.java	18 Apr 2004 23:51:38 -0000	1.2
  +++ ReflectionSocketFactory.java	10 Jun 2004 18:25:24 -0000	1.3
  @@ -64,6 +64,7 @@
        * using reflection. If the methods are not available or could not be executed
        * <tt>null</tt> is returned
        *   
  +     * @param socketfactoryName name of the socket factory class
        * @param host the host name/IP
        * @param port the port on the host
        * @param localAddress the local host name/IP to bind the socket to
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Mime
View raw message