View Javadoc

1   /*
2    * $Id: JettyHttpsConnector.java 12312 2008-07-12 16:19:18Z dandiep $
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.servlet.jetty;
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  
22  import java.io.IOException;
23  import java.security.Provider;
24  
25  import javax.net.ssl.KeyManagerFactory;
26  import javax.net.ssl.TrustManagerFactory;
27  
28  import org.mortbay.jetty.AbstractConnector;
29  import org.mortbay.jetty.security.SslSocketConnector;
30  
31  /**
32   * The <code>JettyHttpsConnector</code> can be using to embed a Jetty server to receive requests on an http inbound endpoint.
33   * One server is created for each connector declared, Many Jetty endpoints can share the same connector.
34   */
35  
36  public class JettyHttpsConnector extends JettyHttpConnector implements TlsDirectKeyStore, TlsIndirectKeyStore, TlsDirectTrustStore, TlsProtocolHandler
37  {
38  
39      public static final String JETTY_SSL = "jetty-ssl";
40      public static final String HTTPS = "https";
41      public static final String PEER_CERTIFICATES = "PEER_CERTIFICATES";
42      public static final String LOCAL_CERTIFICATES = "LOCAL_CERTIFICATES";
43  
44      private TlsConfiguration tls = new TlsConfiguration(TlsConfiguration.DEFAULT_KEYSTORE);
45  
46      public JettyHttpsConnector()
47      {
48          super();
49          registerSupportedProtocol("https");
50      }
51  
52      protected void doInitialise() throws InitialisationException
53      {
54          try
55          {
56              tls.initialise(false, TlsConfiguration.JSSE_NAMESPACE);
57          }
58          catch (CreateException e)
59          {
60              throw new InitialisationException(e, this);
61          }
62          super.doInitialise();
63      }
64  
65      public String getProtocol()
66      {
67          return JETTY_SSL;
68      }
69  
70      public String getClientKeyStore()
71      {
72          return tls.getClientKeyStore();
73      }
74  
75      public String getClientKeyStorePassword()
76      {
77          return tls.getClientKeyStorePassword();
78      }
79  
80      public String getClientKeyStoreType()
81      {
82          return this.tls.getClientKeyStoreType();
83      }
84  
85      public String getKeyManagerAlgorithm()
86      {
87          return tls.getKeyManagerAlgorithm();
88      }
89  
90      public KeyManagerFactory getKeyManagerFactory()
91      {
92          return tls.getKeyManagerFactory();
93      }
94  
95      public String getKeyPassword()
96      {
97          return tls.getKeyPassword();
98      }
99  
100     public String getKeyStore()
101     {
102         return tls.getKeyStore();
103     }
104 
105     public String getKeyStoreType()
106     {
107         return tls.getKeyStoreType();
108     }
109 
110     public String getProtocolHandler()
111     {
112         return tls.getProtocolHandler();
113     }
114 
115     public Provider getProvider()
116     {
117         return tls.getProvider();
118     }
119 
120     public SecurityProviderFactory getSecurityProviderFactory()
121     {
122         return tls.getSecurityProviderFactory();
123     }
124 
125     public String getSslType()
126     {
127         return tls.getSslType();
128     }
129 
130     public String getKeyStorePassword()
131     {
132         return tls.getKeyStorePassword();
133     }
134 
135     public String getTrustManagerAlgorithm()
136     {
137         return tls.getTrustManagerAlgorithm();
138     }
139 
140     public TrustManagerFactory getTrustManagerFactory()
141     {
142         return tls.getTrustManagerFactory();
143     }
144 
145     public String getTrustStore()
146     {
147         return tls.getTrustStore();
148     }
149 
150     public String getTrustStorePassword()
151     {
152         return tls.getTrustStorePassword();
153     }
154 
155     public String getTrustStoreType()
156     {
157         return tls.getTrustStoreType();
158     }
159 
160     public boolean isExplicitTrustStoreOnly()
161     {
162         return tls.isExplicitTrustStoreOnly();
163     }
164 
165     public boolean isRequireClientAuthentication()
166     {
167         return tls.isRequireClientAuthentication();
168     }
169 
170     public void setClientKeyStore(String clientKeyStore) throws IOException
171     {
172         tls.setClientKeyStore(clientKeyStore);
173     }
174 
175     public void setClientKeyStorePassword(String clientKeyStorePassword)
176     {
177         tls.setClientKeyStorePassword(clientKeyStorePassword);
178     }
179 
180     public void setClientKeyStoreType(String clientKeyStoreType)
181     {
182         this.tls.setClientKeyStoreType(clientKeyStoreType);
183     }
184 
185     public void setExplicitTrustStoreOnly(boolean explicitTrustStoreOnly)
186     {
187         tls.setExplicitTrustStoreOnly(explicitTrustStoreOnly);
188     }
189 
190     public void setKeyManagerAlgorithm(String keyManagerAlgorithm)
191     {
192         tls.setKeyManagerAlgorithm(keyManagerAlgorithm);
193     }
194 
195     public void setKeyPassword(String keyPassword)
196     {
197         tls.setKeyPassword(keyPassword);
198     }
199 
200     public void setKeyStore(String keyStore) throws IOException
201     {
202         tls.setKeyStore(keyStore);
203     }
204 
205     public void setKeyStoreType(String keystoreType)
206     {
207         tls.setKeyStoreType(keystoreType);
208     }
209 
210     public void setProtocolHandler(String protocolHandler)
211     {
212         tls.setProtocolHandler(protocolHandler);
213     }
214 
215     public void setProvider(Provider provider)
216     {
217         tls.setProvider(provider);
218     }
219 
220     public void setRequireClientAuthentication(boolean requireClientAuthentication)
221     {
222         tls.setRequireClientAuthentication(requireClientAuthentication);
223     }
224 
225     public void setSecurityProviderFactory(SecurityProviderFactory spFactory)
226     {
227         tls.setSecurityProviderFactory(spFactory);
228     }
229 
230     public void setSslType(String sslType)
231     {
232         tls.setSslType(sslType);
233     }
234 
235     public void setKeyStorePassword(String storePassword)
236     {
237         tls.setKeyStorePassword(storePassword);
238     }
239 
240     public void setTrustManagerAlgorithm(String trustManagerAlgorithm)
241     {
242         tls.setTrustManagerAlgorithm(trustManagerAlgorithm);
243     }
244 
245     public void setTrustManagerFactory(TrustManagerFactory trustManagerFactory)
246     {
247         tls.setTrustManagerFactory(trustManagerFactory);
248     }
249 
250     public void setTrustStore(String trustStore) throws IOException
251     {
252         tls.setTrustStore(trustStore);
253     }
254 
255     public void setTrustStorePassword(String trustStorePassword)
256     {
257         tls.setTrustStorePassword(trustStorePassword);
258     }
259 
260     public void setTrustStoreType(String trustStoreType)
261     {
262         tls.setTrustStoreType(trustStoreType);
263     }
264 
265     protected AbstractConnector createJettyConnector()
266     {
267         SslSocketConnector cnn = new SslSocketConnector();
268        
269         if(tls.getKeyStore() !=null) cnn.setKeystore(tls.getKeyStore());
270         if(tls.getKeyPassword() !=null) cnn.setKeyPassword(tls.getKeyPassword());
271         if(tls.getKeyStoreType() !=null) cnn.setKeystoreType(tls.getKeyStoreType());
272         if(tls.getKeyManagerAlgorithm() !=null) cnn.setSslKeyManagerFactoryAlgorithm(tls.getKeyManagerAlgorithm());
273         if(tls.getProvider() !=null) cnn.setProvider(tls.getProvider().getName());
274         if(tls.getTrustStorePassword() !=null) cnn.setTrustPassword(tls.getTrustStorePassword());
275         if(tls.getTrustStore() !=null) cnn.setTruststore(tls.getTrustStore());
276         if(tls.getTrustStoreType() !=null) cnn.setTruststoreType(tls.getTrustStoreType());
277         if(tls.getTrustManagerAlgorithm() !=null) cnn.setSslTrustManagerFactoryAlgorithm(tls.getTrustManagerAlgorithm());
278         return cnn;
279     }
280 }