1 17 package org.apache.geronimo.tomcat; 18 19 import java.util.Map ; 20 import javax.net.ssl.KeyManagerFactory; 21 22 import org.apache.geronimo.management.geronimo.WebManager; 23 import org.apache.geronimo.system.serverinfo.ServerInfo; 24 import org.apache.geronimo.gbean.GBeanInfo; 25 import org.apache.geronimo.gbean.GBeanInfoBuilder; 26 27 34 public class HttpsConnectorGBean extends ConnectorGBean implements TomcatSecureConnector { 35 private final ServerInfo serverInfo; 36 private String keystoreFileName; 37 private String truststoreFileName; 38 private String algorithm; 39 40 public HttpsConnectorGBean(String name, String protocol, String host, int port, TomcatContainer container, ServerInfo serverInfo) throws Exception { 41 super(name, protocol, host, port, container); 42 43 if (serverInfo == null){ 44 throw new IllegalArgumentException ("serverInfo cannot be null."); 45 } 46 47 this.serverInfo = serverInfo; 48 } 49 50 56 protected void initializeParams(String protocol, Map params) { 57 super.initializeParams(protocol, params); 58 params.put("scheme", "https"); 59 params.put("secure", "true"); 60 } 61 62 67 protected void validateProtocol(String protocol) { 68 if(protocol != null && !protocol.equals(WebManager.PROTOCOL_HTTPS)) { 69 throw new IllegalStateException ("HttpsConnectorGBean only supports "+WebManager.PROTOCOL_HTTPS); 70 } 71 } 72 73 78 public String getKeystoreFileName() { 79 return keystoreFileName; } 81 82 87 public void setKeystoreFileName(String name) { 88 keystoreFileName = name; 89 connector.setAttribute("keystoreFile", serverInfo.resolveServerPath(keystoreFileName)); 90 } 91 92 public String getTruststoreFileName() { 93 return truststoreFileName; } 95 96 public void setTruststoreFileName(String name) { 97 truststoreFileName = name; 98 connector.setAttribute("truststoreFile", serverInfo.resolveServerPath(truststoreFileName)); 99 } 100 101 108 public void setKeystorePassword(String password) { 109 connector.setAttribute("keystorePass", password); 110 } 111 112 public void setTruststorePassword(String password) { 113 connector.setAttribute("truststorePass", password); 114 } 115 116 121 public String getKeystoreType() { 122 return (String )connector.getAttribute("keystoreType"); 123 } 124 125 130 public void setKeystoreType(String type) { 131 connector.setAttribute("keystoreType", type); 132 } 133 134 public String getTruststoreType() { 135 return (String )connector.getAttribute("truststoreType"); 136 } 137 138 public void setTruststoreType(String type) { 139 connector.setAttribute("truststoreType", type); 140 } 141 142 147 public String getAlgorithm() { 148 return algorithm; 149 } 150 151 156 public void setAlgorithm(String algorithm) { 157 this.algorithm = algorithm; 158 if ("default".equalsIgnoreCase(algorithm)) { 159 algorithm = KeyManagerFactory.getDefaultAlgorithm(); 160 } 161 connector.setAttribute("algorithm", algorithm); 162 } 163 164 170 public String getSecureProtocol() { 171 return (String )connector.getAttribute("sslProtocol"); 172 } 173 174 180 public void setSecureProtocol(String protocol) { 181 connector.setAttribute("sslProtocol", protocol); 182 } 183 184 192 public boolean isClientAuthRequired() { 193 Object value = connector.getAttribute("clientAuth"); 194 return value == null ? false : new Boolean (value.toString()).booleanValue(); 195 } 196 197 205 public void setClientAuthRequired(boolean clientCert) { 206 connector.setAttribute("clientAuth", new Boolean (clientCert)); 207 } 208 209 213 public String getCiphers() { 214 return (String )connector.getAttribute("ciphers"); 215 } 216 217 221 public void setCiphers(String ciphers) { 222 connector.setAttribute("ciphers", ciphers); 223 } 224 225 public static final GBeanInfo GBEAN_INFO; 226 227 static { 228 GBeanInfoBuilder infoFactory = GBeanInfoBuilder.createStatic("Tomcat Connector", HttpsConnectorGBean.class, ConnectorGBean.GBEAN_INFO); 229 infoFactory.addAttribute("keystoreFileName", String .class, true, true); 230 infoFactory.addAttribute("truststoreFileName", String .class, true, true); 231 infoFactory.addAttribute("algorithm", String .class, true, true); 232 infoFactory.addAttribute("keystorePassword", String .class, true, true); 233 infoFactory.addAttribute("truststorePassword", String .class, true, true); 234 infoFactory.addAttribute("secureProtocol", String .class, true, true); 237 infoFactory.addAttribute("keystoreType", String .class, true, true); 238 infoFactory.addAttribute("truststoreType", String .class, true, true); 239 infoFactory.addAttribute("clientAuthRequired", boolean.class, true, true); 240 infoFactory.addAttribute("ciphers", String .class, true, true); 241 infoFactory.addInterface(TomcatSecureConnector.class); 242 243 infoFactory.addReference("ServerInfo", ServerInfo.class, "GBean"); 244 infoFactory.setConstructor(new String [] { "name", "protocol", "host", "port", "TomcatContainer", "ServerInfo"}); 245 GBEAN_INFO = infoFactory.getBeanInfo(); 246 } 247 248 public static GBeanInfo getGBeanInfo() { 249 return GBEAN_INFO; 250 } 251 } 252 | Popular Tags |