Return-Path: X-Original-To: apmail-qpid-commits-archive@www.apache.org Delivered-To: apmail-qpid-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id BDAC417A3F for ; Mon, 6 Apr 2015 12:46:58 +0000 (UTC) Received: (qmail 69004 invoked by uid 500); 6 Apr 2015 12:46:58 -0000 Delivered-To: apmail-qpid-commits-archive@qpid.apache.org Received: (qmail 68978 invoked by uid 500); 6 Apr 2015 12:46:58 -0000 Mailing-List: contact commits-help@qpid.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@qpid.apache.org Delivered-To: mailing list commits@qpid.apache.org Received: (qmail 68968 invoked by uid 99); 6 Apr 2015 12:46:58 -0000 Received: from eris.apache.org (HELO hades.apache.org) (140.211.11.105) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 06 Apr 2015 12:46:58 +0000 Received: from hades.apache.org (localhost [127.0.0.1]) by hades.apache.org (ASF Mail Server at hades.apache.org) with ESMTP id 6A4DBAC0044 for ; Mon, 6 Apr 2015 12:46:58 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1671526 - in /qpid/trunk/qpid/java: broker-core/src/main/java/org/apache/qpid/server/security/auth/manager/PrincipalDatabaseAuthenticationManager.java systests/src/test/java/org/apache/qpid/systest/rest/AuthenticationProviderRestTest.java Date: Mon, 06 Apr 2015 12:46:58 -0000 To: commits@qpid.apache.org From: orudyy@apache.org X-Mailer: svnmailer-1.0.9 Message-Id: <20150406124658.6A4DBAC0044@hades.apache.org> Author: orudyy Date: Mon Apr 6 12:46:57 2015 New Revision: 1671526 URL: http://svn.apache.org/r1671526 Log: QPID-6478: Set state to ACTIVE on creation of file based authentication provider when empty or non existing user file is specified Modified: qpid/trunk/qpid/java/broker-core/src/main/java/org/apache/qpid/server/security/auth/manager/PrincipalDatabaseAuthenticationManager.java qpid/trunk/qpid/java/systests/src/test/java/org/apache/qpid/systest/rest/AuthenticationProviderRestTest.java Modified: qpid/trunk/qpid/java/broker-core/src/main/java/org/apache/qpid/server/security/auth/manager/PrincipalDatabaseAuthenticationManager.java URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/broker-core/src/main/java/org/apache/qpid/server/security/auth/manager/PrincipalDatabaseAuthenticationManager.java?rev=1671526&r1=1671525&r2=1671526&view=diff ============================================================================== --- qpid/trunk/qpid/java/broker-core/src/main/java/org/apache/qpid/server/security/auth/manager/PrincipalDatabaseAuthenticationManager.java (original) +++ qpid/trunk/qpid/java/broker-core/src/main/java/org/apache/qpid/server/security/auth/manager/PrincipalDatabaseAuthenticationManager.java Mon Apr 6 12:46:57 2015 @@ -246,6 +246,7 @@ public abstract class PrincipalDatabaseA } else { + setState(State.ACTIVE); return Futures.immediateFuture(null); } } Modified: qpid/trunk/qpid/java/systests/src/test/java/org/apache/qpid/systest/rest/AuthenticationProviderRestTest.java URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/systests/src/test/java/org/apache/qpid/systest/rest/AuthenticationProviderRestTest.java?rev=1671526&r1=1671525&r2=1671526&view=diff ============================================================================== --- qpid/trunk/qpid/java/systests/src/test/java/org/apache/qpid/systest/rest/AuthenticationProviderRestTest.java (original) +++ qpid/trunk/qpid/java/systests/src/test/java/org/apache/qpid/systest/rest/AuthenticationProviderRestTest.java Mon Apr 6 12:46:57 2015 @@ -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 AuthenticationProviderRestT public void testPutCreateSecondPlainPrincipalDatabaseProviderSucceeds() throws Exception { File principalDatabase = getRestTestHelper().createTemporaryPasswdFile(new String[]{"admin2", "guest2", "test2"}); + try + { + + String providerName = "test-provider"; + Map 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); + } + finally + { + principalDatabase.delete(); + } + } + + public void testCreatePlainPrincipalDatabaseProviderFormEmptyFile() throws Exception + { + File principalDatabase = TestFileUtils.createTempFile(this, ".user.password"); + try + { - String providerName = "test-provider"; - Map attributes = new HashMap(); - attributes.put(AuthenticationProvider.NAME, providerName); - attributes.put(AuthenticationProvider.TYPE, PlainPasswordDatabaseAuthenticationManager.PROVIDER_TYPE); - attributes.put(ExternalFileBasedAuthenticationManager.PATH, principalDatabase.getAbsolutePath()); + String providerName = "test-provider"; + Map 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> providerDetails = getRestTestHelper().getJsonAsList("authenticationprovider/" + providerName); + assertNotNull("Providers details cannot be null", providerDetails); + assertEquals("Unexpected number of providers", 1, providerDetails.size()); + Map provider = providerDetails.get(0); + assertEquals("Unexpected state", State.ACTIVE.toString(), provider.get(AuthenticationProvider.STATE)); + } + finally + { + principalDatabase.delete(); + } + } - int responseCode = getRestTestHelper().submitRequest("authenticationprovider/" + providerName, "PUT", attributes); - assertEquals("failed to create authentication provider", 201, responseCode); + public void testCreatePlainPrincipalDatabaseProviderAddUserAndAuthenticateWithNewUser() throws Exception + { + File principalDatabase = TestFileUtils.createTempFile(this, ".user.passwords"); + try + { + String providerName = "test-provider"; + Map 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 userAttributes = new HashMap<>(); + userAttributes.put("password", userPassword); + userAttributes.put("name", userName); + + String url = "user/" + providerName; + getRestTestHelper().submitRequest(url, "POST", userAttributes, HttpServletResponse.SC_CREATED); + + Map userDetails = getRestTestHelper().getJsonAsSingletonList(url + "/" + userName); + assertEquals("Unexpected user name", userName, userDetails.get(User.NAME)); + + String portName = "test-port"; + Map portAttributes = new HashMap(); + 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 --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org For additional commands, e-mail: commits-help@qpid.apache.org