qpid-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From oru...@apache.org
Subject qpid-broker-j git commit: QPID-8219: [Broker-J] Cache authentication results for the same remote hosts and credentials
Date Thu, 26 Jul 2018 12:25:11 GMT
Repository: qpid-broker-j
Updated Branches:
  refs/heads/6.1.x b3842e302 -> 0b3cefaee


QPID-8219: [Broker-J] Cache authentication results for the same remote hosts and credentials

(cherry picked from commit 6fd5156b6a16381839ac86fce1c7ce2aabe542dc)


Project: http://git-wip-us.apache.org/repos/asf/qpid-broker-j/repo
Commit: http://git-wip-us.apache.org/repos/asf/qpid-broker-j/commit/0b3cefae
Tree: http://git-wip-us.apache.org/repos/asf/qpid-broker-j/tree/0b3cefae
Diff: http://git-wip-us.apache.org/repos/asf/qpid-broker-j/diff/0b3cefae

Branch: refs/heads/6.1.x
Commit: 0b3cefaeee90949b52c54bd9150e077525c9d3c7
Parents: b3842e3
Author: Alex Rudyy <orudyy@apache.org>
Authored: Tue Jul 17 13:05:44 2018 +0100
Committer: Alex Rudyy <orudyy@apache.org>
Committed: Thu Jul 26 13:24:47 2018 +0100

----------------------------------------------------------------------
 .../manager/AuthenticationResultCacher.java     | 17 ++++++++-
 .../manager/AuthenticationResultCacherTest.java | 39 +++++++++++---------
 2 files changed, 38 insertions(+), 18 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/qpid-broker-j/blob/0b3cefae/broker-core/src/main/java/org/apache/qpid/server/security/auth/manager/AuthenticationResultCacher.java
----------------------------------------------------------------------
diff --git a/broker-core/src/main/java/org/apache/qpid/server/security/auth/manager/AuthenticationResultCacher.java
b/broker-core/src/main/java/org/apache/qpid/server/security/auth/manager/AuthenticationResultCacher.java
index baf9c25..3fdc8c4 100644
--- a/broker-core/src/main/java/org/apache/qpid/server/security/auth/manager/AuthenticationResultCacher.java
+++ b/broker-core/src/main/java/org/apache/qpid/server/security/auth/manager/AuthenticationResultCacher.java
@@ -19,6 +19,8 @@
 
 package org.apache.qpid.server.security.auth.manager;
 
+import java.net.InetSocketAddress;
+import java.net.SocketAddress;
 import java.nio.charset.Charset;
 import java.nio.charset.StandardCharsets;
 import java.security.AccessController;
@@ -117,7 +119,20 @@ public class AuthenticationResultCacher
             if (connectionPrincipals != null && !connectionPrincipals.isEmpty())
             {
                 SocketConnectionPrincipal connectionPrincipal = connectionPrincipals.iterator().next();
-                md.update(connectionPrincipal.getRemoteAddress().toString().getBytes(UTF8));
+                SocketAddress remoteAddress = connectionPrincipal.getRemoteAddress();
+                String address;
+                if (remoteAddress instanceof InetSocketAddress)
+                {
+                    address = ((InetSocketAddress) remoteAddress).getHostString();
+                }
+                else
+                {
+                    address = remoteAddress.toString();
+                }
+                if (address != null)
+                {
+                    md.update(address.getBytes(UTF8));
+                }
             }
 
             for (String part : content)

http://git-wip-us.apache.org/repos/asf/qpid-broker-j/blob/0b3cefae/broker-core/src/test/java/org/apache/qpid/server/security/auth/manager/AuthenticationResultCacherTest.java
----------------------------------------------------------------------
diff --git a/broker-core/src/test/java/org/apache/qpid/server/security/auth/manager/AuthenticationResultCacherTest.java
b/broker-core/src/test/java/org/apache/qpid/server/security/auth/manager/AuthenticationResultCacherTest.java
index 8919e60..e9e744d 100644
--- a/broker-core/src/test/java/org/apache/qpid/server/security/auth/manager/AuthenticationResultCacherTest.java
+++ b/broker-core/src/test/java/org/apache/qpid/server/security/auth/manager/AuthenticationResultCacherTest.java
@@ -108,32 +108,37 @@ public class AuthenticationResultCacherTest extends QpidTestCase
         });
     }
 
-
-    public void testCacheMissDifferentAddress() throws Exception
+    public void testCacheMissDifferentRemoteAddressHosts() throws Exception
     {
-        Subject.doAs(_subject, new PrivilegedAction<Void>()
-        {
-            @Override
-            public Void run()
-            {
-                AuthenticationResult result;
-                result = _authenticationResultCacher.getOrLoad(new String[]{"credentials"},
_loader);
-                assertEquals("Unexpected AuthenticationResult", _successfulAuthenticationResult,
result);
-                assertEquals("Unexpected number of loads before cache hit", 1, _loadCallCount);
-                return null;
-            }
-        });
+        final String credentials = "credentials";
+        assertGetOrLoad(credentials, _successfulAuthenticationResult, 1);
+        when(_connection.getRemoteSocketAddress()).thenReturn(new InetSocketAddress("example2.com",
8888));
+        assertGetOrLoad(credentials, _successfulAuthenticationResult, 2);
+    }
 
+    public void testCacheHitDifferentRemoteAddressPorts() throws Exception
+    {
+        final int expectedHitCount = 1;
+        final AuthenticationResult expectedResult = _successfulAuthenticationResult;
+        final String credentials = "credentials";
+        assertGetOrLoad(credentials, expectedResult, expectedHitCount);
         when(_connection.getRemoteSocketAddress()).thenReturn(new InetSocketAddress("example.com",
8888));
+        assertGetOrLoad(credentials, expectedResult, expectedHitCount);
+    }
+
+    private void assertGetOrLoad(final String credentials,
+                                 final AuthenticationResult expectedResult,
+                                 final int expectedHitCount)
+    {
         Subject.doAs(_subject, new PrivilegedAction<Void>()
         {
             @Override
             public Void run()
             {
                 AuthenticationResult result;
-                result = _authenticationResultCacher.getOrLoad(new String[]{"credentials"},
_loader);
-                assertEquals("Unexpected AuthenticationResult", _successfulAuthenticationResult,
result);
-                assertEquals("Unexpected number of loads before cache hit", 2, _loadCallCount);
+                result = _authenticationResultCacher.getOrLoad(new String[]{credentials},
_loader);
+                assertEquals("Unexpected AuthenticationResult", expectedResult, result);
+                assertEquals("Unexpected number of loads before cache hit", (long)expectedHitCount,
(long) _loadCallCount);
                 return null;
             }
         });


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


Mime
View raw message