@@ -57,26 +57,43 @@ const int k_AUTHENTICATION_READTIMEOUT = 3 * 60; // 3 minutes
5757// -------------------
5858
5959int Authenticator::onAuthenticationRequest (
60- bsl::ostream& errorDescription,
61- const AuthenticationContextSp& context)
60+ bsl::ostream& errorDescription,
61+ const bmqp_ctrlmsg::AuthenticationMessage& authenticationMsg,
62+ const InitialConnectionContextSp& context)
6263{
6364 // 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
65+ BSLS_ASSERT_SAFE (authenticationMsg.isAuthenticateRequestValue ());
66+ BSLS_ASSERT_SAFE (context->isIncoming ());
6867
6968 const bmqp_ctrlmsg::AuthenticateRequest& authenticateRequest =
70- context-> authenticationMessage () .authenticateRequest ();
69+ authenticationMsg .authenticateRequest ();
7170
7271 BALL_LOG_DEBUG << " Received authentication message from '"
73- << context->initialConnectionContext ()-> channel ()->peerUri ()
72+ << context->channel ()->peerUri ()
7473 << " ': " << authenticateRequest;
7574
7675 bmqp_ctrlmsg::AuthenticationMessage authenticationResponse;
7776 bmqp_ctrlmsg::AuthenticateResponse& response =
7877 authenticationResponse.makeAuthenticateResponse ();
7978
79+ if (!context->authenticationContext ()) {
80+ // Create an AuthenticationContext for that connection
81+ bsl::shared_ptr<mqbnet::AuthenticationContext> authenticationContext =
82+ bsl::allocate_shared<mqbnet::AuthenticationContext>(
83+ d_allocator_p,
84+ context.get (), // initialConnectionContext
85+ false , // isReversed
86+ mqbnet::AuthenticationContext::State::
87+ e_AUTHENTICATING // state
88+ );
89+ context->setAuthenticationContext (authenticationContext);
90+ }
91+ else {
92+ context->authenticationContext ()->testAndSwapState (
93+ mqbnet::AuthenticationContext::State::e_AUTHENTICATED,
94+ mqbnet::AuthenticationContext::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,21 @@ int Authenticator::onAuthenticationRequest(
85102 response.status ().code () = 0 ;
86103 response.lifetimeMs () = 10 * 60 * 1000 ;
87104
88- context->testAndSwapState (
105+ context->authenticationContext ()-> testAndSwapState (
89106 mqbnet::AuthenticationContext::State::e_AUTHENTICATING,
90107 mqbnet::AuthenticationContext::State::e_AUTHENTICATED);
91108
92109 int rc = sendAuthenticationMessage (errorDescription,
93110 authenticationResponse,
94- context);
111+ context-> authenticationContext () );
95112
96113 return rc;
97114}
98115
99116int Authenticator::onAuthenticationResponse (
100- bsl::ostream& errorDescription,
101- const AuthenticationContextSp& context)
117+ bsl::ostream& errorDescription,
118+ const bmqp_ctrlmsg::AuthenticationMessage& authenticationMsg,
119+ const InitialConnectionContextSp& context)
102120{
103121 BALL_LOG_ERROR << " Not Implemented" ;
104122
@@ -167,9 +185,11 @@ Authenticator::~Authenticator()
167185 // NOTHING: (required because of inheritance)
168186}
169187
170- int Authenticator::handleAuthentication (bsl::ostream& errorDescription,
171- bool * isContinueRead,
172- const AuthenticationContextSp& context)
188+ int Authenticator::handleAuthentication (
189+ bsl::ostream& errorDescription,
190+ const bmqp_ctrlmsg::AuthenticationMessage& authenticationMsg,
191+ bool * isContinueRead,
192+ const InitialConnectionContextSp& context)
173193{
174194 enum RcEnum {
175195 // Value for the various RC error categories
@@ -180,19 +200,19 @@ int Authenticator::handleAuthentication(bsl::ostream& errorDescription,
180200 bmqu::MemOutStream errStream;
181201 int rc = rc_SUCCESS;
182202
183- switch (context-> authenticationMessage () .selectionId ()) {
203+ switch (authenticationMsg .selectionId ()) {
184204 case bmqp_ctrlmsg::AuthenticationMessage::
185205 SELECTION_ID_AUTHENTICATE_REQUEST: {
186- rc = onAuthenticationRequest (errStream, context);
206+ rc = onAuthenticationRequest (errStream, authenticationMsg, context);
187207 } break ; // BREAK
188208 case bmqp_ctrlmsg::AuthenticationMessage::
189209 SELECTION_ID_AUTHENTICATE_RESPONSE: {
190- rc = onAuthenticationResponse (errStream, context);
210+ rc = onAuthenticationResponse (errStream, authenticationMsg, context);
191211 } break ; // BREAK
192212 default : {
193213 errorDescription
194214 << " Invalid authentication message received (unknown type): "
195- << context-> authenticationMessage () ;
215+ << authenticationMsg ;
196216 return rc_ERROR; // RETURN
197217 }
198218 }
0 commit comments