diff options
| author | Alex Rudyy <orudyy@apache.org> | 2015-04-06 12:46:57 +0000 |
|---|---|---|
| committer | Alex Rudyy <orudyy@apache.org> | 2015-04-06 12:46:57 +0000 |
| commit | 09dfff6a4638c0a0b910d2fb1aae9f9aa48f5162 (patch) | |
| tree | 5469cb5073cb856f87ef1368487c47dff3fb46f5 /qpid/java | |
| parent | 8ec93cf4ee590ca42b2cfc6387889f603f97668b (diff) | |
| download | qpid-python-09dfff6a4638c0a0b910d2fb1aae9f9aa48f5162.tar.gz | |
QPID-6478: Set state to ACTIVE on creation of file based authentication provider when empty or non existing user file is specified
git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk@1671526 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'qpid/java')
2 files changed, 105 insertions, 7 deletions
diff --git a/qpid/java/broker-core/src/main/java/org/apache/qpid/server/security/auth/manager/PrincipalDatabaseAuthenticationManager.java b/qpid/java/broker-core/src/main/java/org/apache/qpid/server/security/auth/manager/PrincipalDatabaseAuthenticationManager.java index 243e9add66..6631ebab54 100644 --- a/qpid/java/broker-core/src/main/java/org/apache/qpid/server/security/auth/manager/PrincipalDatabaseAuthenticationManager.java +++ b/qpid/java/broker-core/src/main/java/org/apache/qpid/server/security/auth/manager/PrincipalDatabaseAuthenticationManager.java @@ -246,6 +246,7 @@ public abstract class PrincipalDatabaseAuthenticationManager<T extends Principal } else { + setState(State.ACTIVE); return Futures.immediateFuture(null); } } diff --git a/qpid/java/systests/src/test/java/org/apache/qpid/systest/rest/AuthenticationProviderRestTest.java b/qpid/java/systests/src/test/java/org/apache/qpid/systest/rest/AuthenticationProviderRestTest.java index 5cc7e2d4d9..46903481a5 100644 --- a/qpid/java/systests/src/test/java/org/apache/qpid/systest/rest/AuthenticationProviderRestTest.java +++ b/qpid/java/systests/src/test/java/org/apache/qpid/systest/rest/AuthenticationProviderRestTest.java @@ -26,6 +26,12 @@ import java.util.List; import java.util.Map; import java.util.UUID; +import javax.jms.Connection; +import javax.servlet.http.HttpServletResponse; + +import org.apache.qpid.client.AMQConnection; +import org.apache.qpid.client.AMQConnectionURL; +import org.apache.qpid.jms.ConnectionURL; import org.apache.qpid.server.BrokerOptions; import org.apache.qpid.server.management.plugin.servlet.rest.RestServlet; import org.apache.qpid.server.model.AuthenticationProvider; @@ -39,6 +45,7 @@ import org.apache.qpid.server.model.User; import org.apache.qpid.server.security.auth.manager.AnonymousAuthenticationManager; import org.apache.qpid.server.security.auth.manager.PlainPasswordDatabaseAuthenticationManager; import org.apache.qpid.test.utils.TestBrokerConfiguration; +import org.apache.qpid.test.utils.TestFileUtils; public class AuthenticationProviderRestTest extends QpidRestTestCase { @@ -63,15 +70,105 @@ public class AuthenticationProviderRestTest extends QpidRestTestCase public void testPutCreateSecondPlainPrincipalDatabaseProviderSucceeds() throws Exception { File principalDatabase = getRestTestHelper().createTemporaryPasswdFile(new String[]{"admin2", "guest2", "test2"}); + try + { - String providerName = "test-provider"; - Map<String, Object> attributes = new HashMap<String, Object>(); - attributes.put(AuthenticationProvider.NAME, providerName); - attributes.put(AuthenticationProvider.TYPE, PlainPasswordDatabaseAuthenticationManager.PROVIDER_TYPE); - attributes.put(ExternalFileBasedAuthenticationManager.PATH, principalDatabase.getAbsolutePath()); + String providerName = "test-provider"; + Map<String, Object> attributes = new HashMap<String, Object>(); + attributes.put(AuthenticationProvider.NAME, providerName); + attributes.put(AuthenticationProvider.TYPE, PlainPasswordDatabaseAuthenticationManager.PROVIDER_TYPE); + attributes.put(ExternalFileBasedAuthenticationManager.PATH, principalDatabase.getAbsolutePath()); - int responseCode = getRestTestHelper().submitRequest("authenticationprovider/" + providerName, "PUT", attributes); - assertEquals("failed to create authentication provider", 201, responseCode); + int responseCode = getRestTestHelper().submitRequest("authenticationprovider/" + providerName, "PUT", attributes); + assertEquals("failed to create authentication provider", 201, responseCode); + } + finally + { + principalDatabase.delete(); + } + } + + public void testCreatePlainPrincipalDatabaseProviderFormEmptyFile() throws Exception + { + File principalDatabase = TestFileUtils.createTempFile(this, ".user.password"); + try + { + + String providerName = "test-provider"; + Map<String, Object> attributes = new HashMap<>(); + attributes.put(AuthenticationProvider.NAME, providerName); + attributes.put(AuthenticationProvider.TYPE, PlainPasswordDatabaseAuthenticationManager.PROVIDER_TYPE); + attributes.put(ExternalFileBasedAuthenticationManager.PATH, principalDatabase.getAbsolutePath()); + + int responseCode = getRestTestHelper().submitRequest("authenticationprovider/" + providerName, "PUT", attributes); + assertEquals("failed to create authentication provider", 201, responseCode); + + List<Map<String, Object>> providerDetails = getRestTestHelper().getJsonAsList("authenticationprovider/" + providerName); + assertNotNull("Providers details cannot be null", providerDetails); + assertEquals("Unexpected number of providers", 1, providerDetails.size()); + Map<String, Object> provider = providerDetails.get(0); + assertEquals("Unexpected state", State.ACTIVE.toString(), provider.get(AuthenticationProvider.STATE)); + } + finally + { + principalDatabase.delete(); + } + } + + public void testCreatePlainPrincipalDatabaseProviderAddUserAndAuthenticateWithNewUser() throws Exception + { + File principalDatabase = TestFileUtils.createTempFile(this, ".user.passwords"); + try + { + String providerName = "test-provider"; + Map<String, Object> attributes = new HashMap<>(); + attributes.put(AuthenticationProvider.NAME, providerName); + attributes.put(AuthenticationProvider.TYPE, PlainPasswordDatabaseAuthenticationManager.PROVIDER_TYPE); + attributes.put(ExternalFileBasedAuthenticationManager.PATH, principalDatabase.getAbsolutePath()); + + int responseCode = getRestTestHelper().submitRequest("authenticationprovider/" + providerName, "PUT", attributes); + assertEquals("failed to create authentication provider", 201, responseCode); + + String userName = getName(); + String userPassword = "password"; + + Map<String,Object> userAttributes = new HashMap<>(); + userAttributes.put("password", userPassword); + userAttributes.put("name", userName); + + String url = "user/" + providerName; + getRestTestHelper().submitRequest(url, "POST", userAttributes, HttpServletResponse.SC_CREATED); + + Map<String, Object> userDetails = getRestTestHelper().getJsonAsSingletonList(url + "/" + userName); + assertEquals("Unexpected user name", userName, userDetails.get(User.NAME)); + + String portName = "test-port"; + Map<String, Object> portAttributes = new HashMap<String, Object>(); + portAttributes.put(Port.NAME, portName); + portAttributes.put(Port.PORT, getFailingPort()); + portAttributes.put(Port.AUTHENTICATION_PROVIDER, providerName); + + responseCode = getRestTestHelper().submitRequest("port/" + portName, "PUT", portAttributes); + assertEquals("Unexpected response code", 201, responseCode); + + getRestTestHelper().setUsernameAndPassword(userName, userPassword); + + ConnectionURL connectionURL = new AMQConnectionURL("amqp://"+ userName + ":" + userPassword + + "@/?brokerlist='tcp://localhost:"+getFailingPort()+"'"); + Connection connection = getConnection(connectionURL); + try + { + assertTrue("Connection should be successfully established", ((AMQConnection) connection).isConnected()); + } + finally + { + connection.close(); + } + } + finally + { + principalDatabase.delete(); + } } public void testPutCreateNewAnonymousProvider() throws Exception |
