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,42 @@ 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+ State::e_AUTHENTICATING // state
88+ );
89+ context->setAuthenticationContext (authenticationContext);
90+ }
91+ else {
92+ context->authenticationContext ()->testAndSwapState (
93+ State::e_AUTHENTICATED,
94+ State::e_AUTHENTICATING);
95+ }
96+
8097 // Always succeeds for now
8198 // TODO: For later implementation, plugins will perform authentication,
8299 // taking the `AuthenticationContext` and updates it with the
@@ -85,20 +102,20 @@ int Authenticator::onAuthenticationRequest(
85102 response.status ().code () = 0 ;
86103 response.lifetimeMs () = 10 * 60 * 1000 ;
87104
88- context->testAndSwapState (
89- mqbnet::AuthenticationContext::State::e_AUTHENTICATING,
90- mqbnet::AuthenticationContext::State::e_AUTHENTICATED);
105+ context->authenticationContext ()->testAndSwapState (State::e_AUTHENTICATING,
106+ State::e_AUTHENTICATED);
91107
92108 int rc = sendAuthenticationMessage (errorDescription,
93109 authenticationResponse,
94- context);
110+ context-> authenticationContext () );
95111
96112 return rc;
97113}
98114
99115int Authenticator::onAuthenticationResponse (
100- bsl::ostream& errorDescription,
101- const AuthenticationContextSp& context)
116+ bsl::ostream& errorDescription,
117+ const bmqp_ctrlmsg::AuthenticationMessage& authenticationMsg,
118+ const InitialConnectionContextSp& context)
102119{
103120 BALL_LOG_ERROR << " Not Implemented" ;
104121
@@ -167,9 +184,11 @@ Authenticator::~Authenticator()
167184 // NOTHING: (required because of inheritance)
168185}
169186
170- int Authenticator::handleAuthentication (bsl::ostream& errorDescription,
171- bool * isContinueRead,
172- const AuthenticationContextSp& context)
187+ int Authenticator::handleAuthentication (
188+ bsl::ostream& errorDescription,
189+ const bmqp_ctrlmsg::AuthenticationMessage& authenticationMsg,
190+ bool * isContinueRead,
191+ const InitialConnectionContextSp& context)
173192{
174193 enum RcEnum {
175194 // Value for the various RC error categories
@@ -180,19 +199,19 @@ int Authenticator::handleAuthentication(bsl::ostream& errorDescription,
180199 bmqu::MemOutStream errStream;
181200 int rc = rc_SUCCESS;
182201
183- switch (context-> authenticationMessage () .selectionId ()) {
202+ switch (authenticationMsg .selectionId ()) {
184203 case bmqp_ctrlmsg::AuthenticationMessage::
185204 SELECTION_ID_AUTHENTICATE_REQUEST: {
186- rc = onAuthenticationRequest (errStream, context);
205+ rc = onAuthenticationRequest (errStream, authenticationMsg, context);
187206 } break ; // BREAK
188207 case bmqp_ctrlmsg::AuthenticationMessage::
189208 SELECTION_ID_AUTHENTICATE_RESPONSE: {
190- rc = onAuthenticationResponse (errStream, context);
209+ rc = onAuthenticationResponse (errStream, authenticationMsg, context);
191210 } break ; // BREAK
192211 default : {
193212 errorDescription
194213 << " Invalid authentication message received (unknown type): "
195- << context-> authenticationMessage () ;
214+ << authenticationMsg ;
196215 return rc_ERROR; // RETURN
197216 }
198217 }
0 commit comments