You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@activemq.apache.org by ta...@apache.org on 2012/05/04 16:17:36 UTC
svn commit: r1333980 - in /activemq/trunk/activemq-optional/src:
main/java/org/apache/activemq/transport/https/
test/java/org/apache/activemq/transport/https/ test/resources/
Author: tabish
Date: Fri May 4 14:17:36 2012
New Revision: 1333980
URL: http://svn.apache.org/viewvc?rev=1333980&view=rev
Log:
apply patch for: https://issues.apache.org/jira/browse/AMQ-3827
Added:
activemq/trunk/activemq-optional/src/test/java/org/apache/activemq/transport/https/HttpsJmsSendAndReceiveConfigurationSslConfigTest.java (with props)
activemq/trunk/activemq-optional/src/test/java/org/apache/activemq/transport/https/HttpsJmsSendAndReceiveEmbeddedSslConfigTest.java (with props)
activemq/trunk/activemq-optional/src/test/resources/activemq-https.xml (with props)
Modified:
activemq/trunk/activemq-optional/src/main/java/org/apache/activemq/transport/https/HttpsTransportFactory.java
activemq/trunk/activemq-optional/src/main/java/org/apache/activemq/transport/https/HttpsTransportServer.java
Modified: activemq/trunk/activemq-optional/src/main/java/org/apache/activemq/transport/https/HttpsTransportFactory.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-optional/src/main/java/org/apache/activemq/transport/https/HttpsTransportFactory.java?rev=1333980&r1=1333979&r2=1333980&view=diff
==============================================================================
--- activemq/trunk/activemq-optional/src/main/java/org/apache/activemq/transport/https/HttpsTransportFactory.java (original)
+++ activemq/trunk/activemq-optional/src/main/java/org/apache/activemq/transport/https/HttpsTransportFactory.java Fri May 4 14:17:36 2012
@@ -20,14 +20,15 @@ import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URI;
import java.net.URISyntaxException;
-import java.util.Map;
import java.util.HashMap;
+import java.util.Map;
+import org.apache.activemq.broker.SslContext;
import org.apache.activemq.transport.Transport;
import org.apache.activemq.transport.TransportServer;
import org.apache.activemq.transport.http.HttpTransportFactory;
-import org.apache.activemq.util.IntrospectionSupport;
import org.apache.activemq.util.IOExceptionSupport;
+import org.apache.activemq.util.IntrospectionSupport;
import org.apache.activemq.util.URISupport;
import org.apache.activemq.wireformat.WireFormat;
@@ -43,18 +44,16 @@ public class HttpsTransportFactory exten
public TransportServer doBind(URI location) throws IOException {
try {
Map<String, String> options = new HashMap<String, String>(URISupport.parseParameters(location));
- HttpsTransportServer result = new HttpsTransportServer(location, this);
+ HttpsTransportServer result = new HttpsTransportServer(location, this, SslContext.getCurrentSslContext());
Map<String, Object> transportOptions = IntrospectionSupport.extractProperties(options, "transport.");
result.setTransportOption(transportOptions);
return result;
} catch (URISyntaxException e) {
throw IOExceptionSupport.create(e);
}
-
}
protected Transport createTransport(URI location, WireFormat wf) throws MalformedURLException {
return new HttpsClientTransport(asTextWireFormat(wf), location);
}
-
}
Modified: activemq/trunk/activemq-optional/src/main/java/org/apache/activemq/transport/https/HttpsTransportServer.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-optional/src/main/java/org/apache/activemq/transport/https/HttpsTransportServer.java?rev=1333980&r1=1333979&r2=1333980&view=diff
==============================================================================
--- activemq/trunk/activemq-optional/src/main/java/org/apache/activemq/transport/https/HttpsTransportServer.java (original)
+++ activemq/trunk/activemq-optional/src/main/java/org/apache/activemq/transport/https/HttpsTransportServer.java Fri May 4 14:17:36 2012
@@ -18,7 +18,11 @@ package org.apache.activemq.transport.ht
import java.net.URI;
+import javax.net.ssl.SSLContext;
+
+import org.apache.activemq.broker.SslContext;
import org.apache.activemq.transport.http.HttpTransportServer;
+import org.eclipse.jetty.util.ssl.SslContextFactory;
public class HttpsTransportServer extends HttpTransportServer {
@@ -31,41 +35,61 @@ public class HttpsTransportServer extend
private String keyCertificateAlgorithm;
private String protocol;
private String auth;
+ private SslContext context;
- public HttpsTransportServer(URI uri, HttpsTransportFactory factory) {
+ public HttpsTransportServer(URI uri, HttpsTransportFactory factory, SslContext context) {
super(uri, factory);
+ this.context = context;
}
public void doStart() throws Exception {
Krb5AndCertsSslSocketConnector sslConnector = new Krb5AndCertsSslSocketConnector();
- if(auth != null){
- sslConnector.setMode(auth);
- }
-
- sslConnector.getSslContextFactory().setKeyStore(keyStore);
- sslConnector.getSslContextFactory().setKeyStorePassword(keyStorePassword);
- // if the keyPassword hasn't been set, default it to the
- // key store password
- if (keyPassword == null) {
- sslConnector.getSslContextFactory().setKeyStorePassword(keyStorePassword);
- }
- if (keyStoreType != null) {
- sslConnector.getSslContextFactory().setKeyStoreType(keyStoreType);
- }
- if (secureRandomCertficateAlgorithm != null) {
- sslConnector.getSslContextFactory().setSecureRandomAlgorithm(secureRandomCertficateAlgorithm);
- }
- if (keyCertificateAlgorithm != null) {
- sslConnector.getSslContextFactory().setSslKeyManagerFactoryAlgorithm(keyCertificateAlgorithm);
- }
- if (trustCertificateAlgorithm != null) {
- sslConnector.getSslContextFactory().setTrustManagerFactoryAlgorithm(trustCertificateAlgorithm);
- }
- if (protocol != null) {
- sslConnector.getSslContextFactory().setProtocol(protocol);
- }
-
+ SSLContext sslContext = context == null ? null : context.getSSLContext();
+
+ // Get a reference to the current ssl context factory...
+ SslContextFactory factory = sslConnector.getSslContextFactory();
+
+ if (context != null) {
+
+ // Should not be using this method since it does not use all of the values
+ // from the passed SslContext instance.....
+ factory.setSslContext(sslContext);
+
+ } else {
+
+ if (auth != null) {
+ sslConnector.setMode(auth);
+ }
+
+ if (keyStore != null) {
+ factory.setKeyStorePath(keyStore);
+ }
+ if (keyStorePassword != null) {
+ factory.setKeyStorePassword(keyStorePassword);
+ }
+ // if the keyPassword hasn't been set, default it to the
+ // key store password
+ if (keyPassword == null && keyStorePassword != null) {
+ factory.setKeyStorePassword(keyStorePassword);
+ }
+ if (keyStoreType != null) {
+ factory.setKeyStoreType(keyStoreType);
+ }
+ if (secureRandomCertficateAlgorithm != null) {
+ factory.setSecureRandomAlgorithm(secureRandomCertficateAlgorithm);
+ }
+ if (keyCertificateAlgorithm != null) {
+ factory.setSslKeyManagerFactoryAlgorithm(keyCertificateAlgorithm);
+ }
+ if (trustCertificateAlgorithm != null) {
+ factory.setTrustManagerFactoryAlgorithm(trustCertificateAlgorithm);
+ }
+ if (protocol != null) {
+ factory.setProtocol(protocol);
+ }
+ }
+
setConnector(sslConnector);
super.doStart();
Added: activemq/trunk/activemq-optional/src/test/java/org/apache/activemq/transport/https/HttpsJmsSendAndReceiveConfigurationSslConfigTest.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-optional/src/test/java/org/apache/activemq/transport/https/HttpsJmsSendAndReceiveConfigurationSslConfigTest.java?rev=1333980&view=auto
==============================================================================
--- activemq/trunk/activemq-optional/src/test/java/org/apache/activemq/transport/https/HttpsJmsSendAndReceiveConfigurationSslConfigTest.java (added)
+++ activemq/trunk/activemq-optional/src/test/java/org/apache/activemq/transport/https/HttpsJmsSendAndReceiveConfigurationSslConfigTest.java Fri May 4 14:17:36 2012
@@ -0,0 +1,85 @@
+/**
+ * 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.https;
+
+import org.apache.activemq.ActiveMQConnectionFactory;
+import org.apache.activemq.JmsTopicSendReceiveTest;
+import org.apache.activemq.broker.BrokerFactory;
+import org.apache.activemq.broker.BrokerService;
+
+/**
+ * @author Claudio Corsi
+ *
+ */
+public class HttpsJmsSendAndReceiveConfigurationSslConfigTest extends
+ JmsTopicSendReceiveTest {
+
+ public static final String KEYSTORE_TYPE = "jks";
+ public static final String PASSWORD = "password";
+ public static final String TRUST_KEYSTORE = "src/test/resources/client.keystore";
+
+ private BrokerService broker;
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.apache.activemq.JmsSendReceiveTestSupport#setUp()
+ */
+ @Override
+ protected void setUp() throws Exception {
+ // Create the broker service from the configuration and wait until it
+ // has been started...
+ broker = BrokerFactory.createBroker("xbean:activemq-https.xml");
+ broker.setPersistent(false);
+ broker.start();
+ broker.waitUntilStarted();
+ System.setProperty("javax.net.ssl.trustStore", TRUST_KEYSTORE);
+ System.setProperty("javax.net.ssl.trustStorePassword", PASSWORD);
+ System.setProperty("javax.net.ssl.trustStoreType", KEYSTORE_TYPE);
+ // Remove all references of the javax.net.ssl properties that can impact
+ // these tests....
+ System.getProperties().remove("javax.net.ssl.keyStore");
+ System.getProperties().remove("javax.net.ssl.keyStorePassword");
+ System.getProperties().remove("javax.net.ssl.keyStoreType");
+ super.setUp();
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.apache.activemq.AutoFailTestSupport#tearDown()
+ */
+ @Override
+ protected void tearDown() throws Exception {
+ super.tearDown();
+ if (broker != null) {
+ broker.stop();
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.apache.activemq.TestSupport#createConnectionFactory()
+ */
+ @Override
+ protected ActiveMQConnectionFactory createConnectionFactory()
+ throws Exception {
+ return new ActiveMQConnectionFactory("https://localhost:8161");
+ }
+
+}
Propchange: activemq/trunk/activemq-optional/src/test/java/org/apache/activemq/transport/https/HttpsJmsSendAndReceiveConfigurationSslConfigTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: activemq/trunk/activemq-optional/src/test/java/org/apache/activemq/transport/https/HttpsJmsSendAndReceiveEmbeddedSslConfigTest.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-optional/src/test/java/org/apache/activemq/transport/https/HttpsJmsSendAndReceiveEmbeddedSslConfigTest.java?rev=1333980&view=auto
==============================================================================
--- activemq/trunk/activemq-optional/src/test/java/org/apache/activemq/transport/https/HttpsJmsSendAndReceiveEmbeddedSslConfigTest.java (added)
+++ activemq/trunk/activemq-optional/src/test/java/org/apache/activemq/transport/https/HttpsJmsSendAndReceiveEmbeddedSslConfigTest.java Fri May 4 14:17:36 2012
@@ -0,0 +1,99 @@
+/**
+ * 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.https;
+
+import org.apache.activemq.ActiveMQConnectionFactory;
+import org.apache.activemq.JmsTopicSendReceiveTest;
+import org.apache.activemq.broker.BrokerService;
+import org.apache.activemq.spring.SpringSslContext;
+
+/**
+ * @author Claudio Corsi
+ *
+ */
+public class HttpsJmsSendAndReceiveEmbeddedSslConfigTest extends
+ JmsTopicSendReceiveTest {
+
+ /**
+ *
+ */
+ private static final String URI_LOCATION = "https://localhost:8161";
+ public static final String KEYSTORE_TYPE = "jks";
+ public static final String PASSWORD = "password";
+ public static final String TRUST_KEYSTORE = "src/test/resources/client.keystore";
+ public static final String SERVER_KEYSTORE = "src/test/resources/server.keystore";
+
+ private BrokerService broker;
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.apache.activemq.JmsSendReceiveTestSupport#setUp()
+ */
+ @Override
+ protected void setUp() throws Exception {
+ // Create the broker service from the configuration and wait until it
+ // has been started...
+ broker = new BrokerService();
+ SpringSslContext sslContext = new SpringSslContext();
+ sslContext.setKeyStorePassword(PASSWORD);
+ sslContext.setKeyStore(SERVER_KEYSTORE);
+ sslContext.setTrustStore(TRUST_KEYSTORE);
+ sslContext.setTrustStorePassword(PASSWORD);
+ sslContext.afterPropertiesSet(); // This is required so that the SSLContext instance is generated with the passed information.
+ broker.setSslContext(sslContext);
+ broker.addConnector(URI_LOCATION);
+ broker.setPersistent(false);
+ broker.setUseJmx(false);
+ broker.start();
+ broker.waitUntilStarted();
+ System.setProperty("javax.net.ssl.trustStore", TRUST_KEYSTORE);
+ System.setProperty("javax.net.ssl.trustStorePassword", PASSWORD);
+ System.setProperty("javax.net.ssl.trustStoreType", KEYSTORE_TYPE);
+ // Remove all references of the javax.net.ssl properties that can impact
+ // these tests....
+ System.getProperties().remove("javax.net.ssl.keyStore");
+ System.getProperties().remove("javax.net.ssl.keyStorePassword");
+ System.getProperties().remove("javax.net.ssl.keyStoreType");
+ super.setUp();
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.apache.activemq.AutoFailTestSupport#tearDown()
+ */
+ @Override
+ protected void tearDown() throws Exception {
+ super.tearDown();
+ if (broker != null) {
+ broker.stop();
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.apache.activemq.TestSupport#createConnectionFactory()
+ */
+ @Override
+ protected ActiveMQConnectionFactory createConnectionFactory()
+ throws Exception {
+ return new ActiveMQConnectionFactory(URI_LOCATION);
+ }
+
+}
Propchange: activemq/trunk/activemq-optional/src/test/java/org/apache/activemq/transport/https/HttpsJmsSendAndReceiveEmbeddedSslConfigTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: activemq/trunk/activemq-optional/src/test/resources/activemq-https.xml
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-optional/src/test/resources/activemq-https.xml?rev=1333980&view=auto
==============================================================================
--- activemq/trunk/activemq-optional/src/test/resources/activemq-https.xml (added)
+++ activemq/trunk/activemq-optional/src/test/resources/activemq-https.xml Fri May 4 14:17:36 2012
@@ -0,0 +1,41 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ 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.
+-->
+
+<beans xmlns="http://www.springframework.org/schema/beans"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xmlns:amq="http://activemq.apache.org/schema/core"
+ xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd http://activemq.apache.org/schema/core http://activemq.apache.org/schema/core/activemq-core.xsd ">
+
+ <bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer" />
+
+ <amq:broker brokerName="localhost" useJmx="false">
+
+ <amq:sslContext>
+ <amq:sslContext keyStorePassword="password"
+ keyStore="src/test/resources/server.keystore"
+ trustStore="src/test/resources/client.keystore"
+ trustStorePassword="password" />
+ </amq:sslContext>
+
+ <amq:transportConnectors>
+ <amq:transportConnector name="https"
+ uri="https://localhost:8161" />
+ </amq:transportConnectors>
+ </amq:broker>
+
+</beans>
Propchange: activemq/trunk/activemq-optional/src/test/resources/activemq-https.xml
------------------------------------------------------------------------------
svn:eol-style = native