Coverage Report - org.mule.transport.ssl.SslConnector
 
Classes in this File Line Coverage Branch Coverage Complexity
SslConnector
60%
45/75
100%
2/2
1.047
 
 1  
 /*
 2  
  * $Id: SslConnector.java 10489 2008-01-23 17:53:38Z dfeist $
 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.transport.ssl;
 12  
 
 13  
 import org.mule.api.lifecycle.CreateException;
 14  
 import org.mule.api.lifecycle.InitialisationException;
 15  
 import org.mule.api.security.TlsDirectKeyStore;
 16  
 import org.mule.api.security.TlsDirectTrustStore;
 17  
 import org.mule.api.security.TlsIndirectKeyStore;
 18  
 import org.mule.api.security.TlsProtocolHandler;
 19  
 import org.mule.api.security.provider.SecurityProviderFactory;
 20  
 import org.mule.api.security.tls.TlsConfiguration;
 21  
 import org.mule.transport.tcp.TcpConnector;
 22  
 import org.mule.transport.tcp.protocols.DirectProtocol;
 23  
 
 24  
 import java.io.IOException;
 25  
 import java.net.ServerSocket;
 26  
 import java.net.URI;
 27  
 import java.security.Provider;
 28  
 
 29  
 import javax.net.ssl.KeyManagerFactory;
 30  
 import javax.net.ssl.SSLServerSocket;
 31  
 import javax.net.ssl.TrustManagerFactory;
 32  
 
 33  
 /**
 34  
  * <code>SslConnector</code> provides a connector for SSL connections.
 35  
  * Note that the *only* function of the code in this package is to configure and
 36  
  * provide SSL enabled sockets.  All other logic is identical to TCP.
 37  
  */
 38  
 public class SslConnector extends TcpConnector
 39  
         implements TlsDirectKeyStore, TlsIndirectKeyStore, TlsDirectTrustStore, TlsProtocolHandler
 40  
 {
 41  
 
 42  
     public static final String SSL = "ssl";
 43  
     public static final String PEER_CERTIFICATES = "PEER_CERTIFICATES";
 44  
     public static final String LOCAL_CERTIFICATES = "LOCAL_CERTIFICATES";
 45  
 
 46  
     // null initial keystore - see below
 47  58
     private TlsConfiguration tls = new TlsConfiguration(null);
 48  
 
 49  
     public SslConnector()
 50  58
     {
 51  58
         setSocketFactory(new SslSocketFactory(tls));
 52  58
         setServerSocketFactory(new SslServerSocketFactory(tls));
 53  58
         setTcpProtocol(new DirectProtocol());
 54  
         // setting this true causes problems as socket closes before handshake finishes
 55  58
         setValidateConnections(false);
 56  58
     }
 57  
 
 58  
     // @Override
 59  
     protected void doInitialise() throws InitialisationException
 60  
     {
 61  56
         super.doInitialise();
 62  
         // the original logic here was slightly different to other uses of the TlsSupport code -
 63  
         // it appeared to be equivalent to switching anon by whether or not a keyStore was defined
 64  
         // (which seems to make sense), so that is used here.
 65  
         try
 66  
         {
 67  56
             tls.initialise(null == getKeyStore(), TlsConfiguration.JSSE_NAMESPACE);
 68  
         }
 69  0
         catch (CreateException e)
 70  
         {
 71  0
             throw new InitialisationException(e, this);
 72  56
         }
 73  56
     }
 74  
 
 75  
     // @Override
 76  
     protected ServerSocket getServerSocket(URI uri) throws IOException
 77  
     {
 78  52
         SSLServerSocket serverSocket = (SSLServerSocket) super.getServerSocket(uri);
 79  52
         serverSocket.setNeedClientAuth(isRequireClientAuthentication());
 80  52
         return serverSocket;
 81  
     }
 82  
 
 83  
     // @Override
 84  
     public String getProtocol()
 85  
     {
 86  726
         return SSL;
 87  
     }
 88  
 
 89  
     public String getClientKeyStore()
 90  
     {
 91  4
         return tls.getClientKeyStore();
 92  
     }
 93  
 
 94  
     public String getClientKeyStorePassword()
 95  
     {
 96  4
         return tls.getClientKeyStorePassword();
 97  
     }
 98  
 
 99  
     public String getClientKeyStoreType()
 100  
     {
 101  0
         return this.tls.getClientKeyStoreType();
 102  
     }
 103  
 
 104  
     public String getKeyManagerAlgorithm()
 105  
     {
 106  0
         return tls.getKeyManagerAlgorithm();
 107  
     }
 108  
 
 109  
     public KeyManagerFactory getKeyManagerFactory()
 110  
     {
 111  0
         return tls.getKeyManagerFactory();
 112  
     }
 113  
 
 114  
     public String getKeyPassword()
 115  
     {
 116  4
         return tls.getKeyPassword();
 117  
     }
 118  
 
 119  
     public String getKeyStore()
 120  
     {
 121  60
         return tls.getKeyStore();
 122  
     }
 123  
 
 124  
     public String getKeyStoreType()
 125  
     {
 126  0
         return tls.getKeyStoreType();
 127  
     }
 128  
 
 129  
     public String getProtocolHandler()
 130  
     {
 131  2
         return tls.getProtocolHandler();
 132  
     }
 133  
 
 134  
     public Provider getProvider()
 135  
     {
 136  0
         return tls.getProvider();
 137  
     }
 138  
 
 139  
     public SecurityProviderFactory getSecurityProviderFactory()
 140  
     {
 141  0
         return tls.getSecurityProviderFactory();
 142  
     }
 143  
 
 144  
     public String getSslType()
 145  
     {
 146  0
         return tls.getSslType();
 147  
     }
 148  
 
 149  
     public String getKeyStorePassword()
 150  
     {
 151  4
         return tls.getKeyStorePassword();
 152  
     }
 153  
 
 154  
     public String getTrustManagerAlgorithm()
 155  
     {
 156  0
         return tls.getTrustManagerAlgorithm();
 157  
     }
 158  
 
 159  
     public TrustManagerFactory getTrustManagerFactory()
 160  
     {
 161  0
         return tls.getTrustManagerFactory();
 162  
     }
 163  
 
 164  
     public String getTrustStore()
 165  
     {
 166  4
         return tls.getTrustStore();
 167  
     }
 168  
 
 169  
     public String getTrustStorePassword()
 170  
     {
 171  4
         return tls.getTrustStorePassword();
 172  
     }
 173  
 
 174  
     public String getTrustStoreType()
 175  
     {
 176  0
         return tls.getTrustStoreType();
 177  
     }
 178  
 
 179  
     public boolean isExplicitTrustStoreOnly()
 180  
     {
 181  4
         return tls.isExplicitTrustStoreOnly();
 182  
     }
 183  
 
 184  
     public boolean isRequireClientAuthentication()
 185  
     {
 186  56
         return tls.isRequireClientAuthentication();
 187  
     }
 188  
 
 189  
     public void setClientKeyStore(String clientKeyStore) throws IOException
 190  
     {
 191  54
         tls.setClientKeyStore(clientKeyStore);
 192  54
     }
 193  
 
 194  
     public void setClientKeyStorePassword(String clientKeyStorePassword)
 195  
     {
 196  54
         tls.setClientKeyStorePassword(clientKeyStorePassword);
 197  54
     }
 198  
 
 199  
     public void setClientKeyStoreType(String clientKeyStoreType)
 200  
     {
 201  0
         this.tls.setClientKeyStoreType(clientKeyStoreType);
 202  0
     }
 203  
 
 204  
     public void setExplicitTrustStoreOnly(boolean explicitTrustStoreOnly)
 205  
     {
 206  4
         tls.setExplicitTrustStoreOnly(explicitTrustStoreOnly);
 207  4
     }
 208  
 
 209  
     public void setKeyManagerAlgorithm(String keyManagerAlgorithm)
 210  
     {
 211  0
         tls.setKeyManagerAlgorithm(keyManagerAlgorithm);
 212  0
     }
 213  
 
 214  
     public void setKeyPassword(String keyPassword)
 215  
     {
 216  52
         tls.setKeyPassword(keyPassword);
 217  52
     }
 218  
 
 219  
     public void setKeyStore(String keyStore) throws IOException
 220  
     {
 221  52
         tls.setKeyStore(keyStore);
 222  52
     }
 223  
 
 224  
     public void setKeyStoreType(String keystoreType)
 225  
     {
 226  0
         tls.setKeyStoreType(keystoreType);
 227  0
     }
 228  
 
 229  
     public void setProtocolHandler(String protocolHandler)
 230  
     {
 231  4
         tls.setProtocolHandler(protocolHandler);
 232  4
     }
 233  
 
 234  
     public void setProvider(Provider provider)
 235  
     {
 236  0
         tls.setProvider(provider);
 237  0
     }
 238  
 
 239  
     public void setRequireClientAuthentication(boolean requireClientAuthentication)
 240  
     {
 241  4
         tls.setRequireClientAuthentication(requireClientAuthentication);
 242  4
     }
 243  
 
 244  
     public void setSecurityProviderFactory(SecurityProviderFactory spFactory)
 245  
     {
 246  0
         tls.setSecurityProviderFactory(spFactory);
 247  0
     }
 248  
 
 249  
     public void setSslType(String sslType)
 250  
     {
 251  0
         tls.setSslType(sslType);
 252  0
     }
 253  
 
 254  
     public void setKeyStorePassword(String storePassword)
 255  
     {
 256  52
         tls.setKeyStorePassword(storePassword);
 257  52
     }
 258  
 
 259  
     public void setTrustManagerAlgorithm(String trustManagerAlgorithm)
 260  
     {
 261  0
         tls.setTrustManagerAlgorithm(trustManagerAlgorithm);
 262  0
     }
 263  
 
 264  
     public void setTrustManagerFactory(TrustManagerFactory trustManagerFactory)
 265  
     {
 266  0
         tls.setTrustManagerFactory(trustManagerFactory);
 267  0
     }
 268  
 
 269  
     public void setTrustStore(String trustStore) throws IOException
 270  
     {
 271  52
         tls.setTrustStore(trustStore);
 272  52
     }
 273  
 
 274  
     public void setTrustStorePassword(String trustStorePassword)
 275  
     {
 276  52
         tls.setTrustStorePassword(trustStorePassword);
 277  52
     }
 278  
 
 279  
     public void setTrustStoreType(String trustStoreType)
 280  
     {
 281  0
         tls.setTrustStoreType(trustStoreType);
 282  0
     }
 283  
 
 284  
 }