28
28
// MQB
29
29
#include < mqbblp_clustercatalog.h>
30
30
#include < mqbnet_authenticationcontext.h>
31
+ #include < mqbnet_initialconnectioncontext.h>
31
32
32
33
// BMQ
33
34
#include < bmqio_status.h>
@@ -57,26 +58,42 @@ const int k_AUTHENTICATION_READTIMEOUT = 3 * 60; // 3 minutes
57
58
// -------------------
58
59
59
60
int Authenticator::onAuthenticationRequest (
60
- bsl::ostream& errorDescription,
61
- const AuthenticationContextSp& context)
61
+ bsl::ostream& errorDescription,
62
+ const bmqp_ctrlmsg::AuthenticationMessage& authenticationMsg,
63
+ const InitialConnectionContextSp& context)
62
64
{
63
65
// 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 ());
68
68
69
69
const bmqp_ctrlmsg::AuthenticateRequest& authenticateRequest =
70
- context-> authenticationMessage () .authenticateRequest ();
70
+ authenticationMsg .authenticateRequest ();
71
71
72
72
BALL_LOG_DEBUG << " Received authentication message from '"
73
- << context->initialConnectionContext ()-> channel ()->peerUri ()
73
+ << context->channel ()->peerUri ()
74
74
<< " ': " << authenticateRequest;
75
75
76
76
bmqp_ctrlmsg::AuthenticationMessage authenticationResponse;
77
77
bmqp_ctrlmsg::AuthenticateResponse& response =
78
78
authenticationResponse.makeAuthenticateResponse ();
79
79
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
+
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,20 @@ int Authenticator::onAuthenticationRequest(
85
102
response.status ().code () = 0 ;
86
103
response.lifetimeMs () = 10 * 60 * 1000 ;
87
104
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);
91
107
92
108
int rc = sendAuthenticationMessage (errorDescription,
93
109
authenticationResponse,
94
- context);
110
+ context-> authenticationContext () );
95
111
96
112
return rc;
97
113
}
98
114
99
115
int Authenticator::onAuthenticationResponse (
100
- bsl::ostream& errorDescription,
101
- const AuthenticationContextSp& context)
116
+ bsl::ostream& errorDescription,
117
+ const bmqp_ctrlmsg::AuthenticationMessage& authenticationMsg,
118
+ const InitialConnectionContextSp& context)
102
119
{
103
120
BALL_LOG_ERROR << " Not Implemented" ;
104
121
@@ -167,9 +184,11 @@ Authenticator::~Authenticator()
167
184
// NOTHING: (required because of inheritance)
168
185
}
169
186
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)
173
192
{
174
193
enum RcEnum {
175
194
// Value for the various RC error categories
@@ -180,19 +199,19 @@ int Authenticator::handleAuthentication(bsl::ostream& errorDescription,
180
199
bmqu::MemOutStream errStream;
181
200
int rc = rc_SUCCESS;
182
201
183
- switch (context-> authenticationMessage () .selectionId ()) {
202
+ switch (authenticationMsg .selectionId ()) {
184
203
case bmqp_ctrlmsg::AuthenticationMessage::
185
204
SELECTION_ID_AUTHENTICATE_REQUEST: {
186
- rc = onAuthenticationRequest (errStream, context);
205
+ rc = onAuthenticationRequest (errStream, authenticationMsg, context);
187
206
} break ; // BREAK
188
207
case bmqp_ctrlmsg::AuthenticationMessage::
189
208
SELECTION_ID_AUTHENTICATE_RESPONSE: {
190
- rc = onAuthenticationResponse (errStream, context);
209
+ rc = onAuthenticationResponse (errStream, authenticationMsg, context);
191
210
} break ; // BREAK
192
211
default : {
193
212
errorDescription
194
213
<< " Invalid authentication message received (unknown type): "
195
- << context-> authenticationMessage () ;
214
+ << authenticationMsg ;
196
215
return rc_ERROR; // RETURN
197
216
}
198
217
}
0 commit comments