summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGordon Sim <gsim@apache.org>2015-05-29 12:25:00 +0000
committerGordon Sim <gsim@apache.org>2015-05-29 12:25:00 +0000
commit2e1da6896535a662741195ad86288dc367c28140 (patch)
tree07197f1f2c908fd13ae4c2bf431de335a420da48
parentd7ff17002e8f865e1270fb3362b941750dcda296 (diff)
downloadqpid-python-2e1da6896535a662741195ad86288dc367c28140.tar.gz
QPID-6559: add PLAIN support for NullSaslClient
git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk/qpid@1682440 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r--cpp/src/qpid/NullSaslClient.cpp22
-rw-r--r--cpp/src/qpid/NullSaslClient.h4
-rw-r--r--cpp/src/qpid/SaslFactory.cpp4
3 files changed, 22 insertions, 8 deletions
diff --git a/cpp/src/qpid/NullSaslClient.cpp b/cpp/src/qpid/NullSaslClient.cpp
index d1f2706f50..30c2330553 100644
--- a/cpp/src/qpid/NullSaslClient.cpp
+++ b/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/cpp/src/qpid/NullSaslClient.h b/cpp/src/qpid/NullSaslClient.h
index b0a63a8ecb..26882c6c20 100644
--- a/cpp/src/qpid/NullSaslClient.h
+++ b/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/cpp/src/qpid/SaslFactory.cpp b/cpp/src/qpid/SaslFactory.cpp
index f38c592ad5..7bfc510936 100644
--- a/cpp/src/qpid/SaslFactory.cpp
+++ b/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;
}