Skip to content

Commit da77f6c

Browse files
committed
address feedback: more grammar and format
Signed-off-by: Emelia Lei <[email protected]>
1 parent 7eb632a commit da77f6c

25 files changed

+400
-142
lines changed

src/groups/mqb/mqba/mqba_authenticator.cpp

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@
4343
#include <bmqp_protocol.h>
4444
#include <bmqp_schemaeventbuilder.h>
4545
#include <bmqu_memoutstream.h>
46-
#include <bslmt_threadutil.h>
4746

4847
// BDE
4948
#include <ball_log.h>
@@ -58,6 +57,7 @@
5857
#include <bsl_string_view.h>
5958
#include <bsl_vector.h>
6059
#include <bsla_annotations.h>
60+
#include <bslmt_threadutil.h>
6161
#include <bsls_timeinterval.h>
6262

6363
namespace BloombergLP {
@@ -236,9 +236,9 @@ void Authenticator::authenticate(
236236
channel,
237237
context->authenticationContext());
238238

239-
// Return code processRc is rc_SUCCESS even when authentication fails,
240-
// since we still need to continue sending the AuthenticationResponse back
241-
// to the client.
239+
// Return code processRc is rc_SUCCESS even when plugin authentication
240+
// fails, since we still need to continue sending the
241+
// AuthenticationResponse back to the client.
242242
if (processRc != rc_SUCCESS) {
243243
rc = (processRc * 10) + rc_PROCESS_AUTHENTICATION_FAILED;
244244
error = processErrStream.str();
@@ -433,22 +433,22 @@ Authenticator::Authenticator(
433433
BlobSpPool* blobSpPool,
434434
bdlmt::EventScheduler* scheduler,
435435
bslma::Allocator* allocator)
436-
: d_threadPool(bmqsys::ThreadUtil::defaultAttributes(),
436+
: d_allocator_p(allocator)
437+
, d_authnController_p(authnController)
438+
, d_threadPool(bmqsys::ThreadUtil::defaultAttributes(),
437439
k_MIN_THREADS, // min threads
438440
k_MAX_THREADS, // max threads
439441
bsls::TimeInterval(120).totalMilliseconds(), // idle time
440442
allocator)
441-
, d_authnController_p(authnController)
442443
, d_blobSpPool_p(blobSpPool)
443444
, d_scheduler_p(scheduler)
444445
, d_isStarted(false)
445-
, d_allocator_p(allocator)
446446
{
447447
// PRECONDITIONS
448+
BSLS_ASSERT_SAFE(d_allocator_p);
448449
BSLS_ASSERT_SAFE(d_authnController_p);
449450
BSLS_ASSERT_SAFE(d_blobSpPool_p);
450451
BSLS_ASSERT_SAFE(d_scheduler_p);
451-
BSLS_ASSERT_SAFE(d_allocator_p);
452452
}
453453

454454
/// Destructor
@@ -461,9 +461,10 @@ Authenticator::~Authenticator()
461461

462462
int Authenticator::start(bsl::ostream& errorDescription)
463463
{
464-
// PRECONDITIONS
465-
BSLS_ASSERT_OPT(!d_isStarted &&
466-
"start() can only be called once on this object");
464+
if (d_isStarted) {
465+
errorDescription << "start() can only be called once on this object";
466+
return -1;
467+
}
467468

468469
BALL_LOG_INFO << "Starting Authenticator";
469470

src/groups/mqb/mqba/mqba_authenticator.h

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ namespace mqba {
7575
class Authenticator : public mqbnet::Authenticator {
7676
private:
7777
// CLASS-SCOPE CATEGORY
78-
BALL_LOG_SET_CLASS_CATEGORY("MQBNET.AUTHENTICATIONCONTEXT");
78+
BALL_LOG_SET_CLASS_CATEGORY("MQBA.AUTHENTICATOR");
7979

8080
public:
8181
// TYPES
@@ -101,12 +101,15 @@ class Authenticator : public mqbnet::Authenticator {
101101
private:
102102
// DATA
103103

104-
/// Thread pool to run authentication and reauthentication tasks.
105-
bdlmt::ThreadPool d_threadPool;
104+
/// Allocator to use.
105+
bslma::Allocator* d_allocator_p;
106106

107107
/// Authentication Controller.
108108
mqbauthn::AuthenticationController* d_authnController_p;
109109

110+
/// Thread pool to run authentication and reauthentication tasks.
111+
bdlmt::ThreadPool d_threadPool;
112+
110113
BlobSpPool* d_blobSpPool_p;
111114

112115
/// Used to track the duration of a valid authenticated connection.
@@ -117,9 +120,6 @@ class Authenticator : public mqbnet::Authenticator {
117120
/// True if this component is started.
118121
bool d_isStarted;
119122

120-
/// Allocator to use.
121-
bslma::Allocator* d_allocator_p;
122-
123123
private:
124124
// NOT IMPLEMENTED
125125

@@ -181,7 +181,7 @@ class Authenticator : public mqbnet::Authenticator {
181181
const bsl::shared_ptr<bmqio::Channel>& channel);
182182

183183
/// Reauthenticate the connection using the `AuthenticationMessage`
184-
/// stored in `context`. If re-authentication fails, invoke
184+
/// stored in `context`. If reauthentication fails, invoke
185185
/// `initialConnectionCompleteCb` to close the `channel`. Also, update the
186186
/// state of `context` as appropriate.
187187
void reauthenticate(const AuthenticationContextSp& context,
@@ -244,7 +244,7 @@ class Authenticator : public mqbnet::Authenticator {
244244
int authenticationOutbound(const AuthenticationContextSp& context)
245245
BSLS_KEYWORD_OVERRIDE;
246246

247-
/// Schedule a re-authentication job in the thread pool using the
247+
/// Schedule a reauthentication job in the thread pool using the
248248
/// specified `context` and `channel`. Return 0 on success, or a
249249
/// non-zero error code and populate the specified `errorDescription`
250250
/// with a description of the error otherwise.

src/groups/mqb/mqba/mqba_clientsession.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -593,7 +593,8 @@ class ClientSession : public mqbnet::Session,
593593

594594
/// Process the specified `event` received from the optionally specified
595595
/// `source` node. Note that this method is the entry point for all
596-
/// incoming events coming from the remote peer.
596+
/// incoming events coming from the remote peer. The behavior is undefined
597+
/// unless `event` is not `AuthenticationEvent`.
597598
void processEvent(const bmqp::Event& event,
598599
mqbnet::ClusterNode* source = 0) BSLS_KEYWORD_OVERRIDE;
599600

src/groups/mqb/mqba/mqba_sessionnegotiator.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
/// Thread Safety {#mqba_sessionnegotiator_thread}
3131
/// =============
3232
/// This component is held by `InitialConnectionContext`, and its functions
33-
/// are called inly from there. It is not thread safe.
33+
/// are called only from there. It is not thread safe.
3434

3535
// MQB
3636
#include <mqbconfm_messages.h>

src/groups/mqb/mqbauthn/mqbauthn_anonpassauthenticator.cpp

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,9 @@ AnonPassAuthenticationResult::lifetimeMs() const
6767
AnonPassAuthenticator::AnonPassAuthenticator(
6868
const mqbcfg::AuthenticatorPluginConfig* config,
6969
bslma::Allocator* allocator)
70-
: d_authenticatorConfig_p(config)
70+
: d_allocator_p(allocator)
71+
, d_authenticatorConfig_p(config)
7172
, d_isStarted(false)
72-
, d_allocator_p(allocator)
7373
{
7474
if (!config) {
7575
// No config is provided for an anonymous authenticator.
@@ -110,11 +110,12 @@ int AnonPassAuthenticator::authenticate(
110110
return 0;
111111
}
112112

113-
int AnonPassAuthenticator::start(BSLA_UNUSED bsl::ostream& errorDescription)
113+
int AnonPassAuthenticator::start(bsl::ostream& errorDescription)
114114
{
115-
// PRECONDITIONS
116-
BSLS_ASSERT_OPT(!d_isStarted &&
117-
"start() can only be called once on this object");
115+
if (d_isStarted) {
116+
errorDescription << "start() can only be called once on this object";
117+
return -1;
118+
}
118119

119120
d_isStarted = true;
120121

src/groups/mqb/mqbauthn/mqbauthn_anonpassauthenticator.h

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,10 @@
2121
///
2222
/// @brief Provide an default anonymous pass authenticator plugin.
2323
///
24-
/// @bbref{mqbauthn::AnonPassAuthenticator} provides an authenticator plugin
25-
/// that always authenticates successfully, regardless of the input provided.
26-
/// It's used as a default authenticator for the anonymous credential when no
27-
/// other authenticator is configured.
24+
/// @bbref{mqbauthn::AnonPassAuthenticator} provides a built-in authenticator
25+
/// plugin that always authenticates successfully, regardless of the input
26+
/// provided. It's used as a default authenticator for the anonymous credential
27+
/// when no other authenticator is configured.
2828
/// @bbref{mqbauthn::AnonPassAuthenticationResult} and
2929
/// @bbref{mqbauthn::AnonPassAuthenticatorPluginFactory} are the corresponding
3030
/// result and factory classes for the authenticator plugin.
@@ -99,12 +99,12 @@ class AnonPassAuthenticator : public mqbplug::Authenticator {
9999
BALL_LOG_SET_CLASS_CATEGORY("MQBAUTHN.ANONPASSAUTHENTICATOR");
100100

101101
// DATA
102+
bslma::Allocator* d_allocator_p;
103+
102104
const mqbcfg::AuthenticatorPluginConfig* d_authenticatorConfig_p;
103105

104106
bool d_isStarted;
105107

106-
bslma::Allocator* d_allocator_p;
107-
108108
private:
109109
// NOT IMPLEMENTED
110110
AnonPassAuthenticator(const AnonPassAuthenticator& other)
@@ -114,7 +114,8 @@ class AnonPassAuthenticator : public mqbplug::Authenticator {
114114

115115
public:
116116
// TRAITS
117-
BSLMF_NESTED_TRAIT_DECLARATION(Authenticator, bslma::UsesBslmaAllocator)
117+
BSLMF_NESTED_TRAIT_DECLARATION(AnonPassAuthenticator,
118+
bslma::UsesBslmaAllocator)
118119

119120
// CREATORS
120121

src/groups/mqb/mqbauthn/mqbauthn_anonpasspluginlibrary.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@
1919

2020
/// @file mqbauthn_anonpasspluginlibrary.h
2121
///
22-
/// @brief Provide library of anonymous pass authenticator plugin for broker.
22+
/// @brief Provide library of anonymous pass built-in authenticator plugin for
23+
/// the broker.
2324
///
2425
/// @bbref{mqbauthn::PluginLibrary} provides the definition for the
2526
/// 'PluginLibrary' class, which represents and publishes anonymous pass

src/groups/mqb/mqbauthn/mqbauthn_authenticationcontroller.cpp

Lines changed: 27 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
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

4243
typedef 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

5968
int 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: "

src/groups/mqb/mqbauthn/mqbauthn_authenticationcontroller.h

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,17 @@
1717
#ifndef INCLUDED_MQBAUTHN_AUTHENTICATIONCONTROLLER
1818
#define INCLUDED_MQBAUTHN_AUTHENTICATIONCONTROLLER
1919

20+
/// @file mqbauthn_authenticationcontroller.h
21+
///
22+
/// @brief Provide a small utility class that orchestrates authenticator
23+
/// plugins.
24+
///
25+
/// @bbref{AuthenticationController} provides a small utility class that
26+
/// orchestrates authenticator plugins. Responsibilities include creating and
27+
/// holding plugin instances, tracking an optional anonymous credential, and
28+
/// offering start/stop and authenticate operations used by higher-level
29+
/// components.
30+
2031
// MQB
2132
#include <mqbcfg_messages.h>
2233
#include <mqbplug_authenticator.h>
@@ -49,14 +60,18 @@ class AuthenticationController {
4960

5061
// DATA
5162

52-
/// Registered authenticators
53-
/// Mapping an authentication mechanism to a mqbplug::Authenticator
63+
/// Registered authenticator plugins.
64+
/// Mapping an authentication mechanism to a mqbplug::Authenticator.
65+
/// The mechanisms are stored in upper case to make the lookup
66+
/// case-insensitive.
5467
AuthenticatorMap d_authenticators;
5568

56-
/// Anonymous credential
69+
/// Anonymous credential. If set, this credential will be used for
70+
/// authentication when the client does not provide any credential.
71+
/// Default anonymous credential will be used if not set.
5772
bsl::optional<mqbcfg::Credential> d_anonymousCredential;
5873

59-
/// Used to instantiate 'Authenticator'
74+
/// Used to instantiate Authenticator
6075
/// plugins at start-time.
6176
mqbplug::PluginManager* d_pluginManager_p;
6277

0 commit comments

Comments
 (0)