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