summaryrefslogtreecommitdiff
path: root/qpid/java/broker/src/test
diff options
context:
space:
mode:
authorRobert Gemmell <robbie@apache.org>2013-04-01 01:36:18 +0000
committerRobert Gemmell <robbie@apache.org>2013-04-01 01:36:18 +0000
commit43d1adbf18e349a430f7777a862407c51ee2c147 (patch)
treef5dea47975bef966f2d6b870bb99dca2de76fbc9 /qpid/java/broker/src/test
parent4286ef13fc5b0f99f517350e6088f92d86aa596b (diff)
downloadqpid-python-43d1adbf18e349a430f7777a862407c51ee2c147.tar.gz
QPID-4676: change External auth provider to create usernames of the form <CN>@<DC1>.<DC2>....<DCN> by default
- Allows for use of SSL Client Authentication in manner more consistent with the C++ broker - Adds 'useFullDN' attribute to the auth provider to allow enabling use of the old behaviour git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk@1463074 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'qpid/java/broker/src/test')
-rw-r--r--qpid/java/broker/src/test/java/org/apache/qpid/server/security/auth/manager/ExternalAuthenticationManagerTest.java123
1 files changed, 113 insertions, 10 deletions
diff --git a/qpid/java/broker/src/test/java/org/apache/qpid/server/security/auth/manager/ExternalAuthenticationManagerTest.java b/qpid/java/broker/src/test/java/org/apache/qpid/server/security/auth/manager/ExternalAuthenticationManagerTest.java
index a66d73c47d..a5d087593a 100644
--- a/qpid/java/broker/src/test/java/org/apache/qpid/server/security/auth/manager/ExternalAuthenticationManagerTest.java
+++ b/qpid/java/broker/src/test/java/org/apache/qpid/server/security/auth/manager/ExternalAuthenticationManagerTest.java
@@ -25,11 +25,13 @@ import javax.security.sasl.SaslException;
import javax.security.sasl.SaslServer;
import org.apache.qpid.server.security.auth.AuthenticationResult;
+import org.apache.qpid.server.security.auth.UsernamePrincipal;
import org.apache.qpid.test.utils.QpidTestCase;
public class ExternalAuthenticationManagerTest extends QpidTestCase
{
- private AuthenticationManager _manager = new ExternalAuthenticationManager();
+ private AuthenticationManager _manager = new ExternalAuthenticationManager(false);
+ private AuthenticationManager _managerUsingFullDN = new ExternalAuthenticationManager(true);
public void testGetMechanisms() throws Exception
{
@@ -38,13 +40,23 @@ public class ExternalAuthenticationManagerTest extends QpidTestCase
public void testCreateSaslServer() throws Exception
{
- SaslServer server = _manager.createSaslServer("EXTERNAL", "example.example.com", null);
+ createSaslServerTestImpl(_manager);
+ }
+
+ public void testCreateSaslServerUsingFullDN() throws Exception
+ {
+ createSaslServerTestImpl(_managerUsingFullDN);
+ }
+
+ public void createSaslServerTestImpl(AuthenticationManager manager) throws Exception
+ {
+ SaslServer server = manager.createSaslServer("EXTERNAL", "example.example.com", null);
assertEquals("Sasl Server mechanism name is not as expected", "EXTERNAL", server.getMechanismName());
try
{
- server = _manager.createSaslServer("PLAIN", "example.example.com", null);
+ server = manager.createSaslServer("PLAIN", "example.example.com", null);
fail("Expected creating SaslServer with incorrect mechanism to throw an exception");
}
catch (SaslException e)
@@ -53,12 +65,16 @@ public class ExternalAuthenticationManagerTest extends QpidTestCase
}
}
- public void testAuthenticate() throws Exception
+ /**
+ * Test behaviour of the authentication when the useFullDN attribute is set true
+ * and the username is taken directly as the externally supplied Principal
+ */
+ public void testAuthenticateWithFullDN() throws Exception
{
X500Principal principal = new X500Principal("CN=person, DC=example, DC=com");
- SaslServer saslServer = _manager.createSaslServer("EXTERNAL", "example.example.com", principal);
+ SaslServer saslServer = _managerUsingFullDN.createSaslServer("EXTERNAL", "example.example.com", principal);
- AuthenticationResult result = _manager.authenticate(saslServer, new byte[0]);
+ AuthenticationResult result = _managerUsingFullDN.authenticate(saslServer, new byte[0]);
assertNotNull(result);
assertEquals("Expected authentication to be successful",
AuthenticationResult.AuthenticationStatus.SUCCESS,
@@ -66,15 +82,102 @@ public class ExternalAuthenticationManagerTest extends QpidTestCase
assertOnlyContainsWrapped(principal, result.getPrincipals());
+ saslServer = _managerUsingFullDN.createSaslServer("EXTERNAL", "example.example.com", null);
+ result = _managerUsingFullDN.authenticate(saslServer, new byte[0]);
+
+ assertNotNull(result);
+ assertEquals("Expected authentication to be unsuccessful",
+ AuthenticationResult.AuthenticationStatus.ERROR,
+ result.getStatus());
+ }
+
+ /**
+ * Test behaviour of the authentication when parsing the username from
+ * the Principals DN as <CN>@<DC1>.<DC2>.<DC3>....<DCN>
+ */
+ public void testAuthenticateWithUsernameBasedOnCNAndDC() throws Exception
+ {
+ X500Principal principal;
+ SaslServer saslServer;
+ AuthenticationResult result;
+ UsernamePrincipal expectedPrincipal;
+
+ // DN contains only CN
+ principal = new X500Principal("CN=person");
+ expectedPrincipal = new UsernamePrincipal("person");
+ saslServer = _manager.createSaslServer("EXTERNAL", "example.example.com", principal);
+
+ result = _manager.authenticate(saslServer, new byte[0]);
+ assertNotNull(result);
+ assertEquals("Expected authentication to be successful",
+ AuthenticationResult.AuthenticationStatus.SUCCESS,
+ result.getStatus());
+ assertOnlyContainsWrapped(expectedPrincipal, result.getPrincipals());
+
+ // Null princial
saslServer = _manager.createSaslServer("EXTERNAL", "example.example.com", null);
result = _manager.authenticate(saslServer, new byte[0]);
assertNotNull(result);
- assertEquals("Expected authentication to be unsuccessful",
- AuthenticationResult.AuthenticationStatus.ERROR,
- result.getStatus());
+ assertEquals("Expected authentication to be unsuccessful",
+ AuthenticationResult.AuthenticationStatus.ERROR,
+ result.getStatus());
- }
+ // DN doesn't contain CN
+ principal = new X500Principal("DC=example, DC=com, O=My Company Ltd, L=Newbury, ST=Berkshire, C=GB");
+ saslServer = _manager.createSaslServer("EXTERNAL", "example.example.com", principal);
+ result = _manager.authenticate(saslServer, new byte[0]);
+ assertNotNull(result);
+ assertEquals("Expected authentication to be unsuccessful",
+ AuthenticationResult.AuthenticationStatus.ERROR,
+ result.getStatus());
+
+ // DN contains empty CN
+ principal = new X500Principal("CN=, DC=example, DC=com, O=My Company Ltd, L=Newbury, ST=Berkshire, C=GB");
+ saslServer = _manager.createSaslServer("EXTERNAL", "example.example.com", principal);
+ result = _manager.authenticate(saslServer, new byte[0]);
+
+ assertNotNull(result);
+ assertEquals("Expected authentication to be unsuccessful",
+ AuthenticationResult.AuthenticationStatus.ERROR,
+ result.getStatus());
+
+ // DN contains CN and DC
+ principal = new X500Principal("CN=person, DC=example, DC=com");
+ expectedPrincipal = new UsernamePrincipal("person@example.com");
+ saslServer = _manager.createSaslServer("EXTERNAL", "example.example.com", principal);
+
+ result = _manager.authenticate(saslServer, new byte[0]);
+ assertNotNull(result);
+ assertEquals("Expected authentication to be successful",
+ AuthenticationResult.AuthenticationStatus.SUCCESS,
+ result.getStatus());
+ assertOnlyContainsWrapped(expectedPrincipal, result.getPrincipals());
+
+ // DN contains CN and DC and other components
+ principal = new X500Principal("CN=person, DC=example, DC=com, O=My Company Ltd, L=Newbury, ST=Berkshire, C=GB");
+ expectedPrincipal = new UsernamePrincipal("person@example.com");
+ saslServer = _manager.createSaslServer("EXTERNAL", "example.example.com", principal);
+
+ result = _manager.authenticate(saslServer, new byte[0]);
+ assertNotNull(result);
+ assertEquals("Expected authentication to be successful",
+ AuthenticationResult.AuthenticationStatus.SUCCESS,
+ result.getStatus());
+ assertOnlyContainsWrapped(expectedPrincipal, result.getPrincipals());
+
+ // DN contains CN and DC and other components
+ principal = new X500Principal("CN=person, O=My Company Ltd, L=Newbury, ST=Berkshire, C=GB");
+ expectedPrincipal = new UsernamePrincipal("person");
+ saslServer = _manager.createSaslServer("EXTERNAL", "example.example.com", principal);
+
+ result = _manager.authenticate(saslServer, new byte[0]);
+ assertNotNull(result);
+ assertEquals("Expected authentication to be successful",
+ AuthenticationResult.AuthenticationStatus.SUCCESS,
+ result.getStatus());
+ assertOnlyContainsWrapped(expectedPrincipal, result.getPrincipals());
+ }
}