2828// MQB
2929#include < mqbblp_clustercatalog.h>
3030#include < mqbnet_authenticationcontext.h>
31+ #include < mqbnet_initialconnectioncontext.h>
3132
3233// BMQ
3334#include < bmqio_status.h>
@@ -57,26 +58,43 @@ const int k_AUTHENTICATION_READTIMEOUT = 3 * 60; // 3 minutes
5758// -------------------
5859
5960int Authenticator::onAuthenticationRequest (
60- bsl::ostream& errorDescription,
61- const AuthenticationContextSp& context)
61+ bsl::ostream& errorDescription,
62+ const bmqp_ctrlmsg::AuthenticationMessage& authenticationMsg,
63+ const InitialConnectionContextSp& context)
6264{
6365 // PRECONDITIONS
64- BSLS_ASSERT_SAFE (
65- context->authenticationMessage ().isAuthenticateRequestValue ());
66- BSLS_ASSERT_SAFE (context->initialConnectionContext ()->isIncoming ());
67- BSLS_ASSERT_SAFE (!context->isReversed ()); // not supported for now
66+ BSLS_ASSERT_SAFE (authenticationMsg.isAuthenticateRequestValue ());
67+ BSLS_ASSERT_SAFE (context->isIncoming ());
6868
6969 const bmqp_ctrlmsg::AuthenticateRequest& authenticateRequest =
70- context-> authenticationMessage () .authenticateRequest ();
70+ authenticationMsg .authenticateRequest ();
7171
7272 BALL_LOG_DEBUG << " Received authentication message from '"
73- << context->initialConnectionContext ()-> channel ()->peerUri ()
73+ << context->channel ()->peerUri ()
7474 << " ': " << authenticateRequest;
7575
7676 bmqp_ctrlmsg::AuthenticationMessage authenticationResponse;
7777 bmqp_ctrlmsg::AuthenticateResponse& response =
7878 authenticationResponse.makeAuthenticateResponse ();
7979
80+ if (!context->authenticationContext ()) {
81+ // Create an AuthenticationContext for that connection
82+ bsl::shared_ptr<mqbnet::AuthenticationContext> authenticationContext =
83+ bsl::allocate_shared<mqbnet::AuthenticationContext>(
84+ d_allocator_p,
85+ context.get (), // initialConnectionContext
86+ false , // isReversed
87+ mqbnet::AuthenticationContext::State::
88+ e_AUTHENTICATING // state
89+ );
90+ context->setAuthenticationContext (authenticationContext);
91+ }
92+ else {
93+ context->authenticationContext ()->testAndSwapState (
94+ mqbnet::AuthenticationContext::State::e_AUTHENTICATED,
95+ mqbnet::AuthenticationContext::State::e_AUTHENTICATING);
96+ }
97+
8098 // Always succeeds for now
8199 // TODO: For later implementation, plugins will perform authentication,
82100 // taking the `AuthenticationContext` and updates it with the
@@ -85,20 +103,21 @@ int Authenticator::onAuthenticationRequest(
85103 response.status ().code () = 0 ;
86104 response.lifetimeMs () = 10 * 60 * 1000 ;
87105
88- context->testAndSwapState (
106+ context->authenticationContext ()-> testAndSwapState (
89107 mqbnet::AuthenticationContext::State::e_AUTHENTICATING,
90108 mqbnet::AuthenticationContext::State::e_AUTHENTICATED);
91109
92110 int rc = sendAuthenticationMessage (errorDescription,
93111 authenticationResponse,
94- context);
112+ context-> authenticationContext () );
95113
96114 return rc;
97115}
98116
99117int Authenticator::onAuthenticationResponse (
100- bsl::ostream& errorDescription,
101- const AuthenticationContextSp& context)
118+ bsl::ostream& errorDescription,
119+ const bmqp_ctrlmsg::AuthenticationMessage& authenticationMsg,
120+ const InitialConnectionContextSp& context)
102121{
103122 BALL_LOG_ERROR << " Not Implemented" ;
104123
@@ -167,9 +186,11 @@ Authenticator::~Authenticator()
167186 // NOTHING: (required because of inheritance)
168187}
169188
170- int Authenticator::handleAuthentication (bsl::ostream& errorDescription,
171- bool * isContinueRead,
172- const AuthenticationContextSp& context)
189+ int Authenticator::handleAuthentication (
190+ bsl::ostream& errorDescription,
191+ const bmqp_ctrlmsg::AuthenticationMessage& authenticationMsg,
192+ bool * isContinueRead,
193+ const InitialConnectionContextSp& context)
173194{
174195 enum RcEnum {
175196 // Value for the various RC error categories
@@ -180,19 +201,19 @@ int Authenticator::handleAuthentication(bsl::ostream& errorDescription,
180201 bmqu::MemOutStream errStream;
181202 int rc = rc_SUCCESS;
182203
183- switch (context-> authenticationMessage () .selectionId ()) {
204+ switch (authenticationMsg .selectionId ()) {
184205 case bmqp_ctrlmsg::AuthenticationMessage::
185206 SELECTION_ID_AUTHENTICATE_REQUEST: {
186- rc = onAuthenticationRequest (errStream, context);
207+ rc = onAuthenticationRequest (errStream, authenticationMsg, context);
187208 } break ; // BREAK
188209 case bmqp_ctrlmsg::AuthenticationMessage::
189210 SELECTION_ID_AUTHENTICATE_RESPONSE: {
190- rc = onAuthenticationResponse (errStream, context);
211+ rc = onAuthenticationResponse (errStream, authenticationMsg, context);
191212 } break ; // BREAK
192213 default : {
193214 errorDescription
194215 << " Invalid authentication message received (unknown type): "
195- << context-> authenticationMessage () ;
216+ << authenticationMsg ;
196217 return rc_ERROR; // RETURN
197218 }
198219 }
0 commit comments