Author: chirino
Date: Thu Nov 11 13:31:08 2010
New Revision: 1033935
URL: http://svn.apache.org/viewvc?rev=1033935&view=rev
Log:
Broker now loads the key and trust configured so that they can be injected into
the connector's transport server if they are needed.
Added:
activemq/activemq-apollo/trunk/apollo-broker/src/main/scala/org/apache/activemq/apollo/broker/KeyStorage.scala
Modified:
activemq/activemq-apollo/trunk/apollo-broker/src/main/scala/org/apache/activemq/apollo/broker/Broker.scala
activemq/activemq-apollo/trunk/apollo-broker/src/main/scala/org/apache/activemq/apollo/broker/Connector.scala
Modified:
activemq/activemq-apollo/trunk/apollo-broker/src/main/scala/org/apache/activemq/apollo/broker/Broker.scala
URL:
http://svn.apache.org/viewvc/activemq/activemq-apollo/trunk/apollo-broker/src/main/scala/org/apache/activemq/apollo/broker/Broker.scala?rev=1033935&r1=1033934&r2=1033935&view=diff
==============================================================================
---
activemq/activemq-apollo/trunk/apollo-broker/src/main/scala/org/apache/activemq/apollo/broker/Broker.scala
(original)
+++
activemq/activemq-apollo/trunk/apollo-broker/src/main/scala/org/apache/activemq/apollo/broker/Broker.scala
Thu Nov 11 13:31:08 2010
@@ -183,6 +183,8 @@ class Broker() extends BaseService with
val connector_id_counter = new LongCounter
val connection_id_counter = new LongCounter
+ var key_storage:KeyStorage = _
+
override def toString() = "broker: "+id
@@ -207,6 +209,12 @@ class Broker() extends BaseService with
// create the runtime objects from the config
{
data_directory = new File(config.basedir)
+
+ if( config.key_storage!=null ) {
+ key_storage = new KeyStorage
+ key_storage.config = config.key_storage
+ }
+
default_virtual_host = null
for (c <- config.virtual_hosts) {
val host = new VirtualHost(this,
virtual_host_id_counter.incrementAndGet)
Modified:
activemq/activemq-apollo/trunk/apollo-broker/src/main/scala/org/apache/activemq/apollo/broker/Connector.scala
URL:
http://svn.apache.org/viewvc/activemq/activemq-apollo/trunk/apollo-broker/src/main/scala/org/apache/activemq/apollo/broker/Connector.scala?rev=1033935&r1=1033934&r2=1033935&view=diff
==============================================================================
---
activemq/activemq-apollo/trunk/apollo-broker/src/main/scala/org/apache/activemq/apollo/broker/Connector.scala
(original)
+++
activemq/activemq-apollo/trunk/apollo-broker/src/main/scala/org/apache/activemq/apollo/broker/Connector.scala
Thu Nov 11 13:31:08 2010
@@ -140,6 +140,10 @@ class Connector(val broker:Broker, val i
transportServer = TransportFactory.bind( config.bind )
transportServer.setDispatchQueue(dispatchQueue)
transportServer.setAcceptListener(BrokerAcceptListener)
+
+ if( transportServer.isInstanceOf[KeyManagerAware] &&
broker.key_storage!=null ) {
+
transportServer.asInstanceOf[KeyManagerAware].setKeyManagers(broker.key_storage.create_key_managers)
+ }
transportServer.start(onCompleted)
}
Added:
activemq/activemq-apollo/trunk/apollo-broker/src/main/scala/org/apache/activemq/apollo/broker/KeyStorage.scala
URL:
http://svn.apache.org/viewvc/activemq/activemq-apollo/trunk/apollo-broker/src/main/scala/org/apache/activemq/apollo/broker/KeyStorage.scala?rev=1033935&view=auto
==============================================================================
---
activemq/activemq-apollo/trunk/apollo-broker/src/main/scala/org/apache/activemq/apollo/broker/KeyStorage.scala
(added)
+++
activemq/activemq-apollo/trunk/apollo-broker/src/main/scala/org/apache/activemq/apollo/broker/KeyStorage.scala
Thu Nov 11 13:31:08 2010
@@ -0,0 +1,71 @@
+/**
+ * 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.apollo.broker
+
+import org.apache.activemq.apollo.dto.KeyStorageDTO
+import javax.net.ssl._
+import java.security.KeyStore
+import java.io.FileInputStream
+
+/**
+ *
+ * @author <a href="http://hiramchirino.com">Hiram Chirino</a>
+ */
+class KeyStorage {
+
+ var config = new KeyStorageDTO
+
+ var key_store:KeyStore = _
+ var trust_managers:Array[TrustManager] = _
+ var key_managers:Array[KeyManager] = _
+
+ // a little helper for dealing /w null values.
+ private def opt[T](value:T):Option[T] = value match {
+ case null => None
+ case x => Some(x)
+ }
+
+ def create_key_store = {
+ if( trust_managers==null ) {
+ key_store = {
+ val store =
KeyStore.getInstance(opt(config.store_type).getOrElse("JKS"))
+ store.load(new FileInputStream(config.file),
opt(config.password).getOrElse("").toCharArray())
+ store
+ }
+ }
+ key_store
+ }
+
+ def create_trust_managers = {
+ if( trust_managers==null ) {
+ val factory =
TrustManagerFactory.getInstance(opt(config.trust_algorithm).getOrElse("SunX509"))
+ factory.init(create_key_store)
+ trust_managers = factory.getTrustManagers
+ }
+ trust_managers
+ }
+
+ def create_key_managers = {
+ if( key_managers==null ) {
+ val factory =
KeyManagerFactory.getInstance(opt(config.key_algorithm).getOrElse("SunX509"))
+ factory.init(create_key_store,
opt(config.key_password).getOrElse("").toCharArray())
+ key_managers = factory.getKeyManagers
+ }
+ key_managers
+ }
+
+}
\ No newline at end of file