@@ -175,17 +175,29 @@ int InitialConnectionHandler::processBlob(
175
175
rc_INVALID_NEGOTIATION_MESSAGE = -1 ,
176
176
};
177
177
178
- bsl::optional<bmqp_ctrlmsg::NegotiationMessage> negotiationMsg;
178
+ bsl::optional<bmqp_ctrlmsg::AuthenticationMessage> authenticationMsg;
179
+ bsl::optional<bmqp_ctrlmsg::NegotiationMessage> negotiationMsg;
179
180
180
181
int rc = decodeInitialConnectionMessage (errorDescription,
181
182
blob,
183
+ &authenticationMsg,
182
184
&negotiationMsg);
183
185
184
- if (rc != 0 ) {
186
+ if (rc != rc_SUCCESS ) {
185
187
return (rc * 10 ) + rc_INVALID_NEGOTIATION_MESSAGE; // RETURN
186
188
}
187
189
188
- if (negotiationMsg.has_value ()) {
190
+ // Authentication or Negotiation based on the type of message received.
191
+ if (authenticationMsg.has_value ()) {
192
+ context->authenticationContext ()->d_authenticationMessage =
193
+ authenticationMsg.value ();
194
+
195
+ rc = d_authenticator_mp->handleAuthenticationOnMsgType (
196
+ errorDescription,
197
+ isContinueRead,
198
+ context->authenticationContext ());
199
+ }
200
+ else if (negotiationMsg.has_value ()) {
189
201
context->negotiationContext ()->d_negotiationMessage =
190
202
negotiationMsg.value ();
191
203
@@ -206,18 +218,21 @@ int InitialConnectionHandler::processBlob(
206
218
}
207
219
208
220
int InitialConnectionHandler::decodeInitialConnectionMessage (
209
- bsl::ostream& errorDescription,
210
- const bdlbb::Blob& blob,
211
- bsl::optional<bmqp_ctrlmsg::NegotiationMessage>* message)
221
+ bsl::ostream& errorDescription,
222
+ const bdlbb::Blob& blob,
223
+ bsl::optional<bmqp_ctrlmsg::AuthenticationMessage>* authenticationMsg,
224
+ bsl::optional<bmqp_ctrlmsg::NegotiationMessage>* negotiationMsg)
212
225
{
213
- BSLS_ASSERT (message);
226
+ BSLS_ASSERT (authenticationMsg);
227
+ BSLS_ASSERT (negotiationMsg);
214
228
215
229
enum RcEnum {
216
230
// Value for the various RC error categories
217
- rc_SUCCESS = 0 ,
218
- rc_INVALID_MESSAGE = -1 ,
219
- rc_NOT_CONTROL_EVENT = -2 ,
220
- rc_INVALID_CONTROL_EVENT = -3
231
+ rc_SUCCESS = 0 ,
232
+ rc_INVALID_MESSAGE = -1 ,
233
+ rc_INVALID_EVENT = -2 ,
234
+ rc_INVALID_AUTHENTICATION_EVENT = -3 ,
235
+ rc_INVALID_CONTROL_EVENT = -4
221
236
};
222
237
223
238
bdlma::LocalSequentialAllocator<2048 > localAllocator (d_allocator_p);
@@ -231,25 +246,41 @@ int InitialConnectionHandler::decodeInitialConnectionMessage(
231
246
return rc_INVALID_MESSAGE; // RETURN
232
247
}
233
248
234
- if (!event.isControlEvent ()) {
235
- errorDescription << " Invalid negotiation message received "
236
- << " (packet is not a ControlEvent):\n "
237
- << bmqu::BlobStartHexDumper (&blob);
238
- return rc_NOT_CONTROL_EVENT; // RETURN
239
- }
240
-
241
- bmqp_ctrlmsg::NegotiationMessage negotiationMessage;
242
-
243
- int rc = event.loadControlEvent (&negotiationMessage);
249
+ bmqp_ctrlmsg::AuthenticationMessage authenticaionMessage;
250
+ bmqp_ctrlmsg::NegotiationMessage negotiationMessage;
251
+
252
+ if (event.isAuthenticationEvent ()) {
253
+ const int rc = event.loadAuthenticationEvent (&authenticaionMessage);
254
+ if (rc != 0 ) {
255
+ BALL_LOG_ERROR
256
+ << " Invalid response from broker [reason: 'authentication "
257
+ " event is not an AuthenticationMessage', rc: "
258
+ << rc << " ]: " << event;
259
+ return rc_INVALID_AUTHENTICATION_EVENT; // RETURN
260
+ }
244
261
245
- if (rc != 0 ) {
246
- errorDescription << " Invalid negotiation message received (failed "
247
- << " decoding ControlEvent): [rc: " << rc << " ]:\n "
248
- << bmqu::BlobStartHexDumper (&blob);
249
- return rc_INVALID_CONTROL_EVENT; // RETURN
262
+ *authenticationMsg = authenticaionMessage;
250
263
}
264
+ else if (event.isControlEvent ()) {
265
+ const int rc = event.loadControlEvent (&negotiationMessage);
266
+ if (rc != 0 ) {
267
+ BALL_LOG_ERROR
268
+ << " Invalid response from broker [reason: 'authentication "
269
+ " event is not an AuthenticationMessage', rc: "
270
+ << rc << " ]: " << event;
271
+
272
+ return rc_INVALID_CONTROL_EVENT; // RETURN
273
+ }
251
274
252
- *message = negotiationMessage;
275
+ *negotiationMsg = negotiationMessage;
276
+ }
277
+ else {
278
+ errorDescription
279
+ << " Invalid initial connection message received "
280
+ << " (packet is not an AuthenticationEvent or ControlEvent):\n "
281
+ << bmqu::BlobStartHexDumper (&blob);
282
+ return rc_INVALID_EVENT; // RETURN
283
+ }
253
284
254
285
return rc_SUCCESS;
255
286
}
@@ -297,9 +328,11 @@ void InitialConnectionHandler::complete(
297
328
}
298
329
299
330
InitialConnectionHandler::InitialConnectionHandler (
300
- bslma::ManagedPtr<mqbnet::Negotiator>& negotiator,
301
- bslma::Allocator* allocator)
302
- : d_negotiator_mp(negotiator)
331
+ bslma::ManagedPtr<mqbnet::Authenticator>& authenticator,
332
+ bslma::ManagedPtr<mqbnet::Negotiator>& negotiator,
333
+ bslma::Allocator* allocator)
334
+ : d_authenticator_mp(authenticator)
335
+ , d_negotiator_mp(negotiator)
303
336
, d_allocator_p(allocator)
304
337
{
305
338
}
@@ -308,9 +341,21 @@ InitialConnectionHandler::~InitialConnectionHandler()
308
341
{
309
342
}
310
343
311
- void InitialConnectionHandler::handleInitialConnection (
344
+ void InitialConnectionHandler::setupContext (
312
345
const InitialConnectionContextSp& context)
313
346
{
347
+ // Create an AuthenticationContext for that connection
348
+ bsl::shared_ptr<mqbnet::AuthenticationContext> authenticationContext;
349
+ authenticationContext.createInplace (d_allocator_p);
350
+
351
+ authenticationContext->d_initialConnectionContext_p = context.get ();
352
+ authenticationContext->d_isReversed = false ;
353
+ authenticationContext->d_clusterName = " " ;
354
+ authenticationContext->d_connectionType =
355
+ mqbnet::ConnectionType::e_UNKNOWN;
356
+
357
+ context->setAuthenticationContext (authenticationContext);
358
+
314
359
// Create an NegotiationContext for that connection
315
360
bsl::shared_ptr<mqbnet::NegotiationContext> negotiationContext;
316
361
negotiationContext.createInplace (d_allocator_p);
@@ -321,7 +366,11 @@ void InitialConnectionHandler::handleInitialConnection(
321
366
negotiationContext->d_connectionType = mqbnet::ConnectionType::e_UNKNOWN;
322
367
323
368
context->setNegotiationContext (negotiationContext);
369
+ }
324
370
371
+ void InitialConnectionHandler::handleConnectionFlow (
372
+ const InitialConnectionContextSp& context)
373
+ {
325
374
// Reading for inbound request or continue to read
326
375
// after sending a request ourselves
327
376
@@ -363,5 +412,12 @@ void InitialConnectionHandler::handleInitialConnection(
363
412
guard.release ();
364
413
}
365
414
415
+ void InitialConnectionHandler::handleInitialConnection (
416
+ const InitialConnectionContextSp& context)
417
+ {
418
+ setupContext (context);
419
+ handleConnectionFlow (context);
420
+ }
421
+
366
422
} // close package namespace
367
423
} // close enterprise namespace
0 commit comments