[jboss-remoting-commits] JBoss Remoting SVN: r3460 - remoting3/trunk/jrpp/src/main/java/org/jboss/cx/remoting/jrpp.

jboss-remoting-commits at lists.jboss.org jboss-remoting-commits at lists.jboss.org
Wed Feb 20 22:01:31 EST 2008


Author: david.lloyd at jboss.com
Date: 2008-02-20 22:01:31 -0500 (Wed, 20 Feb 2008)
New Revision: 3460

Modified:
   remoting3/trunk/jrpp/src/main/java/org/jboss/cx/remoting/jrpp/JrppConnection.java
Log:
Fix JRPP session initialization problems

Modified: remoting3/trunk/jrpp/src/main/java/org/jboss/cx/remoting/jrpp/JrppConnection.java
===================================================================
--- remoting3/trunk/jrpp/src/main/java/org/jboss/cx/remoting/jrpp/JrppConnection.java	2008-02-21 00:35:30 UTC (rev 3459)
+++ remoting3/trunk/jrpp/src/main/java/org/jboss/cx/remoting/jrpp/JrppConnection.java	2008-02-21 03:01:31 UTC (rev 3460)
@@ -125,6 +125,7 @@
         try {
             ioSession.setAttribute(JRPP_CONNECTION, this);
             this.ioSession = ioSession;
+            this.protocolContext = protocolContext;
         } finally {
             state.releaseExclusive();
         }
@@ -312,7 +313,7 @@
         output.commit();
     }
 
-    public void sendVersionMessage() throws IOException {
+    private void sendVersionMessage() throws IOException {
         // send version info
         final IoBuffer buffer = newBuffer(60, false);
         final MessageOutput output = protocolContext.getMessageOutput(new IoBufferByteOutput(buffer, ioSession));
@@ -322,6 +323,24 @@
         output.commit();
     }
 
+    private void sendAuthRequest() throws IOException {
+        final CallbackHandler callbackHandler = getClientCallbackHandler(attributeMap);
+        final Map<String, ?> saslProps = getSaslProperties(attributeMap);
+        final String[] clientMechs = getClientMechanisms(attributeMap, saslProps);
+        final String authorizationId = getAuthorizationId(attributeMap, protocolContext);
+        final SaslClient saslClient = Sasl.createSaslClient(clientMechs, authorizationId, "jrpp", remoteName, saslProps, callbackHandler);
+        final SaslClientFilter saslClientFilter = getSaslClientFilter();
+        saslClientFilter.setSaslClient(ioSession, saslClient);
+        final IoBuffer buffer = newBuffer(600, true);
+        MessageOutput output = protocolContext.getMessageOutput(new IoBufferByteOutput(buffer, ioSession));
+        write(output, MessageType.AUTH_REQUEST);
+        output.writeInt(clientMechs.length);
+        for (String mech : clientMechs) {
+            output.writeUTF(mech);
+        }
+        output.commit();
+    }
+
     public boolean waitForUp() throws IOException {
         while (! state.in(State.UP, State.CLOSED)) {
             state.waitForAny();
@@ -633,22 +652,30 @@
                             for (int i = 0; i < mechCount; i ++) {
                                 clientMechs[i] = input.readUTF();
                             }
-                            final CallbackHandler callbackHandler = getServerCallbackHandler(attributeMap);
-                            final Map<String, ?> saslProps = getSaslProperties(attributeMap);
-                            final Set<String> serverMechs = getServerMechanisms(attributeMap, saslProps);
-                            final String negotiatedMechanism = getNegotiatedMechanism(clientMechs, serverMechs);
-                            final SaslServer saslServer = Sasl.createSaslServer(negotiatedMechanism, "jrpp", protocolContext.getLocalEndpointName(), saslProps, callbackHandler);
-                            final SaslServerFilter saslServerFilter = getSaslServerFilter();
-                            saslServerFilter.setSaslServer(ioSession, saslServer);
-                            if (saslServerFilter.sendInitialChallenge(ioSession)) {
-                                // complete (that was quick!)
-                                final IoBuffer buffer = newBuffer(60, false);
+                            try {
+                                final CallbackHandler callbackHandler = getServerCallbackHandler(attributeMap);
+                                final Map<String, ?> saslProps = getSaslProperties(attributeMap);
+                                final Set<String> serverMechs = getServerMechanisms(attributeMap, saslProps);
+                                final String negotiatedMechanism = getNegotiatedMechanism(clientMechs, serverMechs);
+                                final SaslServer saslServer = Sasl.createSaslServer(negotiatedMechanism, "jrpp", protocolContext.getLocalEndpointName(), saslProps, callbackHandler);
+                                final SaslServerFilter saslServerFilter = getSaslServerFilter();
+                                saslServerFilter.setSaslServer(ioSession, saslServer);
+                                if (saslServerFilter.sendInitialChallenge(ioSession)) {
+                                    // complete (that was quick!)
+                                    final IoBuffer buffer = newBuffer(60, false);
+                                    final MessageOutput output = protocolContext.getMessageOutput(new IoBufferByteOutput(buffer, ioSession));
+                                    write(output, MessageType.AUTH_SUCCESS);
+                                    output.commit();
+                                    state.requireTransition(State.AWAITING_CLIENT_VERSION, State.UP);
+                                } else {
+                                    state.requireTransition(State.AWAITING_CLIENT_VERSION, State.AWAITING_CLIENT_RESPONSE);
+                                }
+                            } catch (SaslException ex) {
+                                final IoBuffer buffer = newBuffer(100, true);
                                 final MessageOutput output = protocolContext.getMessageOutput(new IoBufferByteOutput(buffer, ioSession));
-                                write(output, MessageType.AUTH_SUCCESS);
+                                write(output, MessageType.AUTH_FAILED);
+                                output.writeUTF("Unable to initiate SASL authentication: " + ex.getMessage());
                                 output.commit();
-                                state.requireTransition(State.AWAITING_CLIENT_VERSION, State.UP);
-                            } else {
-                                state.requireTransition(State.AWAITING_CLIENT_VERSION, State.AWAITING_CLIENT_RESPONSE);
                             }
                             return;
                         }
@@ -664,13 +691,7 @@
                             }
                             final String name = input.readUTF();
                             remoteName = name.length() > 0 ? name : null;
-                            final CallbackHandler callbackHandler = getClientCallbackHandler(attributeMap);
-                            final Map<String, ?> saslProps = getSaslProperties(attributeMap);
-                            final String[] clientMechs = getClientMechanisms(attributeMap, saslProps);
-                            final String authorizationId = getAuthorizationId(attributeMap, protocolContext);
-                            final SaslClient saslClient = Sasl.createSaslClient(clientMechs, authorizationId, "jrpp", remoteName, saslProps, callbackHandler);
-                            final SaslClientFilter saslClientFilter = getSaslClientFilter();
-                            saslClientFilter.setSaslClient(ioSession, saslClient);
+                            sendAuthRequest();
                             state.requireTransition(State.AWAITING_SERVER_VERSION, State.AWAITING_SERVER_CHALLENGE);
                             return;
                         }
@@ -696,9 +717,10 @@
                                     state.requireTransition(State.AWAITING_CLIENT_RESPONSE, State.UP);
                                 }
                             } catch (SaslException ex) {
-                                final IoBuffer buffer = newBuffer(60, false);
+                                final IoBuffer buffer = newBuffer(100, true);
                                 final MessageOutput output = protocolContext.getMessageOutput(new IoBufferByteOutput(buffer, ioSession));
                                 write(output, MessageType.AUTH_FAILED);
+                                output.writeUTF("Authentication failed: " + ex.getMessage());
                                 output.commit();
                                 log.info("Client authentication failed (" + ex.getMessage() + ")");
                                 // todo - retry counter - JBREM-907
@@ -725,7 +747,8 @@
                             return;
                         }
                         case AUTH_FAILED: {
-                            log.info("JRPP client rejected authentication");
+                            String reason = input.readUTF();
+                            log.info("JRPP client failed to authenticate: %s", reason);
                             final SaslClientFilter oldClientFilter = getSaslClientFilter();
                             oldClientFilter.destroy();
                             final CallbackHandler callbackHandler = getClientCallbackHandler(attributeMap);
@@ -735,6 +758,8 @@
                             final SaslClient saslClient = Sasl.createSaslClient(clientMechs, authorizationId, "jrpp", remoteName, saslProps, callbackHandler);
                             final SaslClientFilter saslClientFilter = getSaslClientFilter();
                             saslClientFilter.setSaslClient(ioSession, saslClient);
+                            // todo - retry counter - JBREM-907
+                            sendAuthRequest();
                             return;
                         }
                         default: break OUT;




More information about the jboss-remoting-commits mailing list