Coverage Report - org.mule.api.security.tls.TlsPropertiesSocketFactory
 
Classes in this File Line Coverage Branch Coverage Complexity
TlsPropertiesSocketFactory
0%
0/29
0%
0/2
0
 
 1  
 /*
 2  
  * $Id: TlsPropertiesSocketFactory.java 19191 2010-08-25 21:05:23Z tcarlson $
 3  
  * --------------------------------------------------------------------------------------
 4  
  * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.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.api.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  
     {
 36  0
         super();
 37  0
         logger.debug("creating: " + anon + "; " + namespace);
 38  0
         this.anon = anon;
 39  0
         this.namespace = namespace;
 40  0
     }
 41  
 
 42  
     private synchronized SSLSocketFactory getFactory() throws IOException
 43  
     {
 44  0
         if (null == factory)
 45  
         {
 46  0
             logger.debug("creating factory");
 47  0
             TlsPropertiesMapper propertiesMapper = new TlsPropertiesMapper(namespace);
 48  0
             TlsConfiguration configuration = new TlsConfiguration(TlsConfiguration.DEFAULT_KEYSTORE); 
 49  0
             propertiesMapper.readFromProperties(configuration, System.getProperties());
 50  
             try 
 51  
             {
 52  0
                 configuration.initialise(anon, namespace);
 53  0
                 factory = configuration.getSocketFactory();
 54  
             } 
 55  0
             catch (Exception e)
 56  
             {
 57  0
                 throw (IOException) new IOException(e.getMessage()).initCause(e);
 58  0
             }
 59  
         }
 60  0
         return factory;
 61  
     }
 62  
 
 63  
     @Override
 64  
     public Socket createSocket(Socket s, String host, int port, boolean autoClose) throws IOException
 65  
     {
 66  0
         return getFactory().createSocket(s, host, port, autoClose);
 67  
     }
 68  
 
 69  
     @Override
 70  
     public String[] getDefaultCipherSuites()
 71  
     {
 72  
         try 
 73  
         {
 74  0
             return getFactory().getDefaultCipherSuites();
 75  
         }
 76  0
         catch (Exception e)
 77  
         {
 78  0
             return new String[0];
 79  
         }
 80  
     }
 81  
 
 82  
     @Override
 83  
     public String[] getSupportedCipherSuites()
 84  
     {
 85  
         try 
 86  
         {
 87  0
             return getFactory().getSupportedCipherSuites();
 88  
         }
 89  0
         catch (Exception e)
 90  
         {
 91  0
             return new String[0];
 92  
         }
 93  
     }
 94  
 
 95  
     @Override
 96  
     public Socket createSocket(String host, int port) throws IOException
 97  
     {
 98  0
         return getFactory().createSocket(host, port);
 99  
     }
 100  
 
 101  
     @Override
 102  
     public Socket createSocket(InetAddress host, int port) throws IOException
 103  
     {
 104  0
         return getFactory().createSocket(host, port);
 105  
     }
 106  
 
 107  
     @Override
 108  
     public Socket createSocket(String host, int port, InetAddress localHost, int localPort) throws IOException
 109  
     {
 110  0
         return getFactory().createSocket(host, port);
 111  
     }
 112  
 
 113  
     @Override
 114  
     public Socket createSocket(InetAddress address, int port, InetAddress localAddress, int localPort) throws IOException
 115  
     {
 116  0
         return getFactory().createSocket(address, port, localAddress, localPort);
 117  
     }
 118  
 
 119  
     // see http://forum.java.sun.com/thread.jspa?threadID=701799&messageID=4280973
 120  
     @Override
 121  
     public Socket createSocket() throws IOException
 122  
     {
 123  0
         return getFactory().createSocket();
 124  
     } 
 125  
     
 126  
 }
 127  
 
 128