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     */
017    package org.apache.activemq.transport.https;
018    
019    import java.net.URI;
020    
021    import org.apache.activemq.transport.http.HttpTransportServer;
022    import org.mortbay.jetty.security.SslSocketConnector;
023    
024    public class HttpsTransportServer extends HttpTransportServer {
025    
026        private String keyPassword = System.getProperty("javax.net.ssl.keyPassword");
027        private String keyStorePassword = System.getProperty("javax.net.ssl.keyStorePassword");
028        private String keyStore = System.getProperty("javax.net.ssl.keyStore");
029        private String keyStoreType;
030        private String secureRandomCertficateAlgorithm;
031        private String trustCertificateAlgorithm;
032        private String keyCertificateAlgorithm;
033        private String protocol;
034    
035        public HttpsTransportServer(URI uri) {
036            super(uri);
037        }
038    
039        public void doStart() throws Exception {
040            SslSocketConnector sslConnector = new SslSocketConnector();
041            sslConnector.setKeystore(keyStore);
042            sslConnector.setPassword(keyStorePassword);
043            // if the keyPassword hasn't been set, default it to the
044            // key store password
045            if (keyPassword == null) {
046                sslConnector.setKeyPassword(keyStorePassword);
047            }
048            if (keyStoreType != null) {
049                sslConnector.setKeystoreType(keyStoreType);
050            }
051            if (secureRandomCertficateAlgorithm != null) {
052                sslConnector.setSecureRandomAlgorithm(secureRandomCertficateAlgorithm);
053            }
054            if (keyCertificateAlgorithm != null) {
055                sslConnector.setSslKeyManagerFactoryAlgorithm(keyCertificateAlgorithm);
056            }
057            if (trustCertificateAlgorithm != null) {
058                sslConnector.setSslTrustManagerFactoryAlgorithm(trustCertificateAlgorithm);
059            }
060            if (protocol != null) {
061                sslConnector.setProtocol(protocol);
062            }
063    
064            setConnector(sslConnector);
065    
066            super.doStart();
067        }
068    
069        // Properties
070        // --------------------------------------------------------------------------------
071    
072        public String getKeyStore() {
073            return keyStore;
074        }
075    
076        public void setKeyStore(String keyStore) {
077            this.keyStore = keyStore;
078        }
079    
080        public String getKeyPassword() {
081            return keyPassword;
082        }
083    
084        public void setKeyPassword(String keyPassword) {
085            this.keyPassword = keyPassword;
086        }
087    
088        public String getKeyStoreType() {
089            return keyStoreType;
090        }
091    
092        public void setKeyStoreType(String keyStoreType) {
093            this.keyStoreType = keyStoreType;
094        }
095    
096        public String getKeyStorePassword() {
097            return keyStorePassword;
098        }
099    
100        public void setKeyStorePassword(String keyStorePassword) {
101            this.keyStorePassword = keyStorePassword;
102        }
103    
104        public String getProtocol() {
105            return protocol;
106        }
107    
108        public void setProtocol(String protocol) {
109            this.protocol = protocol;
110        }
111    
112        public String getSecureRandomCertficateAlgorithm() {
113            return secureRandomCertficateAlgorithm;
114        }
115    
116        public void setSecureRandomCertficateAlgorithm(String secureRandomCertficateAlgorithm) {
117            this.secureRandomCertficateAlgorithm = secureRandomCertficateAlgorithm;
118        }
119    
120        public String getKeyCertificateAlgorithm() {
121            return keyCertificateAlgorithm;
122        }
123    
124        public void setKeyCertificateAlgorithm(String keyCertificateAlgorithm) {
125            this.keyCertificateAlgorithm = keyCertificateAlgorithm;
126        }
127    
128        public String getTrustCertificateAlgorithm() {
129            return trustCertificateAlgorithm;
130        }
131    
132        public void setTrustCertificateAlgorithm(String trustCertificateAlgorithm) {
133            this.trustCertificateAlgorithm = trustCertificateAlgorithm;
134        }
135    
136    }