activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cmacn...@apache.org
Subject svn commit: r781883 - /activemq/sandbox/activemq-flow/activemq-client/src/main/java/org/apache/activemq/ActiveMQSslConnectionFactory.java
Date Fri, 05 Jun 2009 01:19:28 GMT
Author: cmacnaug
Date: Fri Jun  5 01:19:28 2009
New Revision: 781883

URL: http://svn.apache.org/viewvc?rev=781883&view=rev
Log:
SslConnectionFactory (that was moved from the bio package)

Added:
    activemq/sandbox/activemq-flow/activemq-client/src/main/java/org/apache/activemq/ActiveMQSslConnectionFactory.java
  (with props)

Added: activemq/sandbox/activemq-flow/activemq-client/src/main/java/org/apache/activemq/ActiveMQSslConnectionFactory.java
URL: http://svn.apache.org/viewvc/activemq/sandbox/activemq-flow/activemq-client/src/main/java/org/apache/activemq/ActiveMQSslConnectionFactory.java?rev=781883&view=auto
==============================================================================
--- activemq/sandbox/activemq-flow/activemq-client/src/main/java/org/apache/activemq/ActiveMQSslConnectionFactory.java
(added)
+++ activemq/sandbox/activemq-flow/activemq-client/src/main/java/org/apache/activemq/ActiveMQSslConnectionFactory.java
Fri Jun  5 01:19:28 2009
@@ -0,0 +1,78 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.activemq;
+
+import java.security.SecureRandom;
+import javax.jms.JMSException;
+import javax.net.ssl.KeyManager;
+import javax.net.ssl.TrustManager;
+import org.apache.activemq.transport.Transport;
+import org.apache.activemq.transport.tcp.SslTransportFactory;
+import org.apache.activemq.util.JMSExceptionSupport;
+
+/**
+ * An ActiveMQConnectionFactory that allows access to the key and trust managers
+ * used for SslConnections. There is no reason to use this class unless SSL is
+ * being used AND the key and trust managers need to be specified from within
+ * code. In fact, if the URI passed to this class does not have an "ssl" scheme,
+ * this class will pass all work on to its superclass.
+ * 
+ * @author sepandm@gmail.com
+ */
+public class ActiveMQSslConnectionFactory extends ActiveMQConnectionFactory {
+    // The key and trust managers used to initialize the used SSLContext.
+    protected KeyManager[] keyManager;
+    protected TrustManager[] trustManager;
+    protected SecureRandom secureRandom;
+
+    /**
+     * Sets the key and trust managers used when creating SSL connections.
+     * 
+     * @param km The KeyManagers used.
+     * @param tm The TrustManagers used.
+     * @param random The SecureRandom number used.
+     */
+    public void setKeyAndTrustManagers(final KeyManager[] km, final TrustManager[] tm, final
SecureRandom random) {
+        keyManager = km;
+        trustManager = tm;
+        secureRandom = random;
+    }
+
+    /**
+     * Overriding to make special considerations for SSL connections. If we are
+     * not using SSL, the superclass's method is called. If we are using SSL, an
+     * SslConnectionFactory is used and it is given the needed key and trust
+     * managers.
+     * 
+     * @author sepandm@gmail.com
+     */
+    protected Transport createTransport() throws JMSException {
+        // If the given URI is non-ssl, let superclass handle it.
+        if (!brokerURL.getScheme().equals("ssl")) {
+            return super.createTransport();
+        }
+
+        try {
+            SslTransportFactory sslFactory = new SslTransportFactory();
+            sslFactory.setKeyAndTrustManagers(keyManager, trustManager, secureRandom);
+            return sslFactory.doConnect(brokerURL);
+        } catch (Exception e) {
+            throw JMSExceptionSupport.create("Could not create Transport. Reason: " + e,
e);
+        }
+    }
+}

Propchange: activemq/sandbox/activemq-flow/activemq-client/src/main/java/org/apache/activemq/ActiveMQSslConnectionFactory.java
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message