From 4a235ffeb36db975743e0dc64c5e7b41e0157d25 Mon Sep 17 00:00:00 2001 From: "Stephen D. Huston" Date: Mon, 16 Mar 2009 21:21:54 +0000 Subject: Add PLAIN auth client handling for Windows; fixes QPID-1733 git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk@755008 13f79535-47bb-0310-9956-ffa450edef68 --- qpid/cpp/src/Makefile.am | 1 + qpid/cpp/src/broker.vcproj | 2 +- qpid/cpp/src/client.vcproj | 8 +- qpid/cpp/src/common.vcproj | 2 +- qpid/cpp/src/qmfconsole.vcproj | 2 +- qpid/cpp/src/qpid.sln | 100 ++++++++-------- qpid/cpp/src/qpid/client/windows/SaslFactory.cpp | 139 +++++++++++++++++++++++ qpid/cpp/src/qpidbroker.vcproj | 2 +- 8 files changed, 198 insertions(+), 58 deletions(-) create mode 100644 qpid/cpp/src/qpid/client/windows/SaslFactory.cpp (limited to 'qpid/cpp/src') diff --git a/qpid/cpp/src/Makefile.am b/qpid/cpp/src/Makefile.am index 45dcffc959..7de05645fa 100644 --- a/qpid/cpp/src/Makefile.am +++ b/qpid/cpp/src/Makefile.am @@ -29,6 +29,7 @@ windows_dist = \ client.vcproj \ qmfconsole.vcproj \ protocol_gen.mak \ + qpid/client/windows/SaslFactory.cpp \ qpid/log/windows/SinkOptions.cpp \ qpid/log/windows/SinkOptions.h \ qpid/sys/windows/check.h \ diff --git a/qpid/cpp/src/broker.vcproj b/qpid/cpp/src/broker.vcproj index db76720f38..e4911e0bfc 100644 --- a/qpid/cpp/src/broker.vcproj +++ b/qpid/cpp/src/broker.vcproj @@ -24,7 +24,7 @@ ProjectType="Visual C++" Version="9.00" Name="broker" - ProjectGUID="{09613D48-FECA-1BAD-9D20-8C378F43FDD9}" + ProjectGUID="{09613D48-FECA-1BAD-9D20-8C374564ADCF}" RootNamespace="broker" Keyword="Win32Proj" SignManifests="true" diff --git a/qpid/cpp/src/client.vcproj b/qpid/cpp/src/client.vcproj index 76f4e44a6c..28b7ec73dc 100644 --- a/qpid/cpp/src/client.vcproj +++ b/qpid/cpp/src/client.vcproj @@ -24,7 +24,7 @@ ProjectType="Visual C++" Version="9.00" Name="client" - ProjectGUID="{6961DBA3-FECA-1BAD-F396-8C398F43FDD9}" + ProjectGUID="{6961DBA3-FECA-1BAD-F396-8C394564ADCF}" RootNamespace="client" Keyword="Win32Proj" SignManifests="true" @@ -455,9 +455,6 @@ - - @@ -482,6 +479,9 @@ + + getSecurityLayer(uint16_t maxFrameSize); + private: + ConnectionSettings settings; + std::string mechanism; +}; + +qpid::sys::Mutex SaslFactory::lock; +std::auto_ptr SaslFactory::instance; + +SaslFactory::SaslFactory() +{ +} + +SaslFactory::~SaslFactory() +{ +} + +SaslFactory& SaslFactory::getInstance() +{ + qpid::sys::Mutex::ScopedLock l(lock); + if (!instance.get()) { + instance = std::auto_ptr(new SaslFactory()); + } + return *instance; +} + +std::auto_ptr SaslFactory::create(const ConnectionSettings& settings) +{ + std::auto_ptr sasl(new WindowsSasl(settings)); + return sasl; +} + +namespace { + const std::string ANONYMOUS = "ANONYMOUS"; + const std::string PLAIN = "PLAIN"; +} + +WindowsSasl::WindowsSasl(const ConnectionSettings& s) + : settings(s) +{ +} + +WindowsSasl::~WindowsSasl() +{ +} + +std::string WindowsSasl::start(const std::string& mechanisms) +{ + QPID_LOG(debug, "WindowsSasl::start(" << mechanisms << ")"); + + typedef boost::tokenizer > tokenizer; + boost::char_separator sep(" "); + bool havePlain = false; + bool haveAnon = false; + tokenizer mechs(mechanisms, sep); + for (tokenizer::iterator mech = mechs.begin(); + mech != mechs.end(); + ++mech) { + if (*mech == ANONYMOUS) + haveAnon = true; + else if (*mech == PLAIN) + havePlain = true; + } + if (!haveAnon && !havePlain) + throw InternalErrorException(QPID_MSG("Sasl error: no common mechanism")); + + std::string resp = ""; + if (havePlain) { + mechanism = PLAIN; + resp = ((char)0) + settings.username + ((char)0) + settings.password; + } + else { + mechanism = ANONYMOUS; + } + return resp; +} + +std::string WindowsSasl::step(const std::string& challenge) +{ + // Shouldn't get this for PLAIN... + throw InternalErrorException(QPID_MSG("Sasl step error")); +} + +std::string WindowsSasl::getMechanism() +{ + return mechanism; +} + +std::auto_ptr WindowsSasl::getSecurityLayer(uint16_t maxFrameSize) +{ + return std::auto_ptr(0); +} + +}} // namespace qpid::client diff --git a/qpid/cpp/src/qpidbroker.vcproj b/qpid/cpp/src/qpidbroker.vcproj index 2d2c35051e..c56970edaa 100644 --- a/qpid/cpp/src/qpidbroker.vcproj +++ b/qpid/cpp/src/qpidbroker.vcproj @@ -3,7 +3,7 @@ ProjectType="Visual C++" Version="9.00" Name="qpidbroker" - ProjectGUID="{66213D3E-FECA-1BAD-9D20-8C378F43FDD9}" + ProjectGUID="{66213D3E-FECA-1BAD-9D20-8C374564ADCF}" RootNamespace="qpidbroker" Keyword="Win32Proj" SignManifests="true" -- cgit v1.2.1