@@ -57,26 +57,43 @@ const int k_AUTHENTICATION_READTIMEOUT = 3 * 60; // 3 minutes
57
57
// -------------------
58
58
59
59
int Authenticator::onAuthenticationRequest (
60
- bsl::ostream& errorDescription,
61
- const AuthenticationContextSp& context)
60
+ bsl::ostream& errorDescription,
61
+ const bmqp_ctrlmsg::AuthenticationMessage& authenticationMsg,
62
+ const InitialConnectionContextSp& context)
62
63
{
63
64
// 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 ());
68
67
69
68
const bmqp_ctrlmsg::AuthenticateRequest& authenticateRequest =
70
- context-> authenticationMessage () .authenticateRequest ();
69
+ authenticationMsg .authenticateRequest ();
71
70
72
71
BALL_LOG_DEBUG << " Received authentication message from '"
73
- << context->initialConnectionContext ()-> channel ()->peerUri ()
72
+ << context->channel ()->peerUri ()
74
73
<< " ': " << authenticateRequest;
75
74
76
75
bmqp_ctrlmsg::AuthenticationMessage authenticationResponse;
77
76
bmqp_ctrlmsg::AuthenticateResponse& response =
78
77
authenticationResponse.makeAuthenticateResponse ();
79
78
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
+
80
97
// Always succeeds for now
81
98
// TODO: For later implementation, plugins will perform authentication,
82
99
// taking the `AuthenticationContext` and updates it with the
@@ -85,20 +102,21 @@ int Authenticator::onAuthenticationRequest(
85
102
response.status ().code () = 0 ;
86
103
response.lifetimeMs () = 10 * 60 * 1000 ;
87
104
88
- context->testAndSwapState (
105
+ context->authenticationContext ()-> testAndSwapState (
89
106
mqbnet::AuthenticationContext::State::e_AUTHENTICATING,
90
107
mqbnet::AuthenticationContext::State::e_AUTHENTICATED);
91
108
92
109
int rc = sendAuthenticationMessage (errorDescription,
93
110
authenticationResponse,
94
- context);
111
+ context-> authenticationContext () );
95
112
96
113
return rc;
97
114
}
98
115
99
116
int Authenticator::onAuthenticationResponse (
100
- bsl::ostream& errorDescription,
101
- const AuthenticationContextSp& context)
117
+ bsl::ostream& errorDescription,
118
+ const bmqp_ctrlmsg::AuthenticationMessage& authenticationMsg,
119
+ const InitialConnectionContextSp& context)
102
120
{
103
121
BALL_LOG_ERROR << " Not Implemented" ;
104
122
@@ -167,9 +185,11 @@ Authenticator::~Authenticator()
167
185
// NOTHING: (required because of inheritance)
168
186
}
169
187
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)
173
193
{
174
194
enum RcEnum {
175
195
// Value for the various RC error categories
@@ -180,19 +200,19 @@ int Authenticator::handleAuthentication(bsl::ostream& errorDescription,
180
200
bmqu::MemOutStream errStream;
181
201
int rc = rc_SUCCESS;
182
202
183
- switch (context-> authenticationMessage () .selectionId ()) {
203
+ switch (authenticationMsg .selectionId ()) {
184
204
case bmqp_ctrlmsg::AuthenticationMessage::
185
205
SELECTION_ID_AUTHENTICATE_REQUEST: {
186
- rc = onAuthenticationRequest (errStream, context);
206
+ rc = onAuthenticationRequest (errStream, authenticationMsg, context);
187
207
} break ; // BREAK
188
208
case bmqp_ctrlmsg::AuthenticationMessage::
189
209
SELECTION_ID_AUTHENTICATE_RESPONSE: {
190
- rc = onAuthenticationResponse (errStream, context);
210
+ rc = onAuthenticationResponse (errStream, authenticationMsg, context);
191
211
} break ; // BREAK
192
212
default : {
193
213
errorDescription
194
214
<< " Invalid authentication message received (unknown type): "
195
- << context-> authenticationMessage () ;
215
+ << authenticationMsg ;
196
216
return rc_ERROR; // RETURN
197
217
}
198
218
}
0 commit comments