Author: gsim
Date: Fri Jul 12 19:27:43 2013
New Revision: 1502664

URL: http://svn.apache.org/r1502664
Log:
QPID-4407: verify mechanism used when no external SASL library is available

Modified:
    qpid/trunk/qpid/cpp/src/qpid/client/ConnectionHandler.cpp

Modified: qpid/trunk/qpid/cpp/src/qpid/client/ConnectionHandler.cpp
URL: 
http://svn.apache.org/viewvc/qpid/trunk/qpid/cpp/src/qpid/client/ConnectionHandler.cpp?rev=1502664&r1=1502663&r2=1502664&view=diff
==============================================================================
--- qpid/trunk/qpid/cpp/src/qpid/client/ConnectionHandler.cpp (original)
+++ qpid/trunk/qpid/cpp/src/qpid/client/ConnectionHandler.cpp Fri Jul 12 
19:27:43 2013
@@ -50,6 +50,7 @@ using qpid::sys::Mutex;
 namespace {
 const std::string OK("OK");
 const std::string PLAIN("PLAIN");
+const std::string ANONYMOUS("ANONYMOUS");
 const std::string en_US("en_US");
 
 const std::string INVALID_STATE_START("start received in invalid state");
@@ -244,6 +245,7 @@ void ConnectionHandler::start(const Fiel
 
     std::vector<std::string> mechlist;
     mechlist.reserve(mechanisms.size());
+
     if (mechanism.empty()) {
         //mechlist is simply what the server offers
         std::transform(mechanisms.begin(), mechanisms.end(), 
std::back_inserter(mechlist), Array::get<std::string, Array::ValuePtr>);
@@ -273,9 +275,25 @@ void ConnectionHandler::start(const Fiel
             proxy.send(body);
         }
     } else {
-        //TODO: verify that desired mechanism and locale are supported
-        std::string response = ((char)0) + username + ((char)0) + password;
-        proxy.startOk(properties, mechanism, response, locale);
+        bool haveAnonymous(false);
+        bool havePlain(false);
+        for (std::vector<std::string>::const_iterator i = mechlist.begin(); i 
!= mechlist.end(); ++i) {
+            if (*i == ANONYMOUS) {
+                haveAnonymous = true;
+                break;
+            } else if (*i == PLAIN) {
+                havePlain = true;
+            }
+        }
+        if (haveAnonymous && (mechanism.empty() || mechanism.find(ANONYMOUS) 
!= std::string::npos)) {
+            proxy.startOk(properties, ANONYMOUS, username, locale);
+        } else if (havePlain && (mechanism.empty() || mechanism.find(PLAIN) 
!=std::string::npos)) {
+            std::string response = ((char)0) + username + ((char)0) + password;
+            proxy.startOk(properties, PLAIN, response, locale);
+        } else {
+            if (!mechanism.empty()) throw Exception(QPID_MSG("Desired 
mechanism(s) not valid: " << mechanism << "; client supports PLAIN or 
ANONYMOUS, broker supports: " << join(mechlist)));
+            throw Exception(QPID_MSG("No valid mechanism; client supports 
PLAIN or ANONYMOUS, broker supports: " << join(mechlist)));
+        }
     }
 }
 



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@qpid.apache.org
For additional commands, e-mail: commits-h...@qpid.apache.org

Reply via email to