You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by kw...@apache.org on 2018/02/19 07:53:21 UTC
[5/5] qpid-broker-j git commit: QPID-8083: [System Tests] [REST/HTTP]
Eliminate AuthenticationProviderRestTest
QPID-8083: [System Tests] [REST/HTTP] Eliminate AuthenticationProviderRestTest
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/b2f2280e
Tree: http://git-wip-us.apache.org/repos/asf/qpid-broker-j/tree/b2f2280e
Diff: http://git-wip-us.apache.org/repos/asf/qpid-broker-j/diff/b2f2280e
Branch: refs/heads/master
Commit: b2f2280e53cebd01a9353a74e91f6ae3f81cd202
Parents: dbe3ca7
Author: Keith Wall <kw...@apache.org>
Authored: Sat Feb 17 13:37:00 2018 +0000
Committer: Keith Wall <kw...@apache.org>
Committed: Mon Feb 19 07:52:42 2018 +0000
----------------------------------------------------------------------
...sswordDatabaseAuthenticationManagerTest.java | 236 ++++++++++++++
.../rest/AuthenticationProviderRestTest.java | 313 -------------------
2 files changed, 236 insertions(+), 313 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/qpid-broker-j/blob/b2f2280e/broker-core/src/test/java/org/apache/qpid/server/security/auth/manager/PlainPasswordDatabaseAuthenticationManagerTest.java
----------------------------------------------------------------------
diff --git a/broker-core/src/test/java/org/apache/qpid/server/security/auth/manager/PlainPasswordDatabaseAuthenticationManagerTest.java b/broker-core/src/test/java/org/apache/qpid/server/security/auth/manager/PlainPasswordDatabaseAuthenticationManagerTest.java
new file mode 100644
index 0000000..aeb48ea
--- /dev/null
+++ b/broker-core/src/test/java/org/apache/qpid/server/security/auth/manager/PlainPasswordDatabaseAuthenticationManagerTest.java
@@ -0,0 +1,236 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+
+package org.apache.qpid.server.security.auth.manager;
+
+import static org.apache.qpid.server.security.auth.AuthenticationResult.AuthenticationStatus.SUCCESS;
+import static org.apache.qpid.server.security.auth.manager.PlainPasswordDatabaseAuthenticationManager.PROVIDER_TYPE;
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.Matchers.equalTo;
+import static org.junit.Assert.assertThat;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+import java.io.File;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.qpid.server.configuration.updater.CurrentThreadTaskExecutor;
+import org.apache.qpid.server.configuration.updater.TaskExecutor;
+import org.apache.qpid.server.logging.EventLogger;
+import org.apache.qpid.server.model.AuthenticationProvider;
+import org.apache.qpid.server.model.Broker;
+import org.apache.qpid.server.model.BrokerModel;
+import org.apache.qpid.server.model.ConfiguredObjectFactory;
+import org.apache.qpid.server.model.ConfiguredObjectFactoryImpl;
+import org.apache.qpid.server.model.Model;
+import org.apache.qpid.server.model.PasswordCredentialManagingAuthenticationProvider;
+import org.apache.qpid.server.model.User;
+import org.apache.qpid.server.security.auth.AuthenticationResult;
+import org.apache.qpid.test.utils.QpidTestCase;
+import org.apache.qpid.test.utils.TestFileUtils;
+
+public class PlainPasswordDatabaseAuthenticationManagerTest extends QpidTestCase
+{
+ private TaskExecutor _taskExecutor;
+ private Broker<?> _broker;
+ private File _passwordFile;
+ private ConfiguredObjectFactory _objectFactory;
+
+ @Override
+ public void setUp() throws Exception
+ {
+ super.setUp();
+ _taskExecutor = CurrentThreadTaskExecutor.newStartedInstance();
+
+ final Model model = BrokerModel.getInstance();
+ _objectFactory = new ConfiguredObjectFactoryImpl(model);
+
+ _broker = mock(Broker.class);
+ when(_broker.getTaskExecutor()).thenReturn(_taskExecutor);
+ when(_broker.getChildExecutor()).thenReturn(_taskExecutor);
+ when(_broker.getModel()).thenReturn(model);
+ when(_broker.getEventLogger()).thenReturn(mock(EventLogger.class));
+ }
+
+ @Override
+ public void tearDown() throws Exception
+ {
+ try
+ {
+ if (_passwordFile.exists())
+ {
+ _passwordFile.delete();
+ }
+ _taskExecutor.stop();
+ }
+ finally
+ {
+ super.tearDown();
+ }
+ }
+
+ public void testExistingPasswordFile()
+ {
+ _passwordFile = TestFileUtils.createTempFile(this, ".user.password", "user:password");
+
+ Map<String, Object> providerAttrs = new HashMap<>();
+ providerAttrs.put(PlainPasswordDatabaseAuthenticationManager.TYPE, PROVIDER_TYPE);
+ providerAttrs.put(PlainPasswordDatabaseAuthenticationManager.PATH, _passwordFile.getAbsolutePath());
+ providerAttrs.put(PlainPasswordDatabaseAuthenticationManager.NAME, getTestName());
+
+ @SuppressWarnings("unchecked")
+ AuthenticationProvider provider = _objectFactory.create(AuthenticationProvider.class, providerAttrs, _broker);
+ assertThat(provider.getChildren(User.class).size(), is(equalTo(1)));
+
+ User user = (User) provider.getChildByName(User.class, "user");
+ assertThat(user.getName(), is(equalTo("user")));
+ }
+
+ public void testAddUser()
+ {
+ _passwordFile = TestFileUtils.createTempFile(this, ".user.password");
+
+ Map<String, Object> providerAttrs = new HashMap<>();
+ providerAttrs.put(PlainPasswordDatabaseAuthenticationManager.TYPE, PROVIDER_TYPE);
+ providerAttrs.put(PlainPasswordDatabaseAuthenticationManager.PATH, _passwordFile.getAbsolutePath());
+ providerAttrs.put(PlainPasswordDatabaseAuthenticationManager.NAME, getTestName());
+
+ AuthenticationProvider provider = _objectFactory.create(AuthenticationProvider.class, providerAttrs, _broker);
+ assertThat(provider.getChildren(User.class).size(), is(equalTo(0)));
+
+ Map<String, Object> userAttrs = new HashMap<>();
+ userAttrs.put(User.TYPE, PROVIDER_TYPE);
+ userAttrs.put(User.NAME, "user");
+ userAttrs.put(User.PASSWORD, "password");
+ User user = (User) provider.createChild(User.class, userAttrs);
+
+ assertThat(provider.getChildren(User.class).size(), is(equalTo(1)));
+ assertThat(user.getName(), is(equalTo("user")));
+ }
+
+ public void testRemoveUser()
+ {
+ _passwordFile = TestFileUtils.createTempFile(this, ".user.password", "user:password");
+
+ Map<String, Object> providerAttrs = new HashMap<>();
+ providerAttrs.put(PlainPasswordDatabaseAuthenticationManager.TYPE, PROVIDER_TYPE);
+ providerAttrs.put(PlainPasswordDatabaseAuthenticationManager.PATH, _passwordFile.getAbsolutePath());
+ providerAttrs.put(PlainPasswordDatabaseAuthenticationManager.NAME, getTestName());
+
+ AuthenticationProvider provider = _objectFactory.create(AuthenticationProvider.class, providerAttrs, _broker);
+ assertThat(provider.getChildren(User.class).size(), is(equalTo(1)));
+
+ User user = (User) provider.getChildByName(User.class, "user");
+ user.delete();
+
+ assertThat(provider.getChildren(User.class).size(), is(equalTo(0)));
+ }
+
+ public void testDurability()
+ {
+ _passwordFile = TestFileUtils.createTempFile(this, ".user.password");
+
+ Map<String, Object> providerAttrs = new HashMap<>();
+ providerAttrs.put(PlainPasswordDatabaseAuthenticationManager.TYPE, PROVIDER_TYPE);
+ providerAttrs.put(PlainPasswordDatabaseAuthenticationManager.PATH, _passwordFile.getAbsolutePath());
+ providerAttrs.put(PlainPasswordDatabaseAuthenticationManager.NAME, getTestName());
+
+ {
+ AuthenticationProvider provider =
+ _objectFactory.create(AuthenticationProvider.class, providerAttrs, _broker);
+ assertThat(provider.getChildren(User.class).size(), is(equalTo(0)));
+
+ Map<String, Object> userAttrs = new HashMap<>();
+ userAttrs.put(User.TYPE, PROVIDER_TYPE);
+ userAttrs.put(User.NAME, "user");
+ userAttrs.put(User.PASSWORD, "password");
+ provider.createChild(User.class, userAttrs);
+
+ provider.close();
+ }
+
+ {
+ AuthenticationProvider provider =
+ _objectFactory.create(AuthenticationProvider.class, providerAttrs, _broker);
+ assertThat(provider.getChildren(User.class).size(), is(equalTo(1)));
+
+ User user = (User) provider.getChildByName(User.class, "user");
+ user.delete();
+
+ provider.close();
+ }
+
+ {
+ AuthenticationProvider provider =
+ _objectFactory.create(AuthenticationProvider.class, providerAttrs, _broker);
+ assertThat(provider.getChildren(User.class).size(), is(equalTo(0)));
+
+ provider.close();
+ }
+ }
+
+ public void testAuthenticate()
+ {
+ _passwordFile = TestFileUtils.createTempFile(this, ".user.password", "user:password");
+
+ String file = _passwordFile.getAbsolutePath();
+ Map<String, Object> providerAttrs = new HashMap<>();
+ providerAttrs.put(PlainPasswordDatabaseAuthenticationManager.TYPE, PROVIDER_TYPE);
+ providerAttrs.put(PlainPasswordDatabaseAuthenticationManager.PATH, file);
+ providerAttrs.put(PlainPasswordDatabaseAuthenticationManager.NAME, getTestName());
+
+ PasswordCredentialManagingAuthenticationProvider provider =
+ ((PasswordCredentialManagingAuthenticationProvider) _objectFactory.create(AuthenticationProvider.class,
+ providerAttrs,
+ _broker));
+
+ {
+ AuthenticationResult result = provider.authenticate("user", "password");
+ assertThat(result.getStatus(), is(equalTo(SUCCESS)));
+ }
+
+ {
+ AuthenticationResult result = provider.authenticate("user", "badpassword");
+ assertThat(result.getStatus(), is(equalTo(AuthenticationResult.AuthenticationStatus.ERROR)));
+ }
+
+ {
+ AuthenticationResult result = provider.authenticate("unknownuser", "badpassword");
+ assertThat(result.getStatus(), is(equalTo(AuthenticationResult.AuthenticationStatus.ERROR)));
+ }
+ }
+
+ public void testDeleteProvider()
+ {
+ _passwordFile = TestFileUtils.createTempFile(this, ".user.password", "user:password");
+
+ Map<String, Object> providerAttrs = new HashMap<>();
+ providerAttrs.put(PlainPasswordDatabaseAuthenticationManager.TYPE, PROVIDER_TYPE);
+ providerAttrs.put(PlainPasswordDatabaseAuthenticationManager.PATH, _passwordFile.getAbsolutePath());
+ providerAttrs.put(PlainPasswordDatabaseAuthenticationManager.NAME, getTestName());
+
+ AuthenticationProvider provider = _objectFactory.create(AuthenticationProvider.class, providerAttrs, _broker);
+ provider.delete();
+
+ assertThat(_passwordFile.exists(), is(equalTo(false)));
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/qpid-broker-j/blob/b2f2280e/systests/src/test/java/org/apache/qpid/systest/rest/AuthenticationProviderRestTest.java
----------------------------------------------------------------------
diff --git a/systests/src/test/java/org/apache/qpid/systest/rest/AuthenticationProviderRestTest.java b/systests/src/test/java/org/apache/qpid/systest/rest/AuthenticationProviderRestTest.java
deleted file mode 100644
index 214c701..0000000
--- a/systests/src/test/java/org/apache/qpid/systest/rest/AuthenticationProviderRestTest.java
+++ /dev/null
@@ -1,313 +0,0 @@
-/*
- *
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- *
- */
-package org.apache.qpid.systest.rest;
-
-import static javax.servlet.http.HttpServletResponse.SC_CONFLICT;
-import static javax.servlet.http.HttpServletResponse.SC_CREATED;
-
-import java.io.File;
-import java.io.IOException;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.UUID;
-
-import javax.servlet.http.HttpServletResponse;
-
-import org.apache.qpid.server.management.plugin.servlet.rest.AbstractServlet;
-import org.apache.qpid.server.model.AuthenticationProvider;
-import org.apache.qpid.server.model.BrokerModel;
-import org.apache.qpid.server.model.ConfiguredObject;
-import org.apache.qpid.server.model.ExternalFileBasedAuthenticationManager;
-import org.apache.qpid.server.model.LifetimePolicy;
-import org.apache.qpid.server.model.Port;
-import org.apache.qpid.server.model.State;
-import org.apache.qpid.server.model.SystemConfig;
-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
-{
-
- public void testGet() throws Exception
- {
- List<Map<String, Object>> providerDetails = getRestTestHelper().getJsonAsList("authenticationprovider");
- assertNotNull("Providers details cannot be null", providerDetails);
- assertEquals("Unexpected number of providers", 1, providerDetails.size());
- for (Map<String, Object> provider : providerDetails)
- {
- boolean managesPrincipals = true;
- String type = PlainPasswordDatabaseAuthenticationManager.PROVIDER_TYPE;
- assertProvider(managesPrincipals, type , provider);
- Map<String, Object> data = getRestTestHelper().getJsonAsMap("authenticationprovider/"
- + provider.get(AuthenticationProvider.NAME));
- assertNotNull("Cannot load data for " + provider.get(AuthenticationProvider.NAME), data);
- assertProvider(managesPrincipals, type, data);
- }
- }
-
- public void testPutCreateSecondPlainPrincipalDatabaseProviderSucceeds() throws Exception
- {
- File principalDatabase = getDefaultBrokerConfiguration().createTemporaryPasswordFile(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());
-
- 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());
-
- getRestTestHelper().submitRequest("authenticationprovider/" + providerName, "PUT", attributes, SC_CREATED);
-
- Map<String, Object> providerDetails = getRestTestHelper().getJsonAsMap("authenticationprovider/" + providerName);
- assertEquals("Unexpected state", State.ACTIVE.toString(), providerDetails.get(AuthenticationProvider.STATE));
- }
- finally
- {
- principalDatabase.delete();
- }
- }
- public void testPutCreateNewAnonymousProvider() throws Exception
- {
- String providerName = "test-provider";
- Map<String, Object> attributes = new HashMap<String, Object>();
- attributes.put(AuthenticationProvider.NAME, providerName);
- attributes.put(AuthenticationProvider.TYPE, AnonymousAuthenticationManager.PROVIDER_TYPE);
-
- getRestTestHelper().submitRequest("authenticationprovider/" + providerName, "PUT", attributes, SC_CREATED);
-
- Map<String, Object> providerDetails = getRestTestHelper().getJsonAsMap("authenticationprovider/" + providerName);
- assertProvider(false, AnonymousAuthenticationManager.PROVIDER_TYPE, providerDetails);
- }
-
- public void testUpdateAuthenticationProviderIdFails() throws Exception
- {
- String providerName = "test-provider";
- Map<String, Object> attributes = new HashMap<String, Object>();
- attributes.put(AuthenticationProvider.NAME, providerName);
- attributes.put(AuthenticationProvider.TYPE, AnonymousAuthenticationManager.PROVIDER_TYPE);
-
- int responseCode = getRestTestHelper().submitRequest("authenticationprovider/" + providerName, "PUT", attributes);
- assertEquals("Unexpected response code", 201, responseCode);
-
- attributes.put(AuthenticationProvider.ID, UUID.randomUUID());
-
- responseCode = getRestTestHelper().submitRequest("authenticationprovider/" + providerName, "PUT", attributes);
- assertEquals("Update with new ID should fail", AbstractServlet.SC_UNPROCESSABLE_ENTITY, responseCode);
- }
-
- public void testDeleteOfUsedAuthenticationProviderFails() throws Exception
- {
- // create provider
- String providerName = "test-provider";
- Map<String, Object> attributes = new HashMap<String, Object>();
- attributes.put(AuthenticationProvider.NAME, providerName);
- attributes.put(AuthenticationProvider.TYPE, AnonymousAuthenticationManager.PROVIDER_TYPE);
-
- int responseCode = getRestTestHelper().submitRequest("authenticationprovider/" + providerName, "PUT", attributes);
- assertEquals("Unexpected response code for provider creation", 201, responseCode);
-
- // create port
- String portName = "test-port";
- Map<String, Object> portAttributes = new HashMap<String, Object>();
- portAttributes.put(Port.NAME, portName);
- portAttributes.put(Port.AUTHENTICATION_PROVIDER, providerName);
- portAttributes.put(Port.PORT, 0);
-
- getRestTestHelper().submitRequest("port/" + portName, "PUT", portAttributes, SC_CREATED);
- getRestTestHelper().submitRequest("authenticationprovider/" + providerName , "DELETE", SC_CONFLICT);
-
- Map<String, Object> providerDetails = getRestTestHelper().getJsonAsMap("authenticationprovider/" + providerName);
- assertProvider(false, AnonymousAuthenticationManager.PROVIDER_TYPE, providerDetails);
- }
-
- public void testDeleteOfUnusedAuthenticationProvider() throws Exception
- {
- // create provider
- String providerName = "test-provider";
- Map<String, Object> attributes = new HashMap<String, Object>();
- attributes.put(AuthenticationProvider.NAME, providerName);
- attributes.put(AuthenticationProvider.TYPE, AnonymousAuthenticationManager.PROVIDER_TYPE);
-
- int responseCode = getRestTestHelper().submitRequest("authenticationprovider/" + providerName, "PUT", attributes);
- assertEquals("Unexpected response code for provider creation", 201, responseCode);
-
- responseCode = getRestTestHelper().submitRequest("authenticationprovider/" + providerName , "DELETE");
- assertEquals("Unexpected response code for provider deletion", 200, responseCode);
-
- getRestTestHelper().submitRequest("authenticationprovider/" + providerName, "GET", HttpServletResponse.SC_NOT_FOUND);
- }
-
- public void testRemovalOfAuthenticationProviderInErrorStateUsingManagementMode() throws Exception
- {
- stopDefaultBroker();
-
- File file = new File(TMP_FOLDER, getTestName());
- if (file.exists())
- {
- file.delete();
- }
- assertFalse("Group file should not exist", file.exists());
-
- TestBrokerConfiguration config = getDefaultBrokerConfiguration();
-
- String providerName = getTestName();
- Map<String, Object> attributes = new HashMap<>();
- attributes.put(AuthenticationProvider.TYPE, PlainPasswordDatabaseAuthenticationManager.PROVIDER_TYPE);
- attributes.put(AuthenticationProvider.NAME, providerName);
- attributes.put(ExternalFileBasedAuthenticationManager.PATH, file.getAbsoluteFile());
-
- UUID id = config.addObjectConfiguration(AuthenticationProvider.class, attributes);
- config.setSaved(false);
- startDefaultBroker(true);
-
- getRestTestHelper().setUsernameAndPassword(SystemConfig.MANAGEMENT_MODE_USER_NAME, MANAGEMENT_MODE_PASSWORD);
-
- Map<String, Object> provider = getRestTestHelper().getJsonAsMap("authenticationprovider/" + providerName);
- assertEquals("Unexpected id", id.toString(), provider.get(AuthenticationProvider.ID));
- assertEquals("Unexpected name", providerName, provider.get(AuthenticationProvider.NAME));
- assertEquals("Unexpected path", file.getAbsolutePath() , provider.get(ExternalFileBasedAuthenticationManager.PATH));
- assertEquals("Unexpected state", State.ERRORED.name() , provider.get(AuthenticationProvider.STATE));
-
- int status = getRestTestHelper().submitRequest("authenticationprovider/" + providerName, "DELETE");
- assertEquals("ACL was not deleted", 200, status);
-
- getRestTestHelper().submitRequest("authenticationprovider/" + providerName, "GET", HttpServletResponse.SC_NOT_FOUND);
- }
-
- public void testUpdateOfAuthenticationProviderInErrorStateUsingManagementMode() throws Exception
- {
- stopDefaultBroker();
-
- final File file = new File(TMP_FOLDER, getTestName());
- file.deleteOnExit();
- if (file.exists())
- {
- file.delete();
- }
- assertFalse(String.format("File '%s' should not exist", file), file.exists());
-
- TestBrokerConfiguration config = getDefaultBrokerConfiguration();
-
- String providerName = getTestName();
- Map<String, Object> attributes = new HashMap<String, Object>();
- attributes.put(AuthenticationProvider.TYPE, PlainPasswordDatabaseAuthenticationManager.PROVIDER_TYPE);
- attributes.put(AuthenticationProvider.NAME, providerName);
- attributes.put(ExternalFileBasedAuthenticationManager.PATH, file.getAbsoluteFile());
-
- UUID id = config.addObjectConfiguration(AuthenticationProvider.class, attributes);
- config.setSaved(false);
- startDefaultBroker(true);
-
- getRestTestHelper().setUsernameAndPassword(SystemConfig.MANAGEMENT_MODE_USER_NAME, MANAGEMENT_MODE_PASSWORD);
-
- Map<String, Object> provider = getRestTestHelper().getJsonAsMap("authenticationprovider/" + providerName);
- assertEquals("Unexpected id", id.toString(), provider.get(AuthenticationProvider.ID));
- assertEquals("Unexpected name", providerName, provider.get(AuthenticationProvider.NAME));
- assertEquals("Unexpected path", file.getAbsolutePath() , provider.get(ExternalFileBasedAuthenticationManager.PATH));
- assertEquals("Unexpected state", State.ERRORED.name() , provider.get(AuthenticationProvider.STATE));
-
- File principalDatabase = null;
- try
- {
- principalDatabase = getDefaultBrokerConfiguration().createTemporaryPasswordFile(new String[]{"admin2", "guest2", "test2"});
- attributes = new HashMap<>();
- attributes.put(AuthenticationProvider.NAME, providerName);
- attributes.put(AuthenticationProvider.ID, id);
- attributes.put(AuthenticationProvider.TYPE, PlainPasswordDatabaseAuthenticationManager.PROVIDER_TYPE);
-
- file.createNewFile();
-
- int status = getRestTestHelper().submitRequest("authenticationprovider/" + providerName, "PUT", attributes);
- assertEquals("ACL was not deleted", 200, status);
-
- provider = getRestTestHelper().getJsonAsMap("authenticationprovider/" + providerName);
- assertEquals("Unexpected id", id.toString(), provider.get(AuthenticationProvider.ID));
- assertEquals("Unexpected name", providerName, provider.get(AuthenticationProvider.NAME));
- assertEquals("Unexpected path", file.getAbsolutePath() , provider.get(
- ExternalFileBasedAuthenticationManager.PATH));
- assertEquals("Unexpected state", State.ACTIVE.name() , provider.get(AuthenticationProvider.STATE));
- }
- finally
- {
- if (principalDatabase != null)
- {
- principalDatabase.delete();
- }
- file.delete();
- }
- }
-
- private void assertProvider(boolean managesPrincipals, String type, Map<String, Object> provider) throws IOException
- {
- Asserts.assertAttributesPresent(provider, BrokerModel.getInstance().getTypeRegistry().getAttributeNames(
- AuthenticationProvider.class),
- AuthenticationProvider.DESCRIPTION, ConfiguredObject.CONTEXT,
- ConfiguredObject.DESIRED_STATE, ConfiguredObject.CREATED_BY,
- ConfiguredObject.CREATED_TIME, ConfiguredObject.LAST_UPDATED_BY, ConfiguredObject.LAST_UPDATED_TIME);
- assertEquals("Unexpected value of provider attribute " + AuthenticationProvider.STATE, State.ACTIVE.name(),
- provider.get(AuthenticationProvider.STATE));
- assertEquals("Unexpected value of provider attribute " + AuthenticationProvider.LIFETIME_POLICY,
- LifetimePolicy.PERMANENT.name(), provider.get(AuthenticationProvider.LIFETIME_POLICY));
- assertEquals("Unexpected value of provider attribute " + AuthenticationProvider.DURABLE, Boolean.TRUE,
- provider.get(AuthenticationProvider.DURABLE));
- assertEquals("Unexpected value of provider attribute " + AuthenticationProvider.TYPE, type,
- provider.get(AuthenticationProvider.TYPE));
-
- if (managesPrincipals)
- {
- List<Map<String, Object>> users =
- getRestTestHelper().getJsonAsList("user/" + provider.get(AuthenticationProvider.NAME));
- assertNotNull("Users are not found", users);
- assertTrue("Unexpected number of users", users.size() > 1);
- for (Map<String, Object> user : users)
- {
- assertNotNull("Attribute " + User.ID, user.get(User.ID));
- assertNotNull("Attribute " + User.NAME, user.get(User.NAME));
- }
- }
- }
-}
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org