From 83cd0d00a444d1e1b5f8e15135bf377eba03388d Mon Sep 17 00:00:00 2001 From: "Charles E. Rolke" Date: Fri, 10 Aug 2012 17:19:51 +0000 Subject: QPID-4142 C++ Broker connection counting gets usernames confused when various auth mechanism are used. The issue is that the connection's userId is changed as the auth progresses. Also, the shadowed connections change differently from the non-shadowed connections. git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk/qpid@1371772 13f79535-47bb-0310-9956-ffa450edef68 --- cpp/src/qpid/acl/AclConnectionCounter.cpp | 41 +++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) (limited to 'cpp/src/qpid/acl/AclConnectionCounter.cpp') diff --git a/cpp/src/qpid/acl/AclConnectionCounter.cpp b/cpp/src/qpid/acl/AclConnectionCounter.cpp index 052fa3c222..8c6e3eef6e 100644 --- a/cpp/src/qpid/acl/AclConnectionCounter.cpp +++ b/cpp/src/qpid/acl/AclConnectionCounter.cpp @@ -296,6 +296,47 @@ bool ConnectionCounter::approveConnection(const broker::Connection& connection) } } + +// +// setUserId +// On cluster shadow connections, track a new user id for this connection. +// +void ConnectionCounter::setUserId(const broker::Connection& connection, + const std::string& username) +{ + Mutex::ScopedLock locker(dataLock); + + connectCountsMap_t::iterator eRef = connectProgressMap.find(connection.getMgmtId()); + if (eRef != connectProgressMap.end()) { + if ((*eRef).second == C_OPENED){ + // Connection has been opened so that current user has been counted + if (connection.isShadow()) { + // This is a shadow connection and therefore receives userId changes + QPID_LOG(debug, "Changing User ID for cluster connection: " + << connection.getMgmtId() << ", old user:'" << connection.getUserId() + << "', new user:'" << username << "'"); + + // Decrement user in-use count for old userId + releaseLH(connectByNameMap, + connection.getUserId(), + nameLimit); + // Increment user in-use count for new userId + (void) countConnectionLH(connectByNameMap, username, nameLimit, false); + } else { + QPID_LOG(warning, "Changing User ID for non-cluster connections is not supported: " + << connection.getMgmtId() << ", old user " << connection.getUserId() + << ", new user " << username); + } + } else { + // connection exists but has not been opened. + // setUserId is called in normal course. The user gets counted when connection is opened. + } + } else { + // Connection does not exist. + } +} + + // // getClientIp - given a connection's mgmtId return the client host part. // -- cgit v1.2.1