You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@activemq.apache.org by dj...@apache.org on 2008/04/10 21:19:27 UTC

svn commit: r646928 - in /activemq/branches/activemq-4.1/activemq-core/src: main/java/org/apache/activemq/transport/tcp/SslTransportServer.java test/java/org/apache/activemq/transport/tcp/SslTransportServerTest.java

Author: djencks
Date: Thu Apr 10 12:19:23 2008
New Revision: 646928

URL: http://svn.apache.org/viewvc?rev=646928&view=rev
Log:
AMQ-1659 Fix want/needClientAuth code and test

Modified:
    activemq/branches/activemq-4.1/activemq-core/src/main/java/org/apache/activemq/transport/tcp/SslTransportServer.java
    activemq/branches/activemq-4.1/activemq-core/src/test/java/org/apache/activemq/transport/tcp/SslTransportServerTest.java

Modified: activemq/branches/activemq-4.1/activemq-core/src/main/java/org/apache/activemq/transport/tcp/SslTransportServer.java
URL: http://svn.apache.org/viewvc/activemq/branches/activemq-4.1/activemq-core/src/main/java/org/apache/activemq/transport/tcp/SslTransportServer.java?rev=646928&r1=646927&r2=646928&view=diff
==============================================================================
--- activemq/branches/activemq-4.1/activemq-core/src/main/java/org/apache/activemq/transport/tcp/SslTransportServer.java (original)
+++ activemq/branches/activemq-4.1/activemq-core/src/main/java/org/apache/activemq/transport/tcp/SslTransportServer.java Thu Apr 10 12:19:23 2008
@@ -41,10 +41,10 @@
 public class SslTransportServer extends TcpTransportServer {
     
     // Specifies if sockets created from this server should needClientAuth.
-    private boolean needClientAuth = false;
+    private boolean needClientAuth;
     
     // Specifies if sockets created from this server should wantClientAuth.
-    private boolean wantClientAuth = false;
+    private boolean wantClientAuth;
     
     
     /**
@@ -107,8 +107,11 @@
      */
     public void bind() throws IOException {
         super.bind();
-        ((SSLServerSocket)this.serverSocket).setWantClientAuth(wantClientAuth);
-        ((SSLServerSocket)this.serverSocket).setNeedClientAuth(needClientAuth);
+        if (needClientAuth) {
+            ((SSLServerSocket)this.serverSocket).setNeedClientAuth(true);
+        } else if (wantClientAuth) {
+            ((SSLServerSocket)this.serverSocket).setWantClientAuth(true);
+        }
     }
     
     /**

Modified: activemq/branches/activemq-4.1/activemq-core/src/test/java/org/apache/activemq/transport/tcp/SslTransportServerTest.java
URL: http://svn.apache.org/viewvc/activemq/branches/activemq-4.1/activemq-core/src/test/java/org/apache/activemq/transport/tcp/SslTransportServerTest.java?rev=646928&r1=646927&r2=646928&view=diff
==============================================================================
--- activemq/branches/activemq-4.1/activemq-core/src/test/java/org/apache/activemq/transport/tcp/SslTransportServerTest.java (original)
+++ activemq/branches/activemq-4.1/activemq-core/src/test/java/org/apache/activemq/transport/tcp/SslTransportServerTest.java Thu Apr 10 12:19:23 2008
@@ -55,40 +55,41 @@
     
     public void testWantAndNeedClientAuthSetters() throws IOException {
         for (int i = 0; i < 4; ++i) {
-            final boolean wantClientAuth = ((i & 0x1) == 1);
-            final boolean needClientAuth = ((i & 0x2) == 1);
-            
-            final int expectedWantStatus = (wantClientAuth ? StubSSLServerSocket.TRUE : StubSSLServerSocket.FALSE );
-            final int expectedNeedStatus = (needClientAuth ? StubSSLServerSocket.TRUE : StubSSLServerSocket.FALSE );
-            
-            createAndBindTransportServer(wantClientAuth, needClientAuth, "");
-            
-            assertEquals("Created ServerSocket did not have correct wantClientAuth status.",
-                sslServerSocket.getWantClientAuthStatus(), expectedWantStatus);
-            
-            assertEquals("Created ServerSocket did not have correct needClientAuth status.",
-                sslServerSocket.getNeedClientAuthStatus(), expectedNeedStatus);
+            String options = "";
+            singleTest(i, options);
             }
     }
     
     public void testWantAndNeedAuthReflection() throws IOException {
         for (int i = 0; i < 4; ++i) {
-            final boolean wantClientAuth = ((i & 0x1) == 1);
-            final boolean needClientAuth = ((i & 0x2) == 1);
-            
-            final int expectedWantStatus = (wantClientAuth ? StubSSLServerSocket.TRUE : StubSSLServerSocket.FALSE );
-            final int expectedNeedStatus = (needClientAuth ? StubSSLServerSocket.TRUE : StubSSLServerSocket.FALSE );
-            
-            String options = "wantClientAuth=" + (wantClientAuth ? "true" : "false") +
-                "&needClientAuth=" + (needClientAuth ? "true" : "false");
-            
-            createAndBindTransportServer(wantClientAuth, needClientAuth, options);
-            
-            assertEquals("Created ServerSocket did not have correct wantClientAuth status.",
-                sslServerSocket.getWantClientAuthStatus(), expectedWantStatus);
-            
-            assertEquals("Created ServerSocket did not have correct needClientAuth status.",
-                sslServerSocket.getNeedClientAuthStatus(), expectedNeedStatus);
+            String options = "wantClientAuth=" + (getWantClientAuth(i) ? "true" : "false") +
+                "&needClientAuth=" + (getNeedClientAuth(i) ? "true" : "false");
+            singleTest(i, options);
         }
+    }
+
+    private void singleTest(int i, String options) throws IOException {
+        final boolean wantClientAuth = getWantClientAuth(i);
+        final boolean needClientAuth = getNeedClientAuth(i);
+
+        final int expectedWantStatus = (needClientAuth? StubSSLServerSocket.UNTOUCHED: wantClientAuth ? StubSSLServerSocket.TRUE : StubSSLServerSocket.UNTOUCHED);
+        final int expectedNeedStatus = (needClientAuth ? StubSSLServerSocket.TRUE : StubSSLServerSocket.UNTOUCHED );
+
+
+        createAndBindTransportServer(wantClientAuth, needClientAuth, options);
+
+        assertEquals("Created ServerSocket did not have correct wantClientAuth status. wantClientAuth: " + wantClientAuth + ", needClientAuth: " + needClientAuth,
+            expectedWantStatus, sslServerSocket.getWantClientAuthStatus());
+
+        assertEquals("Created ServerSocket did not have correct needClientAuth status. wantClientAuth: " + wantClientAuth + ", needClientAuth: " + needClientAuth,
+            expectedNeedStatus, sslServerSocket.getNeedClientAuthStatus());
+    }
+
+    private boolean getNeedClientAuth(int i) {
+        return ((i & 0x2) == 0x2);
+    }
+
+    private boolean getWantClientAuth(int i) {
+        return ((i & 0x1) == 0x1);
     }
 }