3030
3131// BDE
3232#include < ball_log.h>
33+ #include < bdlb_string.h>
3334#include < bsl_string.h>
3435#include < bsl_string_view.h>
3536#include < bsl_unordered_set.h>
@@ -41,6 +42,14 @@ namespace {
4142
4243typedef bsl::unordered_set<mqbplug::PluginFactory*> PluginFactories;
4344
45+ inline bsl::string normalizeMechanism (bsl::string_view mech,
46+ bslma::Allocator* allocator = 0 )
47+ {
48+ bsl::string out (mech.begin (), mech.end (), allocator);
49+ bdlb::String::toUpper (&out);
50+ return out;
51+ }
52+
4453} // close unnamed namespace
4554
4655// ------------------------------
@@ -58,17 +67,19 @@ AuthenticationController::AuthenticationController(
5867
5968int AuthenticationController::start (bsl::ostream& errorDescription)
6069{
61- // PRECONDITIONS
62- BSLS_ASSERT_OPT (!d_isStarted &&
63- " start() can only be called once on this object" );
64-
6570 enum RcEnum {
6671 // Enum for the various RC error categories
6772 rc_SUCCESS = 0 ,
68- rc_DUPLICATE_MECHANISM = -1 ,
69- rc_INVALID_CONFIG = -2
73+ rc_ALREADY_STARTED = -1 ,
74+ rc_DUPLICATE_MECHANISM = -2 ,
75+ rc_INVALID_CONFIG = -3
7076 };
7177
78+ if (d_isStarted) {
79+ errorDescription << " start() can only be called once on this object" ;
80+ return rc_ALREADY_STARTED;
81+ }
82+
7283 bmqu::MemOutStream errorStream (d_allocator_p);
7384
7485 BALL_LOG_INFO << " Starting AuthenticationController" ;
@@ -118,9 +129,12 @@ int AuthenticationController::start(bsl::ostream& errorDescription)
118129 dynamic_cast <mqbplug::AuthenticatorPluginFactory*>(*factoryIt);
119130 AuthenticatorMp authenticator = factory->create (d_allocator_p);
120131
132+ const bsl::string normMech =
133+ normalizeMechanism (authenticator->mechanism (), d_allocator_p);
134+
121135 // Check if there's an authenticator with duplicate mechanism
122136 AuthenticatorMap::const_iterator cit = d_authenticators.find (
123- authenticator-> mechanism () );
137+ normMech );
124138 if (cit != d_authenticators.cend ()) {
125139 errorDescription << " Attempting to create duplicate "
126140 " authenticator with mechanism '"
@@ -141,7 +155,7 @@ int AuthenticationController::start(bsl::ostream& errorDescription)
141155
142156 // Add the authenticator into the collection
143157 d_authenticators.emplace (
144- authenticator-> mechanism () ,
158+ normMech ,
145159 bslmf::MovableRefUtil::move (authenticator));
146160 }
147161
@@ -167,14 +181,15 @@ int AuthenticationController::start(bsl::ostream& errorDescription)
167181 }
168182
169183 // Add the authenticator into the collection
184+ const bsl::string normMech =
185+ normalizeMechanism (authenticator->mechanism (), d_allocator_p);
170186 d_authenticators.emplace (
171- authenticator-> mechanism () ,
187+ normMech ,
172188 bslmf::MovableRefUtil::move (authenticator));
173189 }
174190 }
175191
176192 d_isStarted = true ;
177-
178193 return rc_SUCCESS;
179194}
180195
@@ -214,7 +229,8 @@ int AuthenticationController::authenticate(
214229 int rc = rc_SUCCESS;
215230 bmqu::MemOutStream errorStream (d_allocator_p);
216231
217- AuthenticatorMap::const_iterator cit = d_authenticators.find (mechanism);
232+ const bsl::string normMech = normalizeMechanism (mechanism, d_allocator_p);
233+ AuthenticatorMap::const_iterator cit = d_authenticators.find (normMech);
218234 if (cit != d_authenticators.cend ()) {
219235 const AuthenticatorMp& authenticator = cit->second ;
220236 BALL_LOG_DEBUG << " AuthenticationController: "
0 commit comments