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/10/26 01:16:58 UTC
svn commit: r1402354 - in /activemq/trunk/activemq-core/src:
main/java/org/apache/activemq/transport/nio/
main/java/org/apache/activemq/transport/stomp/
test/java/org/apache/activemq/bugs/
test/resources/org/apache/activemq/bugs/amq4126/
Author: tabish
Date: Thu Oct 25 23:16:57 2012
New Revision: 1402354
URL: http://svn.apache.org/viewvc?rev=1402354&view=rev
Log:
fix for: https://issues.apache.org/jira/browse/AMQ-4133
Added:
activemq/trunk/activemq-core/src/main/java/org/apache/activemq/transport/nio/NIOSSLTransportServer.java (with props)
activemq/trunk/activemq-core/src/test/java/org/apache/activemq/bugs/AMQ4133Test.java (with props)
activemq/trunk/activemq-core/src/test/resources/org/apache/activemq/bugs/amq4126/InconsistentConnectorPropertiesBehaviour.xml (with props)
Modified:
activemq/trunk/activemq-core/src/main/java/org/apache/activemq/transport/nio/NIOSSLTransportFactory.java
activemq/trunk/activemq-core/src/main/java/org/apache/activemq/transport/stomp/StompNIOSSLTransportFactory.java
Modified: activemq/trunk/activemq-core/src/main/java/org/apache/activemq/transport/nio/NIOSSLTransportFactory.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/transport/nio/NIOSSLTransportFactory.java?rev=1402354&r1=1402353&r2=1402354&view=diff
==============================================================================
--- activemq/trunk/activemq-core/src/main/java/org/apache/activemq/transport/nio/NIOSSLTransportFactory.java (original)
+++ activemq/trunk/activemq-core/src/main/java/org/apache/activemq/transport/nio/NIOSSLTransportFactory.java Thu Oct 25 23:16:57 2012
@@ -18,7 +18,6 @@
package org.apache.activemq.transport.nio;
import java.io.IOException;
-import java.net.Socket;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.UnknownHostException;
@@ -42,48 +41,35 @@ import org.slf4j.LoggerFactory;
public class NIOSSLTransportFactory extends NIOTransportFactory {
private static final Logger LOG = LoggerFactory.getLogger(NIOSSLTransportFactory.class);
- SSLContext context;
- protected TcpTransportServer createTcpTransportServer(URI location, ServerSocketFactory serverSocketFactory) throws IOException, URISyntaxException {
- return new TcpTransportServer(this, location, serverSocketFactory) {
- protected Transport createTransport(Socket socket, WireFormat format) throws IOException {
- NIOSSLTransport transport = new NIOSSLTransport(format, socket);
- if (context != null) {
- transport.setSslContext(context);
- }
- return transport;
- }
+ protected SSLContext context;
- @Override
- public boolean isSslServer() {
- return true;
- }
- };
+ protected TcpTransportServer createTcpTransportServer(URI location, ServerSocketFactory serverSocketFactory) throws IOException, URISyntaxException {
+ return new NIOSSLTransportServer(context, this, location, serverSocketFactory);
}
@Override
public TransportServer doBind(URI location) throws IOException {
- if (SslContext.getCurrentSslContext() != null) {
- try {
- context = SslContext.getCurrentSslContext().getSSLContext();
- } catch (Exception e) {
- throw new IOException(e);
- }
- }
+ if (SslContext.getCurrentSslContext() != null) {
+ try {
+ context = SslContext.getCurrentSslContext().getSSLContext();
+ } catch (Exception e) {
+ throw new IOException(e);
+ }
+ }
return super.doBind(location);
}
-
/**
- * Overriding to allow for proper configuration through reflection but delegate to get common
- * configuration
+ * Overriding to allow for proper configuration through reflection but
+ * delegate to get common configuration
*/
public Transport compositeConfigure(Transport transport, WireFormat format, Map options) {
- if (transport instanceof SslTransport) {
- SslTransport sslTransport = (SslTransport)transport.narrow(SslTransport.class);
+ if (transport instanceof SslTransport) {
+ SslTransport sslTransport = (SslTransport) transport.narrow(SslTransport.class);
IntrospectionSupport.setProperties(sslTransport, options);
} else if (transport instanceof NIOSSLTransport) {
- NIOSSLTransport sslTransport = (NIOSSLTransport)transport.narrow(NIOSSLTransport.class);
+ NIOSSLTransport sslTransport = (NIOSSLTransport) transport.narrow(NIOSSLTransport.class);
IntrospectionSupport.setProperties(sslTransport, options);
}
@@ -109,7 +95,7 @@ public class NIOSSLTransportFactory exte
}
}
SocketFactory socketFactory = createSocketFactory();
- return new SslTransport(wf, (SSLSocketFactory)socketFactory, location, localLocation, false);
+ return new SslTransport(wf, (SSLSocketFactory) socketFactory, location, localLocation, false);
}
/**
@@ -120,7 +106,7 @@ public class NIOSSLTransportFactory exte
* @throws IOException
*/
protected SocketFactory createSocketFactory() throws IOException {
- if( SslContext.getCurrentSslContext()!=null ) {
+ if (SslContext.getCurrentSslContext() != null) {
SslContext ctx = SslContext.getCurrentSslContext();
try {
return ctx.getSSLContext().getSocketFactory();
Added: activemq/trunk/activemq-core/src/main/java/org/apache/activemq/transport/nio/NIOSSLTransportServer.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/transport/nio/NIOSSLTransportServer.java?rev=1402354&view=auto
==============================================================================
--- activemq/trunk/activemq-core/src/main/java/org/apache/activemq/transport/nio/NIOSSLTransportServer.java (added)
+++ activemq/trunk/activemq-core/src/main/java/org/apache/activemq/transport/nio/NIOSSLTransportServer.java Thu Oct 25 23:16:57 2012
@@ -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.transport.nio;
+
+import java.io.IOException;
+import java.net.Socket;
+import java.net.URI;
+import java.net.URISyntaxException;
+
+import javax.net.ServerSocketFactory;
+import javax.net.ssl.SSLContext;
+
+import org.apache.activemq.transport.Transport;
+import org.apache.activemq.transport.tcp.TcpTransportFactory;
+import org.apache.activemq.transport.tcp.TcpTransportServer;
+import org.apache.activemq.wireformat.WireFormat;
+
+public class NIOSSLTransportServer extends TcpTransportServer {
+
+ private SSLContext context;
+
+ public NIOSSLTransportServer(SSLContext context, TcpTransportFactory transportFactory, URI location, ServerSocketFactory serverSocketFactory) throws IOException, URISyntaxException {
+ super(transportFactory, location, serverSocketFactory);
+
+ this.context = context;
+ }
+
+ private boolean needClientAuth;
+ private boolean wantClientAuth;
+
+ @Override
+ protected Transport createTransport(Socket socket, WireFormat format) throws IOException {
+ NIOSSLTransport transport = new NIOSSLTransport(format, socket);
+ if (context != null) {
+ transport.setSslContext(context);
+ }
+
+ transport.setNeedClientAuth(needClientAuth);
+ transport.setWantClientAuth(wantClientAuth);
+
+ return transport;
+ }
+
+ @Override
+ public boolean isSslServer() {
+ return true;
+ }
+
+ public boolean isNeedClientAuth() {
+ return this.needClientAuth;
+ }
+
+ public void setNeedClientAuth(boolean value) {
+ this.needClientAuth = value;
+ }
+
+ public boolean isWantClientAuth() {
+ return this.wantClientAuth;
+ }
+
+ public void setWantClientAuth(boolean value) {
+ this.wantClientAuth = value;
+ }
+}
Propchange: activemq/trunk/activemq-core/src/main/java/org/apache/activemq/transport/nio/NIOSSLTransportServer.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: activemq/trunk/activemq-core/src/main/java/org/apache/activemq/transport/stomp/StompNIOSSLTransportFactory.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/transport/stomp/StompNIOSSLTransportFactory.java?rev=1402354&r1=1402353&r2=1402354&view=diff
==============================================================================
--- activemq/trunk/activemq-core/src/main/java/org/apache/activemq/transport/stomp/StompNIOSSLTransportFactory.java (original)
+++ activemq/trunk/activemq-core/src/main/java/org/apache/activemq/transport/stomp/StompNIOSSLTransportFactory.java Thu Oct 25 23:16:57 2012
@@ -29,28 +29,30 @@ import javax.net.ssl.SSLContext;
import org.apache.activemq.broker.SslContext;
import org.apache.activemq.transport.Transport;
import org.apache.activemq.transport.TransportServer;
+import org.apache.activemq.transport.nio.NIOSSLTransportServer;
import org.apache.activemq.transport.tcp.TcpTransport;
import org.apache.activemq.transport.tcp.TcpTransportServer;
import org.apache.activemq.wireformat.WireFormat;
public class StompNIOSSLTransportFactory extends StompNIOTransportFactory {
- SSLContext context;
+ protected SSLContext context;
@Override
protected TcpTransportServer createTcpTransportServer(URI location, ServerSocketFactory serverSocketFactory) throws IOException, URISyntaxException {
- return new TcpTransportServer(this, location, serverSocketFactory) {
+ return new NIOSSLTransportServer(context, this, location, serverSocketFactory) {
+
+ @Override
protected Transport createTransport(Socket socket, WireFormat format) throws IOException {
StompNIOSSLTransport transport = new StompNIOSSLTransport(format, socket);
if (context != null) {
transport.setSslContext(context);
}
- return transport;
- }
- @Override
- public boolean isSslServer() {
- return true;
+ transport.setNeedClientAuth(isNeedClientAuth());
+ transport.setWantClientAuth(isWantClientAuth());
+
+ return transport;
}
};
}
@@ -62,7 +64,7 @@ public class StompNIOSSLTransportFactory
@Override
public TransportServer doBind(URI location) throws IOException {
- if (SslContext.getCurrentSslContext() != null) {
+ if (SslContext.getCurrentSslContext() != null) {
try {
context = SslContext.getCurrentSslContext().getSSLContext();
} catch (Exception e) {
@@ -71,5 +73,4 @@ public class StompNIOSSLTransportFactory
}
return super.doBind(location);
}
-
}
Added: activemq/trunk/activemq-core/src/test/java/org/apache/activemq/bugs/AMQ4133Test.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-core/src/test/java/org/apache/activemq/bugs/AMQ4133Test.java?rev=1402354&view=auto
==============================================================================
--- activemq/trunk/activemq-core/src/test/java/org/apache/activemq/bugs/AMQ4133Test.java (added)
+++ activemq/trunk/activemq-core/src/test/java/org/apache/activemq/bugs/AMQ4133Test.java Thu Oct 25 23:16:57 2012
@@ -0,0 +1,108 @@
+/**
+ * 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.bugs;
+
+import java.io.File;
+import java.net.Socket;
+
+import junit.framework.TestCase;
+import org.apache.activemq.broker.BrokerFactory;
+import org.apache.activemq.broker.BrokerService;
+import org.apache.activemq.transport.stomp.Stomp;
+import org.apache.activemq.transport.stomp.StompConnection;
+import org.apache.activemq.transport.stomp.StompFrame;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+import javax.net.SocketFactory;
+import javax.net.ssl.SSLSocketFactory;
+
+public class AMQ4133Test {
+
+ protected String java_security_auth_login_config = "java.security.auth.login.config";
+ protected String xbean = "xbean:";
+ protected String confBase = "src/test/resources/org/apache/activemq/bugs/amq4126";
+ protected String certBase = "src/test/resources/org/apache/activemq/security";
+ protected String sep = File.separator;
+ protected String activemqXml = "InconsistentConnectorPropertiesBehaviour.xml";
+ protected BrokerService broker;
+
+ protected String oldLoginConf = null;
+
+ @Before
+ public void before() throws Exception {
+ if (System.getProperty(java_security_auth_login_config) != null) {
+ oldLoginConf = System.getProperty(java_security_auth_login_config);
+ }
+ System.setProperty(java_security_auth_login_config, confBase + sep + "login.config");
+ broker = BrokerFactory.createBroker(xbean + confBase + sep + activemqXml);
+
+ broker.start();
+ broker.waitUntilStarted();
+ }
+
+ @After
+ public void after() throws Exception {
+ if (broker != null) {
+ broker.stop();
+ broker.waitUntilStopped();
+ }
+ }
+
+ @Test
+ public void stompSSLTransportNeedClientAuthTrue() throws Exception {
+ stompConnectTo("localhost", broker.getConnectorByName("stomp+ssl").getConnectUri().getPort());
+ }
+
+ @Test
+ public void stompSSLNeedClientAuthTrue() throws Exception {
+ stompConnectTo("localhost", broker.getConnectorByName("stomp+ssl+special").getConnectUri().getPort());
+ }
+
+ @Test
+ public void stompNIOSSLTransportNeedClientAuthTrue() throws Exception {
+ stompConnectTo("localhost", broker.getConnectorByName("stomp+nio+ssl").getConnectUri().getPort());
+ }
+
+ @Test
+ public void stompNIOSSLNeedClientAuthTrue() throws Exception {
+ stompConnectTo("localhost", broker.getConnectorByName("stomp+nio+ssl+special").getConnectUri().getPort());
+ }
+
+ public Socket createSocket(String host, int port) throws Exception {
+ System.setProperty("javax.net.ssl.trustStore", certBase + sep + "broker1.ks");
+ System.setProperty("javax.net.ssl.trustStorePassword", "password");
+ System.setProperty("javax.net.ssl.trustStoreType", "jks");
+ System.setProperty("javax.net.ssl.keyStore", certBase + sep + "client.ks");
+ System.setProperty("javax.net.ssl.keyStorePassword", "password");
+ System.setProperty("javax.net.ssl.keyStoreType", "jks");
+
+ SocketFactory factory = SSLSocketFactory.getDefault();
+ return factory.createSocket(host, port);
+ }
+
+ public void stompConnectTo(String host, int port) throws Exception {
+ StompConnection stompConnection = new StompConnection();
+ stompConnection.open(createSocket(host, port));
+ stompConnection.sendFrame("CONNECT\n" + "\n" + Stomp.NULL);
+ StompFrame f = stompConnection.receive();
+ TestCase.assertEquals(f.getBody(), "CONNECTED", f.getAction());
+ stompConnection.close();
+ }
+
+}
Propchange: activemq/trunk/activemq-core/src/test/java/org/apache/activemq/bugs/AMQ4133Test.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: activemq/trunk/activemq-core/src/test/resources/org/apache/activemq/bugs/amq4126/InconsistentConnectorPropertiesBehaviour.xml
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-core/src/test/resources/org/apache/activemq/bugs/amq4126/InconsistentConnectorPropertiesBehaviour.xml?rev=1402354&view=auto
==============================================================================
--- activemq/trunk/activemq-core/src/test/resources/org/apache/activemq/bugs/amq4126/InconsistentConnectorPropertiesBehaviour.xml (added)
+++ activemq/trunk/activemq-core/src/test/resources/org/apache/activemq/bugs/amq4126/InconsistentConnectorPropertiesBehaviour.xml Thu Oct 25 23:16:57 2012
@@ -0,0 +1,46 @@
+<?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:amq="http://activemq.apache.org/schema/core"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ 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">
+
+ <broker xmlns="http://activemq.apache.org/schema/core" brokerName="broker" id="broker" useJmx="false" persistent="false">
+
+ <plugins>
+ <jaasDualAuthenticationPlugin configuration="activemq-domain" sslConfiguration="activemq-ssl-domain"/>
+ </plugins>
+
+ <sslContext>
+ <sslContext
+ keyStore="./src/test/resources/org/apache/activemq/security/broker1.ks" keyStorePassword="password"
+ trustStore="./src/test/resources/org/apache/activemq/security/client.ks" trustStorePassword="password"/>
+ </sslContext>
+
+ <transportConnectors>
+ <transportConnector name="stomp+ssl+special" uri="stomp+ssl://0.0.0.0:0?needClientAuth=true" />
+ <transportConnector name="stomp+ssl" uri="stomp+ssl://0.0.0.0:0?transport.needClientAuth=true" />
+ <transportConnector name="stomp+nio+ssl+special" uri="stomp+nio+ssl://0.0.0.0:0?needClientAuth=true" />
+ <transportConnector name="stomp+nio+ssl" uri="stomp+nio+ssl://0.0.0.0:0?transport.needClientAuth=true" />
+ </transportConnectors>
+
+ </broker>
+</beans>
Propchange: activemq/trunk/activemq-core/src/test/resources/org/apache/activemq/bugs/amq4126/InconsistentConnectorPropertiesBehaviour.xml
------------------------------------------------------------------------------
svn:eol-style = native