You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by ch...@apache.org on 2012/05/02 19:00:54 UTC

svn commit: r1333110 - in /qpid/trunk/qpid/cpp/src: qpid/acl/AclConnectionCounter.cpp qpid/broker/Connection.h tests/acl.py

Author: chug
Date: Wed May  2 17:00:54 2012
New Revision: 1333110

URL: http://svn.apache.org/viewvc?rev=1333110&view=rev
Log:
QPID-2616 Count and limit client connections.
Bug fix: use Connection.getUserId() and not getUsername() to identify user and upgrade selftest to match. Add comment to Connection.h to suggest the particular pitfall.


Modified:
    qpid/trunk/qpid/cpp/src/qpid/acl/AclConnectionCounter.cpp
    qpid/trunk/qpid/cpp/src/qpid/broker/Connection.h
    qpid/trunk/qpid/cpp/src/tests/acl.py

Modified: qpid/trunk/qpid/cpp/src/qpid/acl/AclConnectionCounter.cpp
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/cpp/src/qpid/acl/AclConnectionCounter.cpp?rev=1333110&r1=1333109&r2=1333110&view=diff
==============================================================================
--- qpid/trunk/qpid/cpp/src/qpid/acl/AclConnectionCounter.cpp (original)
+++ qpid/trunk/qpid/cpp/src/qpid/acl/AclConnectionCounter.cpp Wed May  2 17:00:54 2012
@@ -104,7 +104,7 @@ void ConnectionCounter::releaseLH(
 //
 void ConnectionCounter::connection(broker::Connection& connection) {
     QPID_LOG(trace, "ACL ConnectionCounter connection IP:" << connection.getMgmtId()
-        << ", user:" << connection.getUsername());
+        << ", userId:" << connection.getUserId());
 
     Mutex::ScopedLock locker(dataLock);
 
@@ -117,11 +117,11 @@ void ConnectionCounter::connection(broke
 //
 void ConnectionCounter::opened(broker::Connection& connection) {
     QPID_LOG(trace, "ACL ConnectionCounter Opened IP:" << connection.getMgmtId()
-        << ", user:" << connection.getUsername());
+        << ", userId:" << connection.getUserId());
 
     Mutex::ScopedLock locker(dataLock);
 
-    const std::string& userName(              connection.getUsername());
+    const std::string& userName(              connection.getUserId());
     const std::string& hostName(getClientHost(connection.getMgmtId()));
 
     // Bump state from CREATED to OPENED
@@ -157,7 +157,7 @@ void ConnectionCounter::opened(broker::C
 //
 void ConnectionCounter::closed(broker::Connection& connection) {
     QPID_LOG(trace, "ACL ConnectionCounter Closed IP:" << connection.getMgmtId()
-        << ", user:" << connection.getUsername());
+        << ", userId:" << connection.getUserId());
 
     Mutex::ScopedLock locker(dataLock);
 
@@ -167,7 +167,7 @@ void ConnectionCounter::closed(broker::C
             // Normal case: connection was created and opened.
             // Decrement in-use counts
             releaseLH(connectByNameMap,
-                      connection.getUsername(),
+                      connection.getUserId(),
                       nameLimit);
 
             releaseLH(connectByHostMap,

Modified: qpid/trunk/qpid/cpp/src/qpid/broker/Connection.h
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/cpp/src/qpid/broker/Connection.h?rev=1333110&r1=1333109&r2=1333110&view=diff
==============================================================================
--- qpid/trunk/qpid/cpp/src/qpid/broker/Connection.h (original)
+++ qpid/trunk/qpid/cpp/src/qpid/broker/Connection.h Wed May  2 17:00:54 2012
@@ -113,15 +113,20 @@ class Connection : public sys::Connectio
     void requestIOProcessing (boost::function0<void>);
     void recordFromServer (const framing::AMQFrame& frame);
     void recordFromClient (const framing::AMQFrame& frame);
+
+    // gets for configured federation links
     std::string getAuthMechanism();
     std::string getAuthCredentials();
     std::string getUsername();
     std::string getPassword();
     std::string getHost();
     uint16_t    getPort();
+
     void notifyConnectionForced(const std::string& text);
     void setUserId(const std::string& uid);
     void raiseConnectEvent();
+
+    // credentials for connected client
     const std::string& getUserId() const { return ConnectionState::getUserId(); }
     const std::string& getMgmtId() const { return mgmtId; }
     management::ManagementAgent* getAgent() const { return agent; }

Modified: qpid/trunk/qpid/cpp/src/tests/acl.py
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/cpp/src/tests/acl.py?rev=1333110&r1=1333109&r2=1333110&view=diff
==============================================================================
--- qpid/trunk/qpid/cpp/src/tests/acl.py (original)
+++ qpid/trunk/qpid/cpp/src/tests/acl.py Wed May  2 17:00:54 2012
@@ -1518,29 +1518,41 @@ class ACLTests(TestBase010):
         """
         # By username should be able to connect twice per user
         try:
-            sessiona1 = self.get_session_by_port('anonymous','anonymous', self.port_u())
-            sessiona2 = self.get_session_by_port('anonymous','anonymous', self.port_u())
+            sessiona1 = self.get_session_by_port('alice','alice', self.port_u())
+            sessiona2 = self.get_session_by_port('alice','alice', self.port_u())
         except Exception, e:
-            self.fail("Could not create two connections per user: " + str(e))
+            self.fail("Could not create two connections for user alice: " + str(e))
 
         # Third session should fail
         try:
-            sessiona3 = self.get_session_by_port('anonymous','anonymous', self.port_u())
-            self.fail("Should not be able to create third connection")
+            sessiona3 = self.get_session_by_port('alice','alice', self.port_u())
+            self.fail("Should not be able to create third connection for user alice")
+        except Exception, e:
+            result = None
+
+        try:
+            sessionb1 = self.get_session_by_port('bob','bob', self.port_u())
+            sessionb2 = self.get_session_by_port('bob','bob', self.port_u())
+        except Exception, e:
+            self.fail("Could not create two connections for user bob: " + str(e))
+
+        try:
+            sessionb3 = self.get_session_by_port('bob','bob', self.port_u())
+            self.fail("Should not be able to create third connection for user bob")
         except Exception, e:
             result = None
 
         # By IP address should be able to connect twice per client address
         try:
-            sessionb1 = self.get_session_by_port('anonymous','anonymous', self.port_i())
-            sessionb2 = self.get_session_by_port('anonymous','anonymous', self.port_i())
+            sessionb1 = self.get_session_by_port('alice','alice', self.port_i())
+            sessionb2 = self.get_session_by_port('bob','bob', self.port_i())
         except Exception, e:
-            self.fail("Could not create two connections per user: " + str(e))
+            self.fail("Could not create two connections for client address: " + str(e))
 
         # Third session should fail
         try:
-            sessionb3 = self.get_session_by_port('anonymous','anonymous', self.port_i())
-            self.fail("Should not be able to create third connection")
+            sessionb3 = self.get_session_by_port('charlie','charlie', self.port_i())
+            self.fail("Should not be able to create third connection for client address")
         except Exception, e:
             result = None
 



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org