Save This Page
Home » geronimo-2.2-source-release » org.apache.geronimo.jetty7.connector » [javadoc | source]
    1   /**
    2    *  Licensed to the Apache Software Foundation (ASF) under one or more
    3    *  contributor license agreements.  See the NOTICE file distributed with
    4    *  this work for additional information regarding copyright ownership.
    5    *  The ASF licenses this file to You under the Apache License, Version 2.0
    6    *  (the "License"); you may not use this file except in compliance with
    7    *  the License.  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.jetty7.connector;
   19   
   20   import javax.net.ssl.KeyManagerFactory;
   21   
   22   import org.apache.geronimo.gbean.GBeanInfo;
   23   import org.apache.geronimo.gbean.GBeanInfoBuilder;
   24   import org.apache.geronimo.jetty7.JettyContainer;
   25   import org.apache.geronimo.jetty7.JettySecureConnector;
   26   import org.apache.geronimo.management.geronimo.KeystoreManager;
   27   import org.apache.geronimo.management.geronimo.WebManager;
   28   import org.apache.geronimo.system.threads.ThreadPool;
   29   import org.eclipse.jetty.server.bio.SocketConnector;
   30   
   31   /**
   32    * Implementation of a HTTPS connector based on Jetty's SslConnector (which uses pure JSSE).
   33    *
   34    * @version $Rev: 759104 $ $Date: 2009-03-27 04:21:58 -0700 (Fri, 27 Mar 2009) $
   35    */
   36   public class HTTPSSocketConnector extends JettyConnector implements JettySecureConnector {
   37       private final GeronimoSocketSSLListener https;
   38       private String algorithm;
   39   
   40       public HTTPSSocketConnector(JettyContainer container, ThreadPool threadPool, KeystoreManager keystoreManager) {
   41           super(container, new GeronimoSocketSSLListener(keystoreManager), threadPool, "HTTPSSocketConnector");
   42           https = (GeronimoSocketSSLListener) listener;
   43       }
   44   
   45       public int getDefaultPort() {
   46           return 443;
   47       }
   48   
   49       public String getProtocol() {
   50           return WebManager.PROTOCOL_HTTPS;
   51       }
   52   
   53       public String getAlgorithm() {
   54           return algorithm;
   55       }
   56   
   57       /**
   58        * Algorithm to use.
   59        * As different JVMs have different implementations available, the default algorithm can be used by supplying the value "Default".
   60        *
   61        * @param algorithm the algorithm to use, or "Default" to use the default from {@link javax.net.ssl.KeyManagerFactory#getDefaultAlgorithm()}
   62        */
   63       public void setAlgorithm(String algorithm) {
   64           // cache the value so the null
   65           this.algorithm = algorithm;
   66           if ("default".equalsIgnoreCase(algorithm)) {
   67               algorithm = KeyManagerFactory.getDefaultAlgorithm();
   68           }
   69           https.setSslKeyManagerFactoryAlgorithm(algorithm);
   70       }
   71   
   72       public String getSecureProtocol() {
   73           return https.getProtocol();
   74       }
   75   
   76       public void setSecureProtocol(String protocol) {
   77           https.setProtocol(protocol);
   78       }
   79   
   80       public void setClientAuthRequired(boolean needClientAuth) {
   81           https.setNeedClientAuth(needClientAuth);
   82       }
   83   
   84       public boolean isClientAuthRequired() {
   85           return https.getNeedClientAuth();
   86       }
   87   
   88       public void setClientAuthRequested(boolean wantClientAuth) {
   89           https.setWantClientAuth(wantClientAuth);
   90       }
   91   
   92       public boolean isClientAuthRequested() {
   93           return https.getWantClientAuth();
   94       }
   95   
   96       public void setKeyStore(String keyStore) {
   97           https.setKeyStore(keyStore);
   98       }
   99   
  100       public String getKeyStore() {
  101           return https.getKeyStore();
  102       }
  103   
  104       public void setTrustStore(String trustStore) {
  105           https.setTrustStore(trustStore);
  106       }
  107   
  108       public String getTrustStore() {
  109           return https.getTrustStore();
  110       }
  111   
  112       public void setKeyAlias(String keyAlias) {
  113           https.setKeyAlias(keyAlias);
  114       }
  115   
  116       public String getKeyAlias() {
  117           return https.getKeyAlias();
  118       }
  119       
  120       //TODO does this make sense???
  121       public void setRedirectPort(int port) {
  122           SocketConnector socketListener = (SocketConnector) listener;
  123           socketListener.setConfidentialPort(port);
  124           socketListener.setIntegralPort(port);
  125           socketListener.setIntegralScheme("https");
  126           socketListener.setConfidentialScheme("https");
  127       }
  128   
  129       public static final GBeanInfo GBEAN_INFO;
  130   
  131       static {
  132           GBeanInfoBuilder infoFactory = GBeanInfoBuilder.createStatic("Jetty Connector HTTPS", HTTPSSocketConnector.class, JettyConnector.GBEAN_INFO);
  133           infoFactory.addAttribute("algorithm", String.class, true, true);
  134           infoFactory.addAttribute("secureProtocol", String.class, true, true);
  135           infoFactory.addAttribute("keyStore", String.class, true, true);
  136           infoFactory.addAttribute("keyAlias", String.class, true, true);
  137           infoFactory.addAttribute("trustStore", String.class, true, true);
  138           infoFactory.addAttribute("clientAuthRequired", boolean.class, true, true);
  139           infoFactory.addAttribute("clientAuthRequested", boolean.class, true, true);
  140           infoFactory.addReference("KeystoreManager", KeystoreManager.class, GBeanInfoBuilder.DEFAULT_J2EE_TYPE);
  141           infoFactory.addInterface(JettySecureConnector.class);
  142           infoFactory.setConstructor(new String[]{"JettyContainer", "ThreadPool", "KeystoreManager"});
  143           GBEAN_INFO = infoFactory.getBeanInfo();
  144       }
  145   
  146       public static GBeanInfo getGBeanInfo() {
  147           return GBEAN_INFO;
  148       }
  149   
  150       // ================= NO LONGER USED!!! =====================
  151       // todo: remove these from the SSL interface
  152   
  153       public String getKeystoreFileName() {
  154           return null;
  155       }
  156   
  157       public void setKeystoreFileName(String name) {
  158       }
  159   
  160       public void setKeystorePassword(String password) {
  161       }
  162   
  163       public String getKeystoreType() {
  164           return null;
  165       }
  166   
  167       public void setKeystoreType(String type) {
  168       }
  169   }

Save This Page
Home » geronimo-2.2-source-release » org.apache.geronimo.jetty7.connector » [javadoc | source]