diff options
| author | Gordon Sim <gsim@apache.org> | 2013-07-12 19:27:43 +0000 |
|---|---|---|
| committer | Gordon Sim <gsim@apache.org> | 2013-07-12 19:27:43 +0000 |
| commit | 6139c256a5a98fd92074e518f07b86714987564b (patch) | |
| tree | ccf0e24afa3acef719819435af6fe3e92115a795 /qpid/cpp | |
| parent | 19d1f6373f1f797f915b852a5f398ded59ce8a44 (diff) | |
| download | qpid-python-6139c256a5a98fd92074e518f07b86714987564b.tar.gz | |
QPID-4407: verify mechanism used when no external SASL library is available
git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk@1502664 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'qpid/cpp')
| -rw-r--r-- | qpid/cpp/src/qpid/client/ConnectionHandler.cpp | 24 |
1 files changed, 21 insertions, 3 deletions
diff --git a/qpid/cpp/src/qpid/client/ConnectionHandler.cpp b/qpid/cpp/src/qpid/client/ConnectionHandler.cpp index 4f88cb97ee..3ee3f1cd40 100644 --- a/qpid/cpp/src/qpid/client/ConnectionHandler.cpp +++ b/qpid/cpp/src/qpid/client/ConnectionHandler.cpp @@ -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 FieldTable& /*serverProps*/, const Array& me 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 FieldTable& /*serverProps*/, const Array& me 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))); + } } } |
