Coverage Report - org.mule.umo.security.tls.TlsPropertiesSocketFactory
 
Classes in this File Line Coverage Branch Coverage Complexity
TlsPropertiesSocketFactory
0%
0/29
0%
0/1
1.7
 
 1  
 /*
 2  
  * $Id: TlsPropertiesSocketFactory.java 7976 2007-08-21 14:26:13Z dirk.olmes $
 3  
  * --------------------------------------------------------------------------------------
 4  
  * Copyright (c) MuleSource, Inc.  All rights reserved.  http://www.mulesource.com
 5  
  *
 6  
  * The software in this package is published under the terms of the CPAL v1.0
 7  
  * license, a copy of which has been included with this distribution in the
 8  
  * LICENSE.txt file.
 9  
  */
 10  
 
 11  
 package org.mule.umo.security.tls;
 12  
 
 13  
 import java.io.IOException;
 14  
 import java.net.InetAddress;
 15  
 import java.net.Socket;
 16  
 
 17  
 import javax.net.ssl.SSLSocketFactory;
 18  
 
 19  
 import org.apache.commons.logging.Log;
 20  
 import org.apache.commons.logging.LogFactory;
 21  
 
 22  
 /**
 23  
  * A socket factory that is configured via Properties, using a {@link TlsConfiguration}
 24  
  * that has been stored via {@link TlsPropertiesMapper}.
 25  
  */
 26  
 public class TlsPropertiesSocketFactory extends SSLSocketFactory
 27  
 {
 28  
 
 29  0
     private Log logger = LogFactory.getLog(getClass());
 30  
     private boolean anon;
 31  
     private String namespace;
 32  
     private SSLSocketFactory factory;
 33  
 
 34  
     public TlsPropertiesSocketFactory(boolean anon, String namespace)
 35  0
     {
 36  0
         logger.debug("creating: " + anon + "; " + namespace);
 37  0
         this.anon = anon;
 38  0
         this.namespace = namespace;
 39  0
     }
 40  
 
 41  
     private synchronized SSLSocketFactory getFactory() throws IOException
 42  
     {
 43  0
         if (null == factory)
 44  
         {
 45  0
             logger.debug("creating factory");
 46  0
             TlsPropertiesMapper propertiesMapper = new TlsPropertiesMapper(namespace);
 47  0
             TlsConfiguration configuration = new TlsConfiguration(TlsConfiguration.DEFAULT_KEYSTORE); 
 48  0
             propertiesMapper.readFromProperties(configuration, System.getProperties());
 49  
             try 
 50  
             {
 51  0
                 configuration.initialise(anon, namespace);
 52  0
                 factory = configuration.getSocketFactory();
 53  
             } 
 54  0
             catch (Exception e)
 55  
             {
 56  0
                 throw (IOException) new IOException(e.getMessage()).initCause(e);
 57  0
             }
 58  
         }
 59  0
         return factory;
 60  
     }
 61  
 
 62  
     public Socket createSocket(Socket s, String host, int port, boolean autoClose) throws IOException
 63  
     {
 64  0
         return getFactory().createSocket(s, host, port, autoClose);
 65  
     }
 66  
 
 67  
     public String[] getDefaultCipherSuites()
 68  
     {
 69  
         try 
 70  
         {
 71  0
             return getFactory().getDefaultCipherSuites();
 72  
         }
 73  0
         catch (Exception e)
 74  
         {
 75  0
             return new String[0];
 76  
         }
 77  
     }
 78  
 
 79  
     public String[] getSupportedCipherSuites()
 80  
     {
 81  
         try 
 82  
         {
 83  0
             return getFactory().getSupportedCipherSuites();
 84  
         }
 85  0
         catch (Exception e)
 86  
         {
 87  0
             return new String[0];
 88  
         }
 89  
     }
 90  
 
 91  
     public Socket createSocket(String arg0, int arg1) throws IOException
 92  
     {
 93  0
         return getFactory().createSocket(arg0, arg1);
 94  
     }
 95  
 
 96  
     public Socket createSocket(InetAddress arg0, int arg1) throws IOException
 97  
     {
 98  0
         return getFactory().createSocket(arg0, arg1);
 99  
     }
 100  
 
 101  
     public Socket createSocket(String arg0, int arg1, InetAddress arg2, int arg3) throws IOException
 102  
     {
 103  0
         return getFactory().createSocket(arg0, arg1);
 104  
     }
 105  
 
 106  
     public Socket createSocket(InetAddress arg0, int arg1, InetAddress arg2, int arg3) throws IOException
 107  
     {
 108  0
         return getFactory().createSocket(arg0, arg1, arg2, arg3);
 109  
     }
 110  
 
 111  
     // see http://forum.java.sun.com/thread.jspa?threadID=701799&messageID=4280973
 112  
     public Socket createSocket() throws IOException
 113  
     {
 114  0
         return getFactory().createSocket();
 115  
     } 
 116  
     
 117  
 }
 118  
 
 119