Skip to content

Commit ac15e95

Browse files
committed
adding state to AuthenticationContext
Signed-off-by: Emelia Lei <[email protected]>
1 parent c1b99bc commit ac15e95

File tree

3 files changed

+24
-0
lines changed

3 files changed

+24
-0
lines changed

src/groups/mqb/mqba/mqba_authenticator.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,10 @@ int Authenticator::onAuthenticationRequest(
8585
response.status().code() = 0;
8686
response.lifetimeMs() = 10 * 60 * 1000;
8787

88+
context->testAndSwapState(
89+
mqbnet::AuthenticationContext::State::e_AUTHENTICATING,
90+
mqbnet::AuthenticationContext::State::e_AUTHENTICATED);
91+
8892
int rc = sendAuthenticationMessage(errorDescription,
8993
authenticationResponse,
9094
context);

src/groups/mqb/mqbnet/mqbnet_authenticationcontext.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,12 @@ namespace mqbnet {
3030
AuthenticationContext::AuthenticationContext(
3131
InitialConnectionContext* initialConnectionContext,
3232
bool isReversed,
33+
State state,
3334
ConnectionType::Enum connectionType,
3435
bslma::Allocator* basicAllocator)
3536
: d_initialConnectionContext_p(initialConnectionContext)
3637
, d_authenticationMessage(basicAllocator)
38+
, d_state(state)
3739
, d_isReversed(isReversed)
3840
, d_connectionType(connectionType)
3941
{
@@ -54,6 +56,12 @@ AuthenticationContext& AuthenticationContext::setAuthenticationMessage(
5456
return *this;
5557
}
5658

59+
int AuthenticationContext::testAndSwapState(State compareValue,
60+
State swapValue)
61+
{
62+
return d_state.testAndSwap(compareValue, swapValue);
63+
}
64+
5765
AuthenticationContext& AuthenticationContext::setIsReversed(bool value)
5866
{
5967
d_isReversed = value;

src/groups/mqb/mqbnet/mqbnet_authenticationcontext.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,19 @@ namespace mqbnet {
4040

4141
/// VST for the context associated with an connection being authenticated.
4242
class AuthenticationContext {
43+
public:
44+
// TYPES
45+
enum State {
46+
e_IDLE = 0,
47+
e_AUTHENTICATING,
48+
e_AUTHENTICATED,
49+
};
50+
4351
private:
4452
// DATA
4553
InitialConnectionContext* d_initialConnectionContext_p;
4654
bmqp_ctrlmsg::AuthenticationMessage d_authenticationMessage;
55+
bsls::AtomicInt d_state;
4756
bool d_isReversed;
4857
ConnectionType::Enum d_connectionType;
4958

@@ -63,6 +72,7 @@ class AuthenticationContext {
6372
AuthenticationContext(
6473
InitialConnectionContext* initialConnectionContext,
6574
bool isReversed,
75+
State state = State::e_IDLE,
6676
ConnectionType::Enum connectionType = ConnectionType::e_UNKNOWN,
6777
bslma::Allocator* basicAllocator = 0);
6878

@@ -74,6 +84,8 @@ class AuthenticationContext {
7484
AuthenticationContext& setIsReversed(bool value);
7585
AuthenticationContext& setConnectionType(ConnectionType::Enum value);
7686

87+
int testAndSwapState(State compareValue, State swapValue);
88+
7789
// ACCESSORS
7890
InitialConnectionContext* initialConnectionContext() const;
7991
const bmqp_ctrlmsg::AuthenticationMessage& authenticationMessage() const;

0 commit comments

Comments
 (0)