From 139a220ee73b201517c2212d8e7a7ead48526fb1 Mon Sep 17 00:00:00 2001 From: "Hiram R. Chirino" Date: Wed, 14 May 2008 15:32:54 +0000 Subject: [PATCH] fix for AMQ-1724 git-svn-id: https://svn.apache.org/repos/asf/activemq/trunk@656319 13f79535-47bb-0310-9956-ffa450edef68 --- .../apache/activemq/broker/BrokerService.java | 26 ++- .../apache/activemq/broker/SslContext.java | 76 +++++++ .../activemq/spring/SpringSslContext.java | 194 ++++++++++++++++++ .../transport/tcp/SslTransportFactory.java | 16 +- .../http/activemq.apache.org/schema/core | 2 + activemq-core/src/main/resources/activemq.xsd | 68 +++++- .../src/main/resources/activemq.xsd.html | 26 ++- .../src/main/resources/activemq.xsd.wiki | 29 ++- .../tcp/SslContextBrokerServiceTest.java | 69 +++++++ .../activemq/transport/tcp/activemq-ssl.xml | 44 ++++ 10 files changed, 544 insertions(+), 6 deletions(-) create mode 100644 activemq-core/src/main/java/org/apache/activemq/broker/SslContext.java create mode 100644 activemq-core/src/main/java/org/apache/activemq/spring/SpringSslContext.java create mode 100644 activemq-core/src/test/java/org/apache/activemq/transport/tcp/SslContextBrokerServiceTest.java create mode 100755 activemq-core/src/test/resources/org/apache/activemq/transport/tcp/activemq-ssl.xml diff --git a/activemq-core/src/main/java/org/apache/activemq/broker/BrokerService.java b/activemq-core/src/main/java/org/apache/activemq/broker/BrokerService.java index 16e5308c85..ec97b79401 100644 --- a/activemq-core/src/main/java/org/apache/activemq/broker/BrokerService.java +++ b/activemq-core/src/main/java/org/apache/activemq/broker/BrokerService.java @@ -21,6 +21,8 @@ import java.io.IOException; import java.net.URI; import java.net.URISyntaxException; import java.net.UnknownHostException; +import java.security.KeyManagementException; +import java.security.SecureRandom; import java.util.ArrayList; import java.util.HashMap; import java.util.Iterator; @@ -34,6 +36,8 @@ import java.util.concurrent.atomic.AtomicBoolean; import javax.management.MBeanServer; import javax.management.MalformedObjectNameException; import javax.management.ObjectName; +import javax.net.ssl.KeyManager; +import javax.net.ssl.TrustManager; import org.apache.activemq.ActiveMQConnectionMetaData; import org.apache.activemq.Service; @@ -79,6 +83,7 @@ import org.apache.activemq.store.memory.MemoryPersistenceAdapter; import org.apache.activemq.thread.TaskRunnerFactory; import org.apache.activemq.transport.TransportFactory; import org.apache.activemq.transport.TransportServer; +import org.apache.activemq.transport.tcp.SslTransportFactory; import org.apache.activemq.transport.vm.VMTransportFactory; import org.apache.activemq.usage.SystemUsage; import org.apache.activemq.util.IOExceptionSupport; @@ -172,7 +177,8 @@ public class BrokerService implements Service { private int timeBeforePurgeTempDestinations = 5000; private List shutdownHooks= new ArrayList(); private boolean systemExitOnShutdown; - private int systemExitOnShutdownExitCode; + private int systemExitOnShutdownExitCode; + private SslContext sslContext = new SslContext(); static { String localHostName = "localhost"; @@ -1952,5 +1958,21 @@ public class BrokerService implements Service { public void setSystemExitOnShutdown(boolean systemExitOnShutdown) { this.systemExitOnShutdown = systemExitOnShutdown; } - + + public int getSystemExitOnShutdownExitCode() { + return systemExitOnShutdownExitCode; + } + + public void setSystemExitOnShutdownExitCode(int systemExitOnShutdownExitCode) { + this.systemExitOnShutdownExitCode = systemExitOnShutdownExitCode; + } + + public SslContext getSslContext() { + return sslContext; + } + + public void setSslContext(SslContext sslContext) { + this.sslContext = sslContext; + } + } \ No newline at end of file diff --git a/activemq-core/src/main/java/org/apache/activemq/broker/SslContext.java b/activemq-core/src/main/java/org/apache/activemq/broker/SslContext.java new file mode 100644 index 0000000000..9674b8bbb8 --- /dev/null +++ b/activemq-core/src/main/java/org/apache/activemq/broker/SslContext.java @@ -0,0 +1,76 @@ +/** + * 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.broker; + +import java.security.SecureRandom; +import java.util.ArrayList; +import java.util.List; + +import javax.net.ssl.KeyManager; +import javax.net.ssl.TrustManager; + +/** + * A holder of SSL configuration. + */ +public class SslContext { + + protected List keyManagers = new ArrayList(); + protected List trustManagers = new ArrayList(); + protected SecureRandom secureRandom; + + public KeyManager[] getKeyManagersAsArray() { + KeyManager rc[] = new KeyManager[keyManagers.size()]; + return keyManagers.toArray(rc); + } + public TrustManager[] getTrustManagersAsArray() { + TrustManager rc[] = new TrustManager[trustManagers.size()]; + return trustManagers.toArray(rc); + } + + public void addKeyManager(KeyManager km) { + keyManagers.add(km); + } + public boolean removeKeyManager(KeyManager km) { + return keyManagers.remove(km); + } + public void addTrustManager(TrustManager tm) { + trustManagers.add(tm); + } + public boolean removeTrustManager(TrustManager tm) { + return trustManagers.remove(tm); + } + + public List getKeyManagers() { + return keyManagers; + } + public void setKeyManagers(List keyManagers) { + this.keyManagers = keyManagers; + } + public List getTrustManagers() { + return trustManagers; + } + public void setTrustManagers(List trustManagers) { + this.trustManagers = trustManagers; + } + public SecureRandom getSecureRandom() { + return secureRandom; + } + public void setSecureRandom(SecureRandom secureRandom) { + this.secureRandom = secureRandom; + } + +} diff --git a/activemq-core/src/main/java/org/apache/activemq/spring/SpringSslContext.java b/activemq-core/src/main/java/org/apache/activemq/spring/SpringSslContext.java new file mode 100644 index 0000000000..168482d294 --- /dev/null +++ b/activemq-core/src/main/java/org/apache/activemq/spring/SpringSslContext.java @@ -0,0 +1,194 @@ +/** + * 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.spring; + +import java.io.InputStream; +import java.security.KeyStore; +import java.security.NoSuchAlgorithmException; +import java.security.SecureRandom; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; + +import javax.net.ssl.KeyManager; +import javax.net.ssl.KeyManagerFactory; +import javax.net.ssl.TrustManager; +import javax.net.ssl.TrustManagerFactory; + +import org.apache.activemq.broker.SslContext; +import org.springframework.beans.factory.InitializingBean; +import org.springframework.core.io.Resource; + +/** + * Extends the SslContext so that it's easier to configure from spring. + * + * @org.apache.xbean.XBean element="sslContext" + * + * @version $Revision$ + */ +public class SpringSslContext extends SslContext implements InitializingBean { + + private String keyStoreType="jks"; + private String trustStoreType="jks"; + + private String secureRandomAlgorithm="SHA1PRNG"; + private String keyStoreAlgorithm=KeyManagerFactory.getDefaultAlgorithm(); + private String trustStoreAlgorithm=TrustManagerFactory.getDefaultAlgorithm(); + + private Resource keyStore; + private Resource trustStore; + + private String keyStorePassword; + private String trustStorePassword; + + public void afterPropertiesSet() throws Exception { + keyManagers.addAll(createKeyManagers()); + trustManagers.addAll(createTrustManagers()); + if( secureRandom == null ) { + secureRandom = createSecureRandom(); + } + } + + private SecureRandom createSecureRandom() throws NoSuchAlgorithmException { + return SecureRandom.getInstance(secureRandomAlgorithm); + } + + private Collection createTrustManagers() throws Exception { + KeyStore ks = createTrustManagerKeyStore(); + if( ks ==null ) { + return new ArrayList(0); + } + + TrustManagerFactory tmf = TrustManagerFactory.getInstance(trustStoreAlgorithm); + tmf.init(ks); + return Arrays.asList(tmf.getTrustManagers()); + } + + private Collection createKeyManagers() throws Exception { + KeyStore ks = createKeyManagerKeyStore(); + if( ks ==null ) { + return new ArrayList(0); + } + + KeyManagerFactory tmf = KeyManagerFactory.getInstance(keyStoreAlgorithm); + tmf.init(ks, keyStorePassword==null? null : keyStorePassword.toCharArray()); + return Arrays.asList(tmf.getKeyManagers()); + } + + private KeyStore createTrustManagerKeyStore() throws Exception { + if( trustStore ==null ) { + return null; + } + + KeyStore ks = KeyStore.getInstance(trustStoreType); + InputStream is=trustStore.getInputStream(); + try { + ks.load(is, trustStorePassword==null? null : trustStorePassword.toCharArray()); + } finally { + is.close(); + } + return ks; + } + + private KeyStore createKeyManagerKeyStore() throws Exception { + if( keyStore ==null ) { + return null; + } + + KeyStore ks = KeyStore.getInstance(keyStoreType); + InputStream is=keyStore.getInputStream(); + try { + ks.load(is, keyStorePassword==null? null : keyStorePassword.toCharArray()); + } finally { + is.close(); + } + return ks; + } + + public String getTrustStoreType() { + return trustStoreType; + } + + public String getKeyStoreType() { + return keyStoreType; + } + + public Resource getKeyStore() { + return keyStore; + } + + public void setKeyStore(Resource keyResource) { + this.keyStore = keyResource; + } + + public Resource getTrustStore() { + return trustStore; + } + + public void setTrustStore(Resource trustResource) { + this.trustStore = trustResource; + } + + public String getKeyStoreAlgorithm() { + return keyStoreAlgorithm; + } + + public void setKeyStoreAlgorithm(String keyAlgorithm) { + this.keyStoreAlgorithm = keyAlgorithm; + } + + public String getTrustStoreAlgorithm() { + return trustStoreAlgorithm; + } + + public void setTrustStoreAlgorithm(String trustAlgorithm) { + this.trustStoreAlgorithm = trustAlgorithm; + } + + public String getKeyStorePassword() { + return keyStorePassword; + } + + public void setKeyStorePassword(String keyPassword) { + this.keyStorePassword = keyPassword; + } + + public String getTrustStorePassword() { + return trustStorePassword; + } + + public void setTrustStorePassword(String trustPassword) { + this.trustStorePassword = trustPassword; + } + + public void setKeyStoreType(String keyType) { + this.keyStoreType = keyType; + } + + public void setTrustStoreType(String trustType) { + this.trustStoreType = trustType; + } + + public String getSecureRandomAlgorithm() { + return secureRandomAlgorithm; + } + + public void setSecureRandomAlgorithm(String secureRandomAlgorithm) { + this.secureRandomAlgorithm = secureRandomAlgorithm; + } + +} diff --git a/activemq-core/src/main/java/org/apache/activemq/transport/tcp/SslTransportFactory.java b/activemq-core/src/main/java/org/apache/activemq/transport/tcp/SslTransportFactory.java index 9e75c828ae..0cee264e46 100644 --- a/activemq-core/src/main/java/org/apache/activemq/transport/tcp/SslTransportFactory.java +++ b/activemq-core/src/main/java/org/apache/activemq/transport/tcp/SslTransportFactory.java @@ -34,6 +34,9 @@ import javax.net.ssl.SSLServerSocketFactory; import javax.net.ssl.SSLSocketFactory; import javax.net.ssl.TrustManager; +import org.apache.activemq.broker.BrokerService; +import org.apache.activemq.broker.BrokerServiceAware; +import org.apache.activemq.broker.SslContext; import org.apache.activemq.openwire.OpenWireFormat; import org.apache.activemq.transport.InactivityMonitor; import org.apache.activemq.transport.Transport; @@ -57,7 +60,7 @@ import org.apache.commons.logging.LogFactory; * @author David Martin Clavo david(dot)martin(dot)clavo(at)gmail.com (logging improvement modifications) * @version $Revision$ */ -public class SslTransportFactory extends TcpTransportFactory { +public class SslTransportFactory extends TcpTransportFactory implements BrokerServiceAware { // The log this uses., private static final Log LOG = LogFactory.getLog(SslTransportFactory.class); @@ -162,6 +165,17 @@ public class SslTransportFactory extends TcpTransportFactory { } sslContext.init(km, tm, random); } + + public void setBrokerService(BrokerService brokerService) { + SslContext c = brokerService.getSslContext(); + if( sslContext == null && c!=null ) { + try { + setKeyAndTrustManagers(c.getKeyManagersAsArray(), c.getTrustManagersAsArray(), c.getSecureRandom()); + } catch (KeyManagementException e) { + throw new RuntimeException(e); + } + } + } /** * Creates a new SSL ServerSocketFactory. The given factory will use diff --git a/activemq-core/src/main/resources/META-INF/services/org/apache/xbean/spring/http/activemq.apache.org/schema/core b/activemq-core/src/main/resources/META-INF/services/org/apache/xbean/spring/http/activemq.apache.org/schema/core index ca6a7969e5..2d14aafd5f 100644 --- a/activemq-core/src/main/resources/META-INF/services/org/apache/xbean/spring/http/activemq.apache.org/schema/core +++ b/activemq-core/src/main/resources/META-INF/services/org/apache/xbean/spring/http/activemq.apache.org/schema/core @@ -210,6 +210,8 @@ simpleJmsMessageConvertor = org.apache.activemq.network.jms.SimpleJmsMessageConv simpleMessageGroupMapFactory = org.apache.activemq.broker.region.group.SimpleMessageGroupMapFactory +sslContext = org.apache.activemq.spring.SpringSslContext + statements = org.apache.activemq.store.jdbc.Statements storeCursor = org.apache.activemq.broker.region.policy.StorePendingQueueMessageStoragePolicy diff --git a/activemq-core/src/main/resources/activemq.xsd b/activemq-core/src/main/resources/activemq.xsd index 38c8511022..8b4e98118f 100644 --- a/activemq-core/src/main/resources/activemq.xsd +++ b/activemq-core/src/main/resources/activemq.xsd @@ -650,6 +650,14 @@ other brokers in a federated network + + + + + + + + @@ -806,6 +814,7 @@ consume a given message + + + @@ -858,6 +869,7 @@ enabled. ]]> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -5132,6 +5186,11 @@ subscriptions. + + + @@ -5168,7 +5227,14 @@ consume a given message - + + + + + + diff --git a/activemq-core/src/main/resources/activemq.xsd.html b/activemq-core/src/main/resources/activemq.xsd.html index 2b1beab639..595d886331 100644 --- a/activemq-core/src/main/resources/activemq.xsd.html +++ b/activemq-core/src/main/resources/activemq.xsd.html @@ -221,6 +221,7 @@ matches the message.org.apache.activemq.broker.region.policy.SimpleDisp simpleJmsMessageConvertorConverts Message from one JMS to anotherorg.apache.activemq.network.jms.SimpleJmsMessageConvertor simpleMessageGroupMapFactoryA factory to create instances of {@link SimpleMessageGroupMap} when implementing the Message Groups functionality.org.apache.activemq.broker.region.group.SimpleMessageGroupMapFactory + sslContextExtends the SslContext so that it's easier to configure from spring.org.apache.activemq.spring.SpringSslContext statementsorg.apache.activemq.store.jdbc.Statements storeCursorPending messagesorg.apache.activemq.broker.region.policy.StorePendingQueueMessageStoragePolicy storeDurableSubscriberCursorPending messages for a durableorg.apache.activemq.broker.region.policy.StorePendingDurableSubscriberMessageStoragePolicy @@ -414,6 +415,7 @@ useful for testing. Normally you would want the broker to start up along with the ApplicationContext but sometimes when working with JUnit tests you may wish to start and stop the broker explicitly yourself. supportFailOverxs:boolean + systemExitOnShutdownxs:boolean taskRunnerPriorityxs:integer timeBeforePurgeTempDestinationsxs:integer tmpDataDirectoryxs:string @@ -429,6 +431,7 @@ explicitly configured. useShutdownHookxs:booleanSets whether or not we should use a shutdown handler to close down the broker cleanly if the JVM is terminated. It is recommended you leave this enabled. + useTempMirroredQueuesxs:boolean useVirtualTopicsxs:booleanSets whether or not Virtual Topics should be supported by default if they have not been @@ -465,6 +468,7 @@ other brokers in a federated network regionBrokerloggingBrokerPlugin | multicastTraceBrokerPlugin | timeStampingBrokerPlugin | udpTraceBrokerPlugin services(broker | commandAgent | forwardingBridge | inboundQueueBridge | inboundTopicBridge | jmsQueueConnector | jmsTopicConnector | ldapNetworkConnector | managementContext | masterConnector | memoryUsage | multicastNetworkConnector | networkConnector | outboundQueueBridge | outboundTopicBridge | proxyConnector | storeUsage | systemUsage | tempUsage)*Sets the services associated with this broker such as a {@link MasterConnector} + sslContextsslContext systemUsagesystemUsage taskRunnerFactory<spring:bean/> tempDataStore<spring:bean/> @@ -1425,6 +1429,25 @@ Set of groups connection<spring:bean/>

Element: simpleMessageGroupMapFactory

+

Element: sslContext

+ + + + + + + + + + + +
AttributeTypeDescription
keyStorexs:string
keyStoreAlgorithmxs:string
keyStorePasswordxs:string
keyStoreTypexs:string
secureRandomAlgorithmxs:string
trustStorexs:string
trustStoreAlgorithmxs:string
trustStorePasswordxs:string
trustStoreTypexs:string
+ + + + + +
ElementTypeDescription
keyManagers(<spring:bean/>)*
secureRandom<spring:bean/>
trustManagers(<spring:bean/>)*

Element: statements

@@ -1585,6 +1608,7 @@ before a UsageListener event is fired by the manager.

Element: transportConnector

AttributeTypeDescription
+ @@ -1598,7 +1622,7 @@ create a {@link TransportServer} instance
AttributeTypeDescription
brokerNamexs:string
connectUrixs:string
disableAsyncDispatchxs:boolean
discoveryUrixs:string
- + diff --git a/activemq-core/src/main/resources/activemq.xsd.wiki b/activemq-core/src/main/resources/activemq.xsd.wiki index ecdeb0239a..be0add4e41 100644 --- a/activemq-core/src/main/resources/activemq.xsd.wiki +++ b/activemq-core/src/main/resources/activemq.xsd.wiki @@ -28,6 +28,10 @@ h4. The _[org.apache.activemq.broker.BrokerService|#org.apache.activemq.broker.B connectors, network connectors and a bunch of properties which can be used to configure the broker as its lazily created.{html} | +{anchor:org.apache.activemq.broker.SslContext-types} +h4. The _[org.apache.activemq.broker.SslContext|#org.apache.activemq.broker.SslContext-types]_ Type Implementations + | _[|#sslContext-element]_ | {html}Extends the SslContext so that it's easier to configure from spring.{html} | + {anchor:org.apache.activemq.usage.TempUsage-types} h4. The _[org.apache.activemq.usage.TempUsage|#org.apache.activemq.usage.TempUsage-types]_ Type Implementations | _[|#tempUsage-element]_ | {html}Used to keep track of how much of something is being used so that a @@ -666,10 +670,12 @@ other brokers in a federated network{html} | {@link MasterConnector}{html} | | shutdownOnMasterFailure | _boolean_ | {html}{html} | | splitSystemUsageForProducersConsumers | _boolean_ | {html}{html} | + | sslContext | _[org.apache.activemq.broker.SslContext|#org.apache.activemq.broker.SslContext-types]_ | {html}{html} | | start | _boolean_ | {html}Sets whether or not the broker is started along with the ApplicationContext it is defined within. Normally you would want the broker to start up along with the ApplicationContext but sometimes when working with JUnit tests you may wish to start and stop the broker explicitly yourself.{html} | | supportFailOver | _boolean_ | {html}{html} | + | systemExitOnShutdown | _boolean_ | {html}{html} | | systemUsage | _[org.apache.activemq.usage.SystemUsage|#org.apache.activemq.usage.SystemUsage-types]_ | {html}{html} | | taskRunnerFactory | _org.apache.activemq.thread.TaskRunnerFactory_ | {html}{html} | | taskRunnerPriority | _int_ | {html}{html} | @@ -691,6 +697,7 @@ explicitly configured.{html} | | useShutdownHook | _boolean_ | {html}Sets whether or not we should use a shutdown handler to close down the broker cleanly if the JVM is terminated. It is recommended you leave this enabled.{html} | + | useTempMirroredQueues | _boolean_ | {html}{html} | | useVirtualTopics | _boolean_ | {html}Sets whether or not Virtual Topics should be supported by default if they have not been @@ -1760,6 +1767,24 @@ h3. The _[|#simpleMessageGroupMapFactory-element]_ {html}A factory to create instances of {@link SimpleMessageGroupMap} when implementing the Message Groups functionality.{html} +{anchor:sslContext-element} +h3. The _[|#sslContext-element]_ Element + {html}Extends the SslContext so that it's easier to configure from spring.{html} +h4. Properties + || Property Name || Type || Description || + | keyManagers | (_java.lang.Object_)\* | {html}{html} | + | keyStore | _org.springframework.core.io.Resource_ | {html}{html} | + | keyStoreAlgorithm | _java.lang.String_ | {html}{html} | + | keyStorePassword | _java.lang.String_ | {html}{html} | + | keyStoreType | _java.lang.String_ | {html}{html} | + | secureRandom | _java.security.SecureRandom_ | {html}{html} | + | secureRandomAlgorithm | _java.lang.String_ | {html}{html} | + | trustManagers | (_java.lang.Object_)\* | {html}{html} | + | trustStore | _org.springframework.core.io.Resource_ | {html}{html} | + | trustStoreAlgorithm | _java.lang.String_ | {html}{html} | + | trustStorePassword | _java.lang.String_ | {html}{html} | + | trustStoreType | _java.lang.String_ | {html}{html} | + {anchor:statements-element} h3. The _[|#statements-element]_ Element {html}{html} @@ -1952,7 +1977,8 @@ h3. The _[|#transportConnector-element]_ Element h4. Properties || Property Name || Type || Description || | brokerInfo | _org.apache.activemq.command.BrokerInfo_ | {html}{html} | - | brokerService | _[org.apache.activemq.broker.BrokerService|#org.apache.activemq.broker.BrokerService-types]_ | {html}{html} | + | brokerName | _java.lang.String_ | {html}{html} | + | brokerService | _[org.apache.activemq.broker.BrokerService|#org.apache.activemq.broker.BrokerService-types]_ | {html}This is called by the BrokerService right before it starts the transport.{html} | | connectUri | _java.net.URI_ | {html}{html} | | disableAsyncDispatch | _boolean_ | {html}{html} | | discoveryAgent | _org.apache.activemq.transport.discovery.DiscoveryAgent_ | {html}{html} | @@ -2303,6 +2329,7 @@ matches the message.{html} | | _[|#simpleJmsMessageConvertor-element]_ | {html}Converts Message from one JMS to another{html} | | _[|#simpleMessageGroupMapFactory-element]_ | {html}A factory to create instances of {@link SimpleMessageGroupMap} when implementing the Message Groups functionality.{html} | + | _[|#sslContext-element]_ | {html}Extends the SslContext so that it's easier to configure from spring.{html} | | _[|#statements-element]_ | {html}{html} | | _[|#storeCursor-element]_ | {html}Pending messages{html} | | _[|#storeDurableSubscriberCursor-element]_ | {html}Pending messages for a durable{html} | diff --git a/activemq-core/src/test/java/org/apache/activemq/transport/tcp/SslContextBrokerServiceTest.java b/activemq-core/src/test/java/org/apache/activemq/transport/tcp/SslContextBrokerServiceTest.java new file mode 100644 index 0000000000..a154e41927 --- /dev/null +++ b/activemq-core/src/test/java/org/apache/activemq/transport/tcp/SslContextBrokerServiceTest.java @@ -0,0 +1,69 @@ +/** + * 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.transport.tcp; + +import java.net.URI; +import java.net.URISyntaxException; +import java.util.Map; + +import junit.framework.Test; +import junit.framework.TestCase; +import junit.textui.TestRunner; +import org.apache.activemq.broker.BrokerService; +import org.apache.activemq.broker.TransportConnector; +import org.apache.activemq.transport.TransportBrokerTestSupport; +import org.springframework.context.support.ClassPathXmlApplicationContext; + +/** + * + */ +public class SslContextBrokerServiceTest extends TestCase { + + + private ClassPathXmlApplicationContext context; + private BrokerService broker; + private TransportConnector connector; + + + public void testConfiguration() throws URISyntaxException { + + assertNotNull(broker); + assertNotNull(connector); + + assertEquals(new URI("ssl://localhost:61616"), connector.getUri()); + + assertNotNull(broker.getSslContext()); + assertFalse(broker.getSslContext().getKeyManagers().isEmpty()); + assertFalse(broker.getSslContext().getTrustManagers().isEmpty()); + + } + + protected void setUp() throws Exception { + Thread.currentThread().setContextClassLoader(SslContextBrokerServiceTest.class.getClassLoader()); + context = new ClassPathXmlApplicationContext("org/apache/activemq/transport/tcp/activemq-ssl.xml"); + Map beansOfType = context.getBeansOfType(BrokerService.class); + broker = (BrokerService)beansOfType.values().iterator().next(); + connector = broker.getTransportConnectors().get(0); + } + + @Override + protected void tearDown() throws Exception { + + context.destroy(); + } + +} diff --git a/activemq-core/src/test/resources/org/apache/activemq/transport/tcp/activemq-ssl.xml b/activemq-core/src/test/resources/org/apache/activemq/transport/tcp/activemq-ssl.xml new file mode 100755 index 0000000000..1fe92a9df7 --- /dev/null +++ b/activemq-core/src/test/resources/org/apache/activemq/transport/tcp/activemq-ssl.xml @@ -0,0 +1,44 @@ + + + + + + + + + + + + + + + + + + + + + +
ElementTypeDescription
brokerInfo<spring:bean/>
brokerServicebroker
brokerServicebrokerThis is called by the BrokerService right before it starts the transport.
discoveryAgent<spring:bean/>
messageAuthorizationPolicy<spring:bean/>Sets the policy used to decide if the current connection is authorized to consume a given message