diff options
author | Gordon Sim <gsim@apache.org> | 2015-05-29 12:25:00 +0000 |
---|---|---|
committer | Gordon Sim <gsim@apache.org> | 2015-05-29 12:25:00 +0000 |
commit | 3d4a32246131df4bcc77e95c1194b07fd2951461 (patch) | |
tree | a908021f0790a400f1a3939af47cf799704af647 | |
parent | ca32b06c0c0a969c0a4622809be280fed75e8137 (diff) | |
download | qpid-python-3d4a32246131df4bcc77e95c1194b07fd2951461.tar.gz |
QPID-6559: add PLAIN support for NullSaslClient
git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk@1682440 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r-- | qpid/cpp/src/qpid/NullSaslClient.cpp | 22 | ||||
-rw-r--r-- | qpid/cpp/src/qpid/NullSaslClient.h | 4 | ||||
-rw-r--r-- | qpid/cpp/src/qpid/SaslFactory.cpp | 4 |
3 files changed, 22 insertions, 8 deletions
diff --git a/qpid/cpp/src/qpid/NullSaslClient.cpp b/qpid/cpp/src/qpid/NullSaslClient.cpp index d1f2706f50..30c2330553 100644 --- a/qpid/cpp/src/qpid/NullSaslClient.cpp +++ b/qpid/cpp/src/qpid/NullSaslClient.cpp @@ -25,15 +25,25 @@ namespace qpid { namespace { const std::string ANONYMOUS("ANONYMOUS"); +const std::string PLAIN("PLAIN"); } -bool NullSaslClient::start(const std::string& mechanisms, std::string&, - const qpid::sys::SecuritySettings*) +NullSaslClient::NullSaslClient(const std::string& u, const std::string& p) : username(u), password(p) {} + +bool NullSaslClient::start(const std::string& mechanisms, std::string& response, + const qpid::sys::SecuritySettings*) { - if (mechanisms.find(ANONYMOUS) == std::string::npos) { + if (!username.empty() && !password.empty() && mechanisms.find(PLAIN) != std::string::npos) { + mechanism = PLAIN; + response = ((char)0) + username + ((char)0) + password; + } else if (mechanisms.find(ANONYMOUS) != std::string::npos) { + mechanism = ANONYMOUS; + const char* u = username.empty() ? ANONYMOUS.c_str() : username.c_str(); + response = ((char)0) + u; + } else { throw qpid::Exception("No suitable mechanism!"); } - return false; + return true; } std::string NullSaslClient::step(const std::string&) { @@ -41,11 +51,11 @@ std::string NullSaslClient::step(const std::string&) } std::string NullSaslClient::getMechanism() { - return ANONYMOUS; + return mechanism; } std::string NullSaslClient::getUserId() { - return ANONYMOUS; + return username.empty() ? ANONYMOUS : username; } std::auto_ptr<qpid::sys::SecurityLayer> NullSaslClient::getSecurityLayer(uint16_t) { diff --git a/qpid/cpp/src/qpid/NullSaslClient.h b/qpid/cpp/src/qpid/NullSaslClient.h index b0a63a8ecb..26882c6c20 100644 --- a/qpid/cpp/src/qpid/NullSaslClient.h +++ b/qpid/cpp/src/qpid/NullSaslClient.h @@ -28,6 +28,7 @@ namespace qpid { class NullSaslClient : public Sasl { public: + NullSaslClient(const std::string& username, const std::string& password); bool start(const std::string& mechanisms, std::string& response, const qpid::sys::SecuritySettings* externalSecuritySettings = 0); std::string step(const std::string& challenge); @@ -35,6 +36,9 @@ class NullSaslClient : public Sasl std::string getUserId(); std::auto_ptr<qpid::sys::SecurityLayer> getSecurityLayer(uint16_t maxFrameSize); private: + const std::string username; + const std::string password; + std::string mechanism; }; } // namespace qpid diff --git a/qpid/cpp/src/qpid/SaslFactory.cpp b/qpid/cpp/src/qpid/SaslFactory.cpp index f38c592ad5..7bfc510936 100644 --- a/qpid/cpp/src/qpid/SaslFactory.cpp +++ b/qpid/cpp/src/qpid/SaslFactory.cpp @@ -47,9 +47,9 @@ SaslFactory& SaslFactory::getInstance() return *instance; } -std::auto_ptr<Sasl> SaslFactory::create( const std::string &, const std::string &, const std::string &, const std::string &, int, int, bool ) +std::auto_ptr<Sasl> SaslFactory::create(const std::string& username, const std::string& password, const std::string&, const std::string&, int, int, bool) { - std::auto_ptr<Sasl> client(new NullSaslClient); + std::auto_ptr<Sasl> client(new NullSaslClient(username, password)); return client; } |