KickJava   Java API By Example, From Geeks To Geeks.

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


1 /**
2  *
3  * Copyright 2003-2004 The Apache Software Foundation
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * 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.jetty.connector;
19
20 import javax.net.ssl.KeyManagerFactory;
21
22 import org.mortbay.http.SslListener;
23
24 import org.apache.geronimo.gbean.GBeanInfo;
25 import org.apache.geronimo.gbean.GBeanInfoBuilder;
26 import org.apache.geronimo.j2ee.j2eeobjectnames.NameFactory;
27 import org.apache.geronimo.jetty.JettyContainer;
28 import org.apache.geronimo.system.serverinfo.ServerInfo;
29
30 /**
31  * Implementation of a HTTPS connector based on Jetty's SslConnector (which uses pure JSSE).
32  *
33  * @version $Rev: 165331 $ $Date: 2005-04-29 11:51:02 -0700 (Fri, 29 Apr 2005) $
34  */

35 public class HTTPSConnector extends JettyConnector {
36     private final SslListener https;
37     private final ServerInfo serverInfo;
38     private String JavaDoc keystore;
39     private String JavaDoc algorithm;
40
41     public HTTPSConnector(JettyContainer container, ServerInfo serverInfo) {
42         super(container, new SslListener());
43         this.serverInfo = serverInfo;
44         https = (SslListener) listener;
45     }
46
47     public String JavaDoc getKeystore() {
48         // this does not delegate to https as it needs to be resolved against ServerInfo
49
return keystore;
50     }
51
52     public void setKeystore(String JavaDoc keystore) {
53         // this does not delegate to https as it needs to be resolved against ServerInfo
54
this.keystore = keystore;
55     }
56
57     public String JavaDoc getAlgorithm() {
58         return algorithm;
59     }
60
61     /**
62      * Algorithm to use.
63      * As different JVMs have different implementations available, the default
64      * algorithm can be used by supplying a null value.
65      *
66      * @param algorithm the algorithm to use, or null to use the default from {@link javax.net.ssl.KeyManagerFactory#getDefaultAlgorithm()}
67      */

68     public void setAlgorithm(String JavaDoc algorithm) {
69         // cache the value so the null
70
this.algorithm = algorithm;
71         if (algorithm == null) {
72             algorithm = KeyManagerFactory.getDefaultAlgorithm();
73         }
74         https.setAlgorithm(algorithm);
75     }
76
77     public void setPassword(String JavaDoc password) {
78         https.setPassword(password);
79     }
80
81     public void setKeyPassword(String JavaDoc password) {
82         https.setKeyPassword(password);
83     }
84
85     public String JavaDoc getProtocol() {
86         return https.getProtocol();
87     }
88
89     public void setProtocol(String JavaDoc protocol) {
90         https.setProtocol(protocol);
91     }
92
93     public String JavaDoc getKeystoreType() {
94         return https.getKeystoreType();
95     }
96
97     public void setKeystoreType(String JavaDoc keystoreType) {
98         https.setKeystoreType(keystoreType);
99     }
100
101     public void setNeedClientAuth(boolean needClientAuth) {
102         https.setNeedClientAuth(needClientAuth);
103     }
104
105     public boolean getNeedClientAuth() {
106         return https.getNeedClientAuth();
107     }
108
109     public void doStart() throws Exception JavaDoc {
110         https.setKeystore(serverInfo.resolvePath(keystore));
111         super.doStart();
112     }
113
114     public static final GBeanInfo GBEAN_INFO;
115
116     static {
117         GBeanInfoBuilder infoFactory = new GBeanInfoBuilder("Jetty HTTPS Connector", HTTPSConnector.class, JettyConnector.GBEAN_INFO);
118         infoFactory.addAttribute("keystore", String JavaDoc.class, true);
119         infoFactory.addAttribute("algorithm", String JavaDoc.class, true);
120         infoFactory.addAttribute("keyPassword", String JavaDoc.class, true);
121         infoFactory.addAttribute("keystoreType", String JavaDoc.class, true);
122         infoFactory.addAttribute("needClientAuth", boolean.class, true);
123         infoFactory.addAttribute("password", String JavaDoc.class, true);
124         infoFactory.addAttribute("protocol", String JavaDoc.class, true);
125         infoFactory.addReference("ServerInfo", ServerInfo.class, NameFactory.GERONIMO_SERVICE);
126         infoFactory.setConstructor(new String JavaDoc[]{"JettyContainer", "ServerInfo"});
127         GBEAN_INFO = infoFactory.getBeanInfo();
128     }
129
130     public static GBeanInfo getGBeanInfo() {
131         return GBEAN_INFO;
132     }
133 }
134
Popular Tags