Coverage Report - org.mule.transport.http.HttpsConnector
 
Classes in this File Line Coverage Branch Coverage Complexity
HttpsConnector
55%
41/74
N/A
1.047
 
 1  
 /*
 2  
  * $Id: HttpsConnector.java 11989 2008-06-10 15:18:30Z rossmason $
 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.http;
 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.ssl.SslServerSocketFactory;
 22  
 import org.mule.transport.ssl.SslSocketFactory;
 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>HttpsConnector</code> provides Secure http connectivity on top of what is already provided with the
 35  
  * Mule {@link org.mule.transport.http.HttpConnector}.
 36  
  */
 37  
 public class HttpsConnector extends HttpConnector
 38  
         implements TlsDirectKeyStore, TlsIndirectKeyStore, TlsDirectTrustStore, TlsProtocolHandler
 39  
 {
 40  
 
 41  
     public static final String HTTPS = "https";
 42  
     public static final String PEER_CERTIFICATES = "PEER_CERTIFICATES";
 43  
     public static final String LOCAL_CERTIFICATES = "LOCAL_CERTIFICATES";
 44  
 
 45  30
     private TlsConfiguration tls = new TlsConfiguration(TlsConfiguration.DEFAULT_KEYSTORE);
 46  
 
 47  
     public HttpsConnector()
 48  30
     {
 49  30
         setSocketFactory(new SslSocketFactory(tls));
 50  30
         setServerSocketFactory(new SslServerSocketFactory(tls));
 51  
         // setting this true causes problems as socket closes before handshake finishes
 52  30
         setValidateConnections(false);
 53  30
     }
 54  
 
 55  
     // @Override
 56  
     protected ServerSocket getServerSocket(URI uri) throws IOException
 57  
     {
 58  0
         SSLServerSocket serverSocket = (SSLServerSocket) super.getServerSocket(uri);
 59  0
         serverSocket.setNeedClientAuth(isRequireClientAuthentication());
 60  0
         return serverSocket;
 61  
     }
 62  
 
 63  
     protected void doInitialise() throws InitialisationException
 64  
     {
 65  
         try
 66  
         {
 67  30
             tls.initialise(false, TlsConfiguration.JSSE_NAMESPACE);
 68  
         }
 69  0
         catch (CreateException e)
 70  
         {
 71  0
             throw new InitialisationException(e, this);
 72  30
         }
 73  30
         super.doInitialise();
 74  30
     }
 75  
 
 76  
     public String getProtocol()
 77  
     {
 78  64
         return HTTPS;
 79  
     }
 80  
 
 81  
     public String getClientKeyStore()
 82  
     {
 83  2
         return tls.getClientKeyStore();
 84  
     }
 85  
 
 86  
     public String getClientKeyStorePassword()
 87  
     {
 88  2
         return tls.getClientKeyStorePassword();
 89  
     }
 90  
 
 91  
     public String getClientKeyStoreType()
 92  
     {
 93  0
         return this.tls.getClientKeyStoreType();
 94  
     }
 95  
 
 96  
     public String getKeyManagerAlgorithm()
 97  
     {
 98  0
         return tls.getKeyManagerAlgorithm();
 99  
     }
 100  
 
 101  
     public KeyManagerFactory getKeyManagerFactory()
 102  
     {
 103  0
         return tls.getKeyManagerFactory();
 104  
     }
 105  
 
 106  
     public String getKeyPassword()
 107  
     {
 108  2
         return tls.getKeyPassword();
 109  
     }
 110  
 
 111  
     public String getKeyStore()
 112  
     {
 113  2
         return tls.getKeyStore();
 114  
     }
 115  
 
 116  
     public String getKeyStoreType()
 117  
     {
 118  0
         return tls.getKeyStoreType();
 119  
     }
 120  
 
 121  
     public String getProtocolHandler()
 122  
     {
 123  2
         return tls.getProtocolHandler();
 124  
     }
 125  
 
 126  
     public Provider getProvider()
 127  
     {
 128  0
         return tls.getProvider();
 129  
     }
 130  
 
 131  
     public SecurityProviderFactory getSecurityProviderFactory()
 132  
     {
 133  0
         return tls.getSecurityProviderFactory();
 134  
     }
 135  
 
 136  
     public String getSslType()
 137  
     {
 138  0
         return tls.getSslType();
 139  
     }
 140  
 
 141  
     public String getKeyStorePassword()
 142  
     {
 143  2
         return tls.getKeyStorePassword();
 144  
     }
 145  
 
 146  
     public String getTrustManagerAlgorithm()
 147  
     {
 148  0
         return tls.getTrustManagerAlgorithm();
 149  
     }
 150  
 
 151  
     public TrustManagerFactory getTrustManagerFactory()
 152  
     {
 153  0
         return tls.getTrustManagerFactory();
 154  
     }
 155  
 
 156  
     public String getTrustStore()
 157  
     {
 158  2
         return tls.getTrustStore();
 159  
     }
 160  
 
 161  
     public String getTrustStorePassword()
 162  
     {
 163  2
         return tls.getTrustStorePassword();
 164  
     }
 165  
 
 166  
     public String getTrustStoreType()
 167  
     {
 168  0
         return tls.getTrustStoreType();
 169  
     }
 170  
 
 171  
     public boolean isExplicitTrustStoreOnly()
 172  
     {
 173  2
         return tls.isExplicitTrustStoreOnly();
 174  
     }
 175  
 
 176  
     public boolean isRequireClientAuthentication()
 177  
     {
 178  2
         return tls.isRequireClientAuthentication();
 179  
     }
 180  
 
 181  
     public void setClientKeyStore(String clientKeyStore) throws IOException
 182  
     {
 183  30
         tls.setClientKeyStore(clientKeyStore);
 184  30
     }
 185  
 
 186  
     public void setClientKeyStorePassword(String clientKeyStorePassword)
 187  
     {
 188  30
         tls.setClientKeyStorePassword(clientKeyStorePassword);
 189  30
     }
 190  
 
 191  
     public void setClientKeyStoreType(String clientKeyStoreType)
 192  
     {
 193  0
         this.tls.setClientKeyStoreType(clientKeyStoreType);
 194  0
     }
 195  
 
 196  
     public void setExplicitTrustStoreOnly(boolean explicitTrustStoreOnly)
 197  
     {
 198  8
         tls.setExplicitTrustStoreOnly(explicitTrustStoreOnly);
 199  8
     }
 200  
 
 201  
     public void setKeyManagerAlgorithm(String keyManagerAlgorithm)
 202  
     {
 203  0
         tls.setKeyManagerAlgorithm(keyManagerAlgorithm);
 204  0
     }
 205  
 
 206  
     public void setKeyPassword(String keyPassword)
 207  
     {
 208  30
         tls.setKeyPassword(keyPassword);
 209  30
     }
 210  
 
 211  
     public void setKeyStore(String keyStore) throws IOException
 212  
     {
 213  30
         tls.setKeyStore(keyStore);
 214  30
     }
 215  
 
 216  
     public void setKeyStoreType(String keystoreType)
 217  
     {
 218  0
         tls.setKeyStoreType(keystoreType);
 219  0
     }
 220  
 
 221  
     public void setProtocolHandler(String protocolHandler)
 222  
     {
 223  4
         tls.setProtocolHandler(protocolHandler);
 224  4
     }
 225  
 
 226  
     public void setProvider(Provider provider)
 227  
     {
 228  0
         tls.setProvider(provider);
 229  0
     }
 230  
 
 231  
     public void setRequireClientAuthentication(boolean requireClientAuthentication)
 232  
     {
 233  8
         tls.setRequireClientAuthentication(requireClientAuthentication);
 234  8
     }
 235  
 
 236  
     public void setSecurityProviderFactory(SecurityProviderFactory spFactory)
 237  
     {
 238  0
         tls.setSecurityProviderFactory(spFactory);
 239  0
     }
 240  
 
 241  
     public void setSslType(String sslType)
 242  
     {
 243  0
         tls.setSslType(sslType);
 244  0
     }
 245  
 
 246  
     public void setKeyStorePassword(String storePassword)
 247  
     {
 248  30
         tls.setKeyStorePassword(storePassword);
 249  30
     }
 250  
 
 251  
     public void setTrustManagerAlgorithm(String trustManagerAlgorithm)
 252  
     {
 253  0
         tls.setTrustManagerAlgorithm(trustManagerAlgorithm);
 254  0
     }
 255  
 
 256  
     public void setTrustManagerFactory(TrustManagerFactory trustManagerFactory)
 257  
     {
 258  0
         tls.setTrustManagerFactory(trustManagerFactory);
 259  0
     }
 260  
 
 261  
     public void setTrustStore(String trustStore) throws IOException
 262  
     {
 263  30
         tls.setTrustStore(trustStore);
 264  30
     }
 265  
 
 266  
     public void setTrustStorePassword(String trustStorePassword)
 267  
     {
 268  30
         tls.setTrustStorePassword(trustStorePassword);
 269  30
     }
 270  
 
 271  
     public void setTrustStoreType(String trustStoreType)
 272  
     {
 273  0
         tls.setTrustStoreType(trustStoreType);
 274  0
     }
 275  
 
 276  
 }