Skip to content

Commit 6737422

Browse files
committed
modity authenticator (can't compile)
Signed-off-by: Emelia Lei <[email protected]>
1 parent e5becab commit 6737422

5 files changed

+133
-251
lines changed

Diff for: src/groups/mqb/mqba/mqba_authenticator.cpp

+9-33
Original file line numberDiff line numberDiff line change
@@ -39,24 +39,9 @@ const int k_AUTHENTICATION_READTIMEOUT = 3 * 60; // 3 minutes
3939

4040
}
4141

42-
// -----------------------
42+
// -------------------
4343
// class Authenticator
44-
// -----------------------
45-
46-
void Authenticator::readCallback(const bmqio::Status& status,
47-
int* numNeeded,
48-
bdlbb::Blob* blob,
49-
const AuthenticationContextSp& context)
50-
{
51-
}
52-
53-
int Authenticator::decodeNegotiationMessage(
54-
bsl::ostream& errorDescription,
55-
const AuthenticationContextSp& context,
56-
const bdlbb::Blob& blob)
57-
{
58-
return 0;
59-
}
44+
// -------------------
6045

6146
int Authenticator::onAuthenticationRequest(
6247
bsl::ostream& errorDescription,
@@ -73,9 +58,9 @@ int Authenticator::onAuthenticationResponse(
7358
}
7459

7560
int Authenticator::sendAuthenticationMessage(
76-
bsl::ostream& errorDescription,
77-
const bmqp_ctrlmsg::NegotiationMessage& message,
78-
const AuthenticationContextSp& context)
61+
bsl::ostream& errorDescription,
62+
const bmqp_ctrlmsg::AuthenticationMessage& message,
63+
const AuthenticationContextSp& context)
7964
{
8065
return 0;
8166
}
@@ -85,15 +70,12 @@ void Authenticator::initiateOutboundAuthentication(
8570
{
8671
}
8772

88-
void Authenticator::scheduleRead(const AuthenticationContextSp& context)
89-
{
90-
}
91-
9273
// CREATORS
9374
Authenticator::Authenticator(bslma::Allocator* allocator)
9475
: d_allocator_p(allocator)
9576
, d_clusterCatalog_p(0)
9677
{
78+
// NOTHING
9779
}
9880

9981
/// Destructor
@@ -102,16 +84,10 @@ Authenticator::~Authenticator()
10284
// NOTHING: (required because of inheritance)
10385
}
10486

105-
void Authenticator::authenticate(
106-
mqbnet::AuthenticatorContext* context,
107-
const bsl::shared_ptr<bmqio::Channel>& channel,
108-
const mqbnet::Authenticator::AuthenticationCb& authenticationCb)
87+
int Authenticator::authenticationOutboundOrReverse(
88+
const AuthenticationContextSp& context)
10989
{
110-
// Create a AuthenticationContextSp for that connection
111-
AuthenticationContextSp AuthenticationContext;
112-
AuthenticationContext.createInplace(d_allocator_p);
113-
114-
AuthenticationContext->d_authenticationCb = authenticationCb;
90+
return 0;
11591
}
11692

11793
} // close package namespace

Diff for: src/groups/mqb/mqba/mqba_authenticator.h

+17-84
Original file line numberDiff line numberDiff line change
@@ -57,56 +57,18 @@ class Dispatcher;
5757

5858
namespace mqba {
5959

60-
// =======================
60+
// ===================
6161
// class Authenticator
62-
// =======================
62+
// ===================
6363

6464
/// Authenticator for a BlazingMQ session with client or broker
6565
class Authenticator : public mqbnet::Authenticator {
6666
public:
6767
// TYPES
6868

6969
private:
70-
// PRIVATE TYPES
71-
struct ConnectionType {
72-
// Enum representing the type of session being negotiated, from that
73-
// side of the connection's point of view.
74-
enum Enum {
75-
e_UNKNOWN,
76-
e_CLUSTER_PROXY, // Reverse connection proxy -> broker
77-
e_CLUSTER_MEMBER, // Cluster node -> cluster node
78-
e_CLIENT, // Either SDK or Proxy -> Proxy or cluster node
79-
e_ADMIN
80-
};
81-
};
82-
83-
/// Struct used to hold the context associated to a session being
84-
/// negotiated
85-
struct AuthenticationContext {
86-
// PUBLIC DATA
87-
88-
/// The associated authenticatorContext, passed in by the caller.
89-
mqbnet::AuthenticatorContext* d_authenticatorContext_p;
90-
91-
/// The channel to use for the authentication.
92-
bsl::shared_ptr<bmqio::Channel> d_channelSp;
93-
94-
/// The callback to invoke to notify of the status of the
95-
/// authentication.
96-
mqbnet::Authenticator::AuthenticationCb d_authenticationCb;
97-
98-
/// The negotiation message received from the remote peer.
99-
bmqp_ctrlmsg::NegotiationMessage d_authenticationMessage;
100-
101-
/// True if this is a "reversed" connection (on either side of the
102-
/// connection).
103-
bool d_isReversed;
104-
105-
/// The type of the session being negotiated.
106-
ConnectionType::Enum d_connectionType;
107-
};
108-
109-
typedef bsl::shared_ptr<AuthenticationContext> AuthenticationContextSp;
70+
typedef bsl::shared_ptr<mqbnet::AuthenticationContext>
71+
AuthenticationContextSp;
11072

11173
private:
11274
// DATA
@@ -127,33 +89,14 @@ class Authenticator : public mqbnet::Authenticator {
12789
private:
12890
// PRIVATE MANIPULATORS
12991

130-
/// Read callback method invoked when receiving data in the specified
131-
/// `blob`, if the specified `status` indicates success. The specified
132-
/// `numNeeded` can be used to indicate if more bytes are needed in
133-
/// order to get a full message. The specified `context` holds the
134-
/// negotiation context associated to this read.
135-
void readCallback(const bmqio::Status& status,
136-
int* numNeeded,
137-
bdlbb::Blob* blob,
138-
const AuthenticationContextSp& context);
139-
140-
/// Decode the negotiation messages received in the specified `blob` and
141-
/// store it, on success, in the corresponding member of the specified
142-
/// `context`, returning 0. Return a non-zero code on error and
143-
/// populate the specified `errorDescription` with a description of the
144-
/// error.
145-
int decodeNegotiationMessage(bsl::ostream& errorDescription,
146-
const AuthenticationContextSp& context,
147-
const bdlbb::Blob& blob);
148-
149-
/// Invoked when received a `ClientIdentity` negotiation message with
92+
/// Invoked when received a `ClientIdentity` authentication message with
15093
/// the specified `context`. Creates and return a Session on success,
15194
/// or return a null pointer and populate the specified
15295
/// `errorDescription` with a description of the error on failure.
15396
int onAuthenticationRequest(bsl::ostream& errorDescription,
15497
const AuthenticationContextSp& context);
15598

156-
/// Invoked when received a `BrokerResponse` negotiation message with
99+
/// Invoked when received a `BrokerResponse` authentication message with
157100
/// the specified `context`. Creates and return a Session on success,
158101
/// or return a null pointer and populate the specified
159102
/// `errorDescription` with a description of the error on failure.
@@ -164,22 +107,18 @@ class Authenticator : public mqbnet::Authenticator {
164107
/// specified `context` and return 0 on success, or return a non-zero
165108
/// code on error and populate the specified `errorDescription` with a
166109
/// description of the error.
167-
int
168-
sendAuthenticationMessage(bsl::ostream& errorDescription,
169-
const bmqp_ctrlmsg::NegotiationMessage& message,
170-
const AuthenticationContextSp& context);
110+
int sendAuthenticationMessage(
111+
bsl::ostream& errorDescription,
112+
const bmqp_ctrlmsg::AuthenticationMessage& message,
113+
const AuthenticationContextSp& context);
171114

172-
/// Initiate an outbound negotiation (i.e., send out some negotiation
115+
/// Initiate an outbound authentication (i.e., send out some authentication
173116
/// message and schedule a read of the response) using the specified
174117
/// `context`.
175118
/// Senario: reverse connection
176119
void
177120
initiateOutboundAuthentication(const AuthenticationContextSp& context);
178121

179-
/// Schedule a read for the negotiation of the session of the specified
180-
/// `context`.
181-
void scheduleRead(const AuthenticationContextSp& context);
182-
183122
public:
184123
// TRAITS
185124
BSLMF_NESTED_TRAIT_DECLARATION(Authenticator, bslma::UsesBslmaAllocator)
@@ -205,25 +144,19 @@ class Authenticator : public mqbnet::Authenticator {
205144
// MANIPULATORS
206145
// (virtual: mqbnet::Authenticator)
207146

208-
/// Negotiate the connection on the specified `channel` associated with
209-
/// the specified negotiation `context` and invoke the specified
210-
/// `negotiationCb` once the negotiation is complete (either success or
211-
/// failure). Note that if no negotiation are needed, the
212-
/// `negotiationCb` may be invoked directly from inside the call to
213-
/// `negotiate`.
214-
void authenticate(mqbnet::AuthenticatorContext* context,
215-
const bsl::shared_ptr<bmqio::Channel>& channel,
216-
const mqbnet::Authenticator::AuthenticationCb&
217-
authenticationCb) BSLS_KEYWORD_OVERRIDE;
147+
/// Send out outbound authentication message or reverse connection request
148+
/// with the specified `context`.
149+
int authenticationOutboundOrReverse(const AuthenticationContextSp& context)
150+
BSLS_KEYWORD_OVERRIDE;
218151
};
219152

220153
// ============================================================================
221154
// INLINE DEFINITIONS
222155
// ============================================================================
223156

224-
// -----------------------
157+
// -------------------
225158
// class Authenticator
226-
// -----------------------
159+
// -------------------
227160

228161
inline Authenticator&
229162
Authenticator::setClusterCatalog(mqbblp::ClusterCatalog* value)
+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// Copyright 2025 Bloomberg Finance L.P.
2+
// SPDX-License-Identifier: Apache-2.0
3+
//
4+
// Licensed under the Apache License, Version 2.0 (the "License");
5+
// you may not use this file except in compliance with the License.
6+
// You may obtain a copy of the License at
7+
//
8+
// http://www.apache.org/licenses/LICENSE-2.0
9+
//
10+
// Unless required by applicable law or agreed to in writing, software
11+
// distributed under the License is distributed on an "AS IS" BASIS,
12+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
// See the License for the specific language governing permissions and
14+
// limitations under the License.
15+
16+
// mqbnet_authenticationcontext.cpp -*-C++-*-
17+
#include <mqbnet_authenticationcontext.h>
18+
19+
#include <mqbscm_version.h>
20+
namespace BloombergLP {
21+
namespace mqbnet {
22+
23+
// NOTHING
24+
25+
} // close package namespace
26+
} // close enterprise namespace

Diff for: src/groups/mqb/mqbnet/mqbnet_authenticationcontext.h

+76
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
// Copyright 2025 Bloomberg Finance L.P.
2+
// SPDX-License-Identifier: Apache-2.0
3+
//
4+
// Licensed under the Apache License, Version 2.0 (the "License");
5+
// you may not use this file except in compliance with the License.
6+
// You may obtain a copy of the License at
7+
//
8+
// http://www.apache.org/licenses/LICENSE-2.0
9+
//
10+
// Unless required by applicable law or agreed to in writing, software
11+
// distributed under the License is distributed on an "AS IS" BASIS,
12+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
// See the License for the specific language governing permissions and
14+
// limitations under the License.
15+
16+
// mqbnet_authenticationcontext.h -*-C++-*-
17+
#ifndef INCLUDED_MQBNET_AUTHENTICATIONCONTEXT
18+
#define INCLUDED_MQBNET_AUTHENTICATIONCONTEXT
19+
20+
/// @file mqbnet_authenticationcontext.h
21+
///
22+
/// @brief Provide the context for initial connection handler for establishing
23+
/// sessions.
24+
///
25+
26+
// MQB
27+
#include <mqbnet_initialconnectioncontext.h>
28+
29+
// BMQ
30+
#include <bmqp_ctrlmsg_messages.h>
31+
32+
namespace BloombergLP {
33+
namespace mqbnet {
34+
35+
struct ConnectionType {
36+
// Enum representing the type of session being authenticated, from that
37+
// side of the connection's point of view.
38+
enum Enum {
39+
e_UNKNOWN,
40+
e_CLUSTER_PROXY, // Reverse connection proxy -> broker
41+
e_CLUSTER_MEMBER, // Cluster node -> cluster node
42+
e_CLIENT, // Either SDK or Proxy -> Proxy or cluster node
43+
e_ADMIN
44+
};
45+
};
46+
47+
// ===========================
48+
// class AuthenticationContext
49+
// ===========================
50+
51+
// VST for an implementation of AuthenticationContext
52+
struct AuthenticationContext {
53+
// DATA
54+
/// The associated InitialConnectionContext passed in by the caller.
55+
/// Held, not owned
56+
InitialConnectionContext* d_initialConnectionContext_p;
57+
58+
/// The authentication message received from the remote peer.
59+
bmqp_ctrlmsg::AuthenticationMessage d_authenticationMessage;
60+
61+
/// The cluster involved in the session being authenticated,
62+
/// or empty if none.
63+
bsl::string d_clusterName;
64+
65+
/// True if this is a "reversed" connection (on either side of the
66+
/// connection).
67+
bool d_isReversed;
68+
69+
/// The type of the session being authenticated.
70+
ConnectionType::Enum d_connectionType;
71+
};
72+
73+
} // close package namespace
74+
} // close enterprise namespace
75+
76+
#endif

0 commit comments

Comments
 (0)