KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > geronimo > jetty6 > connector > HTTPSConnector


1 /**
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements. See the NOTICE file distributed with
4  * this work for additional information regarding copyright ownership.
5  * The ASF licenses this file to You under the Apache License, Version 2.0
6  * (the "License"); you may not use this file except in compliance with
7  * the License. You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */

17
18 package org.apache.geronimo.jetty6.connector;
19
20 import javax.net.ssl.KeyManagerFactory;
21 import org.apache.geronimo.gbean.GBeanInfo;
22 import org.apache.geronimo.gbean.GBeanInfoBuilder;
23 import org.apache.geronimo.j2ee.j2eeobjectnames.NameFactory;
24 import org.apache.geronimo.jetty6.JettyContainer;
25 import org.apache.geronimo.jetty6.JettySecureConnector;
26 import org.apache.geronimo.management.geronimo.KeystoreManager;
27 import org.apache.geronimo.management.geronimo.WebManager;
28
29 /**
30  * Implementation of a HTTPS connector based on Jetty's SslConnector (which uses pure JSSE).
31  *
32  * @version $Rev: 482336 $ $Date: 2006-12-04 15:12:19 -0500 (Mon, 04 Dec 2006) $
33  */

34 public class HTTPSConnector extends JettyConnector implements JettySecureConnector {
35     private final GeronimoSSLListener https;
36     private String JavaDoc algorithm;
37
38     public HTTPSConnector(JettyContainer container, KeystoreManager keystoreManager) {
39         super(container, new GeronimoSSLListener(keystoreManager));
40         https = (GeronimoSSLListener) listener;
41     }
42
43     public int getDefaultPort() {
44         return 443;
45     }
46
47     public String JavaDoc getProtocol() {
48         return WebManager.PROTOCOL_HTTPS;
49     }
50
51     public String JavaDoc getAlgorithm() {
52         return algorithm;
53     }
54
55     /**
56      * Algorithm to use.
57      * As different JVMs have different implementations available, the default algorithm can be used by supplying the value "Default".
58      *
59      * @param algorithm the algorithm to use, or "Default" to use the default from {@link javax.net.ssl.KeyManagerFactory#getDefaultAlgorithm()}
60      */

61     public void setAlgorithm(String JavaDoc algorithm) {
62         // cache the value so the null
63
this.algorithm = algorithm;
64         if ("default".equalsIgnoreCase(algorithm)) {
65             algorithm = KeyManagerFactory.getDefaultAlgorithm();
66         }
67         https.setSslKeyManagerFactoryAlgorithm(algorithm);
68     }
69
70     public String JavaDoc getSecureProtocol() {
71         return https.getProtocol();
72     }
73
74     public void setSecureProtocol(String JavaDoc protocol) {
75         https.setProtocol(protocol);
76     }
77
78     public void setClientAuthRequired(boolean needClientAuth) {
79         https.setNeedClientAuth(needClientAuth);
80     }
81
82     public boolean isClientAuthRequired() {
83         return https.getNeedClientAuth();
84     }
85
86     public void setClientAuthRequested(boolean wantClientAuth) {
87         https.setWantClientAuth(wantClientAuth);
88     }
89
90     public boolean isClientAuthRequested() {
91         return https.getWantClientAuth();
92     }
93
94     public void setKeyStore(String JavaDoc keyStore) {
95         https.setKeyStore(keyStore);
96     }
97
98     public String JavaDoc getKeyStore() {
99         return https.getKeyStore();
100     }
101
102     public void setTrustStore(String JavaDoc trustStore) {
103         https.setTrustStore(trustStore);
104     }
105
106     public String JavaDoc getTrustStore() {
107         return https.getTrustStore();
108     }
109
110     public void setKeyAlias(String JavaDoc keyAlias) {
111         https.setKeyAlias(keyAlias);
112     }
113
114     public String JavaDoc getKeyAlias() {
115         return https.getKeyAlias();
116     }
117
118     public static final GBeanInfo GBEAN_INFO;
119
120     static {
121         GBeanInfoBuilder infoFactory = GBeanInfoBuilder.createStatic("Jetty Connector HTTPS", HTTPSConnector.class, JettyConnector.GBEAN_INFO);
122         infoFactory.addAttribute("algorithm", String JavaDoc.class, true, true);
123         infoFactory.addAttribute("secureProtocol", String JavaDoc.class, true, true);
124         infoFactory.addAttribute("keyStore", String JavaDoc.class, true, true);
125         infoFactory.addAttribute("keyAlias", String JavaDoc.class, true, true);
126         infoFactory.addAttribute("trustStore", String JavaDoc.class, true, true);
127         infoFactory.addAttribute("clientAuthRequired", boolean.class, true, true);
128         infoFactory.addAttribute("clientAuthRequested", boolean.class, true, true);
129         infoFactory.addReference("KeystoreManager", KeystoreManager.class, NameFactory.GERONIMO_SERVICE);
130         infoFactory.addInterface(JettySecureConnector.class);
131         infoFactory.setConstructor(new String JavaDoc[]{"JettyContainer", "KeystoreManager"});
132         GBEAN_INFO = infoFactory.getBeanInfo();
133     }
134
135     public static GBeanInfo getGBeanInfo() {
136         return GBEAN_INFO;
137     }
138
139     // ================= NO LONGER USED!!! =====================
140
// todo: remove these from the SSL interface
141

142     public String JavaDoc getKeystoreFileName() {
143         return null;
144     }
145
146     public void setKeystoreFileName(String JavaDoc name) {
147     }
148
149     public void setKeystorePassword(String JavaDoc password) {
150     }
151
152     public String JavaDoc getKeystoreType() {
153         return null;
154     }
155
156     public void setKeystoreType(String JavaDoc type) {
157     }
158 }
159
Popular Tags