Author: rajith
Date: Tue Jan 12 23:14:11 2010
New Revision: 898570

URL: http://svn.apache.org/viewvc?rev=898570&view=rev
Log:
This is a fix for QPID-2339

Modified:
    
qpid/trunk/qpid/java/common/src/main/java/org/apache/qpid/transport/ClientDelegate.java

Modified: 
qpid/trunk/qpid/java/common/src/main/java/org/apache/qpid/transport/ClientDelegate.java
URL: 
http://svn.apache.org/viewvc/qpid/trunk/qpid/java/common/src/main/java/org/apache/qpid/transport/ClientDelegate.java?rev=898570&r1=898569&r2=898570&view=diff
==============================================================================
--- 
qpid/trunk/qpid/java/common/src/main/java/org/apache/qpid/transport/ClientDelegate.java
 (original)
+++ 
qpid/trunk/qpid/java/common/src/main/java/org/apache/qpid/transport/ClientDelegate.java
 Tue Jan 12 23:14:11 2010
@@ -24,6 +24,8 @@
 
 import java.lang.management.ManagementFactory;
 import java.lang.management.RuntimeMXBean;
+import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
@@ -62,7 +64,7 @@
     private String vhost;
     private String username;
     private String password;
-    private String[] saslMechs;
+    private List<String> clientMechs;
     private String protocol;
     private String serverName;
     
@@ -71,7 +73,7 @@
         this.vhost = vhost;
         this.username = username;
         this.password = password;
-        this.saslMechs = saslMechs.split(" ");
+        this.clientMechs = Arrays.asList(saslMechs.split(" "));
         
         // Looks kinda of silly but the Sun SASL Kerberos client uses the 
         // protocol + servername as the service key.
@@ -96,24 +98,41 @@
         clientProperties.put("qpid.client_process",
                 System.getProperty("qpid.client_process","Qpid Java Client"));
         
-        List<Object> mechanisms = start.getMechanisms();
-        if (mechanisms == null || mechanisms.isEmpty())
+        List<Object> brokerMechs = start.getMechanisms();
+        if (brokerMechs == null || brokerMechs.isEmpty())
         {
             conn.connectionStartOk
                 (clientProperties, null, null, conn.getLocale());
             return;
         }
-
-        String[] mechs = new String[mechanisms.size()];
-        mechanisms.toArray(mechs);
-
+        
+        List<String> choosenMechs = new ArrayList<String>();
+        for (String mech:clientMechs)
+        {
+            if (brokerMechs.contains(mech)) 
+            {
+                choosenMechs.add(mech);
+            }
+        }
+        
+        if (choosenMechs.size() == 0)
+        {
+            conn.exception(new ConnectionException("The following SASL 
mechanisms " +
+                    clientMechs.toString()  + 
+                    " specified by the client are not supported by the 
broker"));
+            return;
+        }
+        
+        String[] mechs = new String[choosenMechs.size()];
+        choosenMechs.toArray(mechs); 
+        
         try
         {
             UsernamePasswordCallbackHandler handler =
                 new UsernamePasswordCallbackHandler();
             handler.initialise(username, password);
             SaslClient sc = Sasl.createSaslClient
-                (saslMechs, null, protocol, serverName, null, handler);
+                (mechs, null, protocol, serverName, null, handler);
             conn.setSaslClient(sc);
 
             byte[] response = sc.hasInitialResponse() ?



---------------------------------------------------------------------
Apache Qpid - AMQP Messaging Implementation
Project:      http://qpid.apache.org
Use/Interact: mailto:[email protected]

Reply via email to