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: package org.apache.geronimo.tomcat.connector;
020:
021: import java.util.Map;
022:
023: import javax.net.ssl.KeyManagerFactory;
024:
025: import org.apache.geronimo.gbean.GBeanInfo;
026: import org.apache.geronimo.gbean.GBeanInfoBuilder;
027: import org.apache.geronimo.management.geronimo.WebManager;
028: import org.apache.geronimo.system.serverinfo.ServerInfo;
029: import org.apache.geronimo.tomcat.TomcatContainer;
030:
031: public abstract class AbstractHttp11ConnectorGBean extends
032: BaseHttp11ConnectorGBean implements Http11Protocol {
033: private String keystoreFileName;
034:
035: private String truststoreFileName;
036:
037: private String algorithm;
038:
039: public AbstractHttp11ConnectorGBean(String name, Map initParams,
040: String tomcatProtocol, String host, int port,
041: TomcatContainer container, ServerInfo serverInfo)
042: throws Exception {
043: super (name, initParams, tomcatProtocol, host, port, container,
044: serverInfo);
045: }
046:
047: @Override
048: public int getDefaultPort() {
049: return 80;
050: }
051:
052: @Override
053: public String getGeronimoProtocol() {
054: return WebManager.PROTOCOL_HTTP;
055: }
056:
057: // Generic SSL
058: public String getAlgorithm() {
059: return algorithm;
060: }
061:
062: public String getCiphers() {
063: return (String) connector.getAttribute("ciphers");
064: }
065:
066: public boolean getClientAuth() {
067: Object value = connector.getAttribute("clientAuth");
068: return value == null ? false : new Boolean(value.toString())
069: .booleanValue();
070: }
071:
072: public String getKeyAlias() {
073: return (String) connector.getAttribute("keyAlias");
074: }
075:
076: public String getKeystoreFile() {
077: return keystoreFileName;
078: }
079:
080: public String getKeystoreType() {
081: return (String) connector.getAttribute("keystoreType");
082: }
083:
084: public String getSslProtocol() {
085: return (String) connector.getAttribute("sslProtocol");
086: }
087:
088: public String getTruststoreFile() {
089: return truststoreFileName;
090: }
091:
092: public String getTruststoreType() {
093: return (String) connector.getAttribute("truststoreType");
094: }
095:
096: public String getTruststorePass() {
097: return (String) connector.getAttribute("truststorePass");
098: }
099:
100: public String getKeystorePass() {
101: return (String) connector.getAttribute("keystorePass");
102: }
103:
104: public void setAlgorithm(String algorithm) {
105: this .algorithm = algorithm;
106: if ("default".equalsIgnoreCase(algorithm)) {
107: algorithm = KeyManagerFactory.getDefaultAlgorithm();
108: }
109: connector.setAttribute("algorithm", algorithm);
110: }
111:
112: public void setCiphers(String ciphers) {
113: connector.setAttribute("ciphers", ciphers);
114: }
115:
116: public void setClientAuth(boolean clientAuth) {
117: connector.setAttribute("clientAuth", new Boolean(clientAuth));
118: }
119:
120: public void setKeyAlias(String keyAlias) {
121: if (keyAlias.equals(""))
122: keyAlias = null;
123: connector.setAttribute("keyAlias", keyAlias);
124: }
125:
126: public void setKeystoreFile(String keystoreFile) {
127: if (keystoreFile != null && keystoreFile.equals(""))
128: keystoreFile = null;
129: keystoreFileName = keystoreFile;
130: if (keystoreFileName == null)
131: connector.setAttribute("keystoreFile", null);
132: else
133: connector.setAttribute("keystoreFile", serverInfo
134: .resolveServerPath(keystoreFileName));
135: }
136:
137: public void setKeystorePass(String keystorePass) {
138: if (keystorePass != null && keystorePass.equals(""))
139: keystorePass = null;
140: connector.setAttribute("keystorePass", keystorePass);
141: }
142:
143: public void setKeystoreType(String keystoreType) {
144: if (keystoreType != null && keystoreType.equals(""))
145: keystoreType = null;
146: connector.setAttribute("keystoreType", keystoreType);
147: }
148:
149: public void setSslProtocol(String sslProtocol) {
150: if (sslProtocol != null && sslProtocol.equals(""))
151: sslProtocol = null;
152: connector.setAttribute("sslProtocol", sslProtocol);
153: }
154:
155: public void setTruststoreFile(String truststoreFile) {
156: if (truststoreFile != null && truststoreFile.equals(""))
157: truststoreFile = null;
158: truststoreFileName = truststoreFile;
159: if (truststoreFileName == null)
160: connector.setAttribute("truststoreFile", null);
161: else
162: connector.setAttribute("truststoreFile", serverInfo
163: .resolveServerPath(truststoreFileName));
164: }
165:
166: public void setTruststorePass(String truststorePass) {
167: if (truststorePass != null && truststorePass.equals(""))
168: truststorePass = null;
169: connector.setAttribute("truststorePass", truststorePass);
170: }
171:
172: public void setTruststoreType(String truststoreType) {
173: if (truststoreType != null && truststoreType.equals(""))
174: truststoreType = null;
175: connector.setAttribute("truststoreType", truststoreType);
176: }
177:
178: public static final GBeanInfo GBEAN_INFO;
179:
180: static {
181: GBeanInfoBuilder infoFactory = GBeanInfoBuilder.createStatic(
182: "Tomcat Connector", AbstractHttp11ConnectorGBean.class,
183: BaseHttp11ConnectorGBean.GBEAN_INFO);
184: infoFactory.addInterface(Http11Protocol.class, new String[] {
185: //SSL Attributes
186: "algorithm", "clientAuth", "keystoreFile",
187: "keystorePass", "keystoreType", "sslProtocol",
188: "ciphers", "keyAlias", "truststoreFile",
189: "truststorePass", "truststoreType" }, new String[] {
190: //SSL Attributes
191: "algorithm", "clientAuth", "keystoreFile",
192: "keystorePass", "keystoreType", "sslProtocol",
193: "ciphers", "keyAlias", "truststoreFile",
194: "truststorePass", "truststoreType" });
195: infoFactory.setConstructor(new String[] { "name", "initParams",
196: "tomcatProtocol", "host", "port", "TomcatContainer",
197: "ServerInfo" });
198: GBEAN_INFO = infoFactory.getBeanInfo();
199: }
200:
201: public static GBeanInfo getGBeanInfo() {
202: return GBEAN_INFO;
203: }
204:
205: }
|