001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one
003: * or more contributor license agreements. See the NOTICE file
004: * distributed with this work for additional information
005: * regarding copyright ownership. The ASF licenses this file
006: * to you under the Apache License, Version 2.0 (the
007: * "License"); you may not use this file except in compliance
008: * with the License. You may obtain a copy of the License at
009: *
010: * http://www.apache.org/licenses/LICENSE-2.0
011: *
012: * Unless required by applicable law or agreed to in writing,
013: * software distributed under the License is distributed on an
014: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015: * KIND, either express or implied. See the License for the
016: * specific language governing permissions and limitations
017: * under the License.
018: */
019:
020: package org.apache.geronimo.jetty6.connector;
021:
022: import javax.net.ssl.KeyManagerFactory;
023:
024: import org.apache.geronimo.gbean.GBeanInfo;
025: import org.apache.geronimo.gbean.GBeanInfoBuilder;
026: import org.apache.geronimo.j2ee.j2eeobjectnames.NameFactory;
027: import org.apache.geronimo.jetty6.JettyContainer;
028: import org.apache.geronimo.jetty6.JettySecureConnector;
029: import org.apache.geronimo.management.geronimo.KeystoreManager;
030: import org.apache.geronimo.management.geronimo.WebManager;
031: import org.apache.geronimo.system.threads.ThreadPool;
032: import org.mortbay.jetty.nio.SelectChannelConnector;
033:
034: /**
035: * Implementation of a HTTPS connector based on Jetty's SslConnector (which uses pure JSSE).
036: *
037: * @version $Rev: 564252 $ $Date: 2007-08-09 09:02:09 -0700 (Thu, 09 Aug 2007) $
038: */
039: public class HTTPSSelectChannelConnector extends JettyConnector
040: implements JettySecureConnector {
041: private final GeronimoSelectChannelSSLListener https;
042: private String algorithm;
043:
044: public HTTPSSelectChannelConnector(JettyContainer container,
045: ThreadPool threadPool, KeystoreManager keystoreManager) {
046: super (container, new GeronimoSelectChannelSSLListener(
047: keystoreManager), threadPool,
048: "HTTPSSelectChannelConnector");
049: https = (GeronimoSelectChannelSSLListener) listener;
050: }
051:
052: public int getDefaultPort() {
053: return 443;
054: }
055:
056: public String getProtocol() {
057: return WebManager.PROTOCOL_HTTPS;
058: }
059:
060: public String getAlgorithm() {
061: return algorithm;
062: }
063:
064: /**
065: * Algorithm to use.
066: * As different JVMs have different implementations available, the default algorithm can be used by supplying the value "Default".
067: *
068: * @param algorithm the algorithm to use, or "Default" to use the default from {@link javax.net.ssl.KeyManagerFactory#getDefaultAlgorithm()}
069: */
070: public void setAlgorithm(String algorithm) {
071: // cache the value so the null
072: this .algorithm = algorithm;
073: if ("default".equalsIgnoreCase(algorithm)) {
074: algorithm = KeyManagerFactory.getDefaultAlgorithm();
075: }
076: https.setSslKeyManagerFactoryAlgorithm(algorithm);
077: }
078:
079: public String getSecureProtocol() {
080: return https.getProtocol();
081: }
082:
083: public void setSecureProtocol(String protocol) {
084: https.setProtocol(protocol);
085: }
086:
087: public void setClientAuthRequired(boolean needClientAuth) {
088: https.setNeedClientAuth(needClientAuth);
089: }
090:
091: public boolean isClientAuthRequired() {
092: return https.getNeedClientAuth();
093: }
094:
095: public void setClientAuthRequested(boolean wantClientAuth) {
096: https.setWantClientAuth(wantClientAuth);
097: }
098:
099: public boolean isClientAuthRequested() {
100: return https.getWantClientAuth();
101: }
102:
103: public void setKeyStore(String keyStore) {
104: https.setKeyStore(keyStore);
105: }
106:
107: public String getKeyStore() {
108: return https.getKeyStore();
109: }
110:
111: public void setTrustStore(String trustStore) {
112: https.setTrustStore(trustStore);
113: }
114:
115: public String getTrustStore() {
116: return https.getTrustStore();
117: }
118:
119: public void setKeyAlias(String keyAlias) {
120: https.setKeyAlias(keyAlias);
121: }
122:
123: public String getKeyAlias() {
124: return https.getKeyAlias();
125: }
126:
127: //TODO does this make sense???
128: public void setRedirectPort(int port) {
129: SelectChannelConnector socketListener = (SelectChannelConnector) listener;
130: socketListener.setConfidentialPort(port);
131: socketListener.setIntegralPort(port);
132: socketListener.setIntegralScheme("https");
133: socketListener.setConfidentialScheme("https");
134: }
135:
136: public static final GBeanInfo GBEAN_INFO;
137:
138: static {
139: GBeanInfoBuilder infoFactory = GBeanInfoBuilder.createStatic(
140: "Jetty SelectChannel Connector HTTPS",
141: HTTPSSelectChannelConnector.class,
142: JettyConnector.GBEAN_INFO);
143: infoFactory.addAttribute("algorithm", String.class, true, true);
144: infoFactory.addAttribute("secureProtocol", String.class, true,
145: true);
146: infoFactory.addAttribute("keyStore", String.class, true, true);
147: infoFactory.addAttribute("keyAlias", String.class, true, true);
148: infoFactory
149: .addAttribute("trustStore", String.class, true, true);
150: infoFactory.addAttribute("clientAuthRequired", boolean.class,
151: true, true);
152: infoFactory.addAttribute("clientAuthRequested", boolean.class,
153: true, true);
154: infoFactory.addReference("KeystoreManager",
155: KeystoreManager.class, NameFactory.GERONIMO_SERVICE);
156: infoFactory.addInterface(JettySecureConnector.class);
157: infoFactory.setConstructor(new String[] { "JettyContainer",
158: "ThreadPool", "KeystoreManager" });
159: GBEAN_INFO = infoFactory.getBeanInfo();
160: }
161:
162: public static GBeanInfo getGBeanInfo() {
163: return GBEAN_INFO;
164: }
165:
166: // ================= NO LONGER USED!!! =====================
167: // todo: remove these from the SSL interface
168:
169: public String getKeystoreFileName() {
170: return null;
171: }
172:
173: public void setKeystoreFileName(String name) {
174: }
175:
176: public void setKeystorePassword(String password) {
177: }
178:
179: public String getKeystoreType() {
180: return null;
181: }
182:
183: public void setKeystoreType(String type) {
184: }
185: }
|