@@ -47,7 +47,48 @@ int Authenticator::onAuthenticationRequest(
47
47
bsl::ostream& errorDescription,
48
48
const AuthenticationContextSp& context)
49
49
{
50
- return 0 ;
50
+ // PRECONDITIONS
51
+ BSLS_ASSERT_SAFE (
52
+ context->d_authenticationMessage .isAuthenticateRequestValue ());
53
+ BSLS_ASSERT_SAFE (context->d_initialConnectionContext_p ->isIncoming () ||
54
+ context->d_isReversed );
55
+
56
+ bmqp_ctrlmsg::AuthenticateRequest& authenticateRequest =
57
+ context->d_authenticationMessage .authenticateRequest ();
58
+
59
+ BALL_LOG_DEBUG
60
+ << " Received authentication message from '"
61
+ << context->d_initialConnectionContext_p ->channel ()->peerUri ()
62
+ << " ': " << authenticateRequest;
63
+
64
+ bmqp_ctrlmsg::AuthenticationMessage authenticationResponse;
65
+ bmqp_ctrlmsg::AuthenticateResponse& response =
66
+ authenticationResponse.makeAuthenticateResponse ();
67
+
68
+ // TODO: authenticate
69
+ if (authenticateRequest.mechanism () == " " ) {
70
+ BALL_LOG_ERROR << " Error on authentication" ;
71
+
72
+ bmqu::MemOutStream os;
73
+ os << " Mechanism is unspecified" ;
74
+ response.status ().category () =
75
+ bmqp_ctrlmsg::StatusCategory::E_NOT_SUPPORTED;
76
+ response.status ().message () = os.str ();
77
+ response.status ().code () = -1 ;
78
+ }
79
+ else {
80
+ response.status ().category () = bmqp_ctrlmsg::StatusCategory::E_SUCCESS;
81
+ response.status ().code () = 0 ;
82
+ response.lifetimeMs () = 10 * 60 * 1000 ;
83
+ }
84
+
85
+ BALL_LOG_INFO << " send authn response " << authenticationResponse;
86
+
87
+ int rc = sendAuthenticationMessage (errorDescription,
88
+ authenticationResponse,
89
+ context);
90
+
91
+ return rc;
51
92
}
52
93
53
94
int Authenticator::onAuthenticationResponse (
@@ -62,7 +103,41 @@ int Authenticator::sendAuthenticationMessage(
62
103
const bmqp_ctrlmsg::AuthenticationMessage& message,
63
104
const AuthenticationContextSp& context)
64
105
{
65
- return 0 ;
106
+ enum RcEnum {
107
+ // Value for the various RC error categories
108
+ rc_SUCCESS = 0 ,
109
+ rc_BUILD_FAILURE = -1 ,
110
+ rc_WRITE_FAILURE = -2
111
+ };
112
+
113
+ bmqp::EncodingType::Enum encodingType = bmqp::EncodingType::e_BER;
114
+
115
+ // TODO: why do we create a local allocator?
116
+ bdlma::LocalSequentialAllocator<2048 > localAllocator (d_allocator_p);
117
+
118
+ bmqp::SchemaEventBuilder builder (d_blobSpPool_p,
119
+ encodingType,
120
+ &localAllocator);
121
+
122
+ int rc = builder.setMessage (message, bmqp::EventType::e_AUTHENTICATION);
123
+ if (rc != 0 ) {
124
+ errorDescription << " Failed building AuthenticationMessage "
125
+ << " [rc: " << rc << " , message: " << message << " ]" ;
126
+ return rc_BUILD_FAILURE; // RETURN
127
+ }
128
+
129
+ // Send response event
130
+ bmqio::Status status;
131
+ context->d_initialConnectionContext_p ->channel ()->write (&status,
132
+ *builder.blob ());
133
+ if (!status) {
134
+ errorDescription << " Failed sending AuthenticationMessage "
135
+ << " [status: " << status << " , message: " << message
136
+ << " ]" ;
137
+ return rc_WRITE_FAILURE; // RETURN
138
+ }
139
+
140
+ return rc_SUCCESS;
66
141
}
67
142
68
143
void Authenticator::initiateOutboundAuthentication (
@@ -71,8 +146,10 @@ void Authenticator::initiateOutboundAuthentication(
71
146
}
72
147
73
148
// CREATORS
74
- Authenticator::Authenticator (bslma::Allocator* allocator)
149
+ Authenticator::Authenticator (BlobSpPool* blobSpPool,
150
+ bslma::Allocator* allocator)
75
151
: d_allocator_p(allocator)
152
+ , d_blobSpPool_p(blobSpPool)
76
153
, d_clusterCatalog_p(0 )
77
154
{
78
155
// NOTHING
@@ -84,6 +161,53 @@ Authenticator::~Authenticator()
84
161
// NOTHING: (required because of inheritance)
85
162
}
86
163
164
+ int Authenticator::handleAuthenticationOnMsgType (
165
+ const AuthenticationContextSp& context)
166
+ {
167
+ enum RcEnum {
168
+ // Value for the various RC error categories
169
+ rc_SUCCESS = 0 ,
170
+ rc_ERROR = -1 ,
171
+ };
172
+
173
+ bmqu::MemOutStream errStream;
174
+ int rc = rc_SUCCESS;
175
+
176
+ switch (context->d_authenticationMessage .selectionId ()) {
177
+ case bmqp_ctrlmsg::AuthenticationMessage::
178
+ SELECTION_ID_AUTHENTICATE_REQUEST: {
179
+ BALL_LOG_INFO << " Received authn request: "
180
+ << context->d_authenticationMessage ;
181
+ rc = onAuthenticationRequest (errStream, context);
182
+ } break ; // BREAK
183
+ case bmqp_ctrlmsg::AuthenticationMessage::
184
+ SELECTION_ID_AUTHENTICATE_RESPONSE: {
185
+ BALL_LOG_INFO << " Received authn response: "
186
+ << context->d_authenticationMessage ;
187
+ } break ; // BREAK
188
+ default : {
189
+ errStream << " Invalid authentication message received (unknown type): "
190
+ << context->d_authenticationMessage ;
191
+ bsl::string error (errStream.str ().data (), errStream.str ().length ());
192
+ context->d_initialConnectionContext_p ->initialConnectionCompleteCb ()(
193
+ rc_ERROR,
194
+ error,
195
+ bsl::shared_ptr<mqbnet::Session>());
196
+ return rc_ERROR; // RETURN
197
+ }
198
+ }
199
+
200
+ if (rc != rc_SUCCESS) {
201
+ bsl::string error (errStream.str ().data (), errStream.str ().length ());
202
+ context->d_initialConnectionContext_p ->initialConnectionCompleteCb ()(
203
+ rc_ERROR,
204
+ error,
205
+ bsl::shared_ptr<mqbnet::Session>());
206
+ }
207
+
208
+ return rc;
209
+ }
210
+
87
211
int Authenticator::authenticationOutboundOrReverse (
88
212
const AuthenticationContextSp& context)
89
213
{
0 commit comments