View Javadoc

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