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