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