diff options
| author | Robert Gemmell <robbie@apache.org> | 2013-04-29 13:50:09 +0000 |
|---|---|---|
| committer | Robert Gemmell <robbie@apache.org> | 2013-04-29 13:50:09 +0000 |
| commit | 592a967141635e00f9bbefb8c2a2236f8fe62f27 (patch) | |
| tree | 1516abb58778c8a8f10b1ab671e70cad3d7699d1 /qpid/java/broker/src/test | |
| parent | e73e575362d883519a03ee3a9d87ef4cb92f87a7 (diff) | |
| download | qpid-python-592a967141635e00f9bbefb8c2a2236f8fe62f27.tar.gz | |
QPID-4784: stop generating errors during creation of PDAM's due to duplicate sasl provider registration, simplify PDAM.
git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk@1477078 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'qpid/java/broker/src/test')
4 files changed, 28 insertions, 280 deletions
diff --git a/qpid/java/broker/src/test/java/org/apache/qpid/server/model/BrokerShutdownTest.java b/qpid/java/broker/src/test/java/org/apache/qpid/server/model/BrokerShutdownTest.java deleted file mode 100644 index eb5c672eb8..0000000000 --- a/qpid/java/broker/src/test/java/org/apache/qpid/server/model/BrokerShutdownTest.java +++ /dev/null @@ -1,190 +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.server.model; - -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; - -import org.apache.qpid.server.BrokerOptions; -import org.apache.qpid.server.configuration.ConfigurationEntry; -import org.apache.qpid.server.configuration.ConfigurationEntryStore; -import org.apache.qpid.server.configuration.ConfiguredObjectRecoverer; -import org.apache.qpid.server.configuration.RecovererProvider; -import org.apache.qpid.server.configuration.startup.DefaultRecovererProvider; -import org.apache.qpid.server.logging.LogRecorder; -import org.apache.qpid.server.logging.RootMessageLogger; -import org.apache.qpid.server.model.AuthenticationProvider; -import org.apache.qpid.server.model.Broker; -import org.apache.qpid.server.model.ConfiguredObject; -import org.apache.qpid.server.model.State; -import org.apache.qpid.server.configuration.updater.TaskExecutor; -import org.apache.qpid.server.plugin.AuthenticationManagerFactory; -import org.apache.qpid.server.security.auth.manager.PlainPasswordFileAuthenticationManagerFactory; -import org.apache.qpid.server.stats.StatisticsGatherer; -import org.apache.qpid.server.virtualhost.VirtualHostRegistry; -import org.apache.qpid.test.utils.QpidTestCase; -import org.apache.qpid.test.utils.TestFileUtils; - -import java.io.File; -import java.security.Provider; -import java.security.Security; -import java.util.Collections; -import java.util.HashMap; -import java.util.LinkedList; -import java.util.List; -import java.util.Map; -import java.util.UUID; - -/** - * QPID-1390 : Test to validate that the AuthenticationManger can successfully unregister any new SASL providers when - * the broker is stopped. - */ -public class BrokerShutdownTest extends QpidTestCase -{ - private Provider[] _defaultProviders; - private Broker _broker; - private TaskExecutor _taskExecutor; - - @Override - public void setUp() throws Exception - { - // Get default providers - _defaultProviders = Security.getProviders(); - - super.setUp(); - - _taskExecutor = new TaskExecutor(); - _taskExecutor.start(); - - // Startup the new broker and register the new providers - _broker = startBroker(); - } - - @Override - public void tearDown() throws Exception - { - try - { - super.tearDown(); - } - finally - { - if (_taskExecutor != null) - { - _taskExecutor.stopImmediately(); - } - } - - } - - private Broker startBroker() throws Exception - { - ConfigurationEntryStore store = mock(ConfigurationEntryStore.class); - UUID brokerId = UUID.randomUUID(); - UUID authenticationProviderId = UUID.randomUUID(); - - ConfigurationEntry root = new ConfigurationEntry(brokerId, Broker.class.getSimpleName(), Collections.<String, Object> emptyMap(), - Collections.singleton(authenticationProviderId), store); - - File file = TestFileUtils.createTempFile(BrokerShutdownTest.this, ".db.users"); - Map<String, Object> attributes = new HashMap<String, Object>(); - attributes.put(AuthenticationManagerFactory.ATTRIBUTE_TYPE, PlainPasswordFileAuthenticationManagerFactory.PROVIDER_TYPE); - attributes.put(PlainPasswordFileAuthenticationManagerFactory.ATTRIBUTE_PATH, file.getAbsolutePath()); - ConfigurationEntry authenticationProviderEntry = new ConfigurationEntry(authenticationProviderId, AuthenticationProvider.class.getSimpleName(), attributes, - Collections.<UUID> emptySet(), store); - - when(store.getRootEntry()).thenReturn(root); - when(store.getEntry(brokerId)).thenReturn(root); - when(store.getEntry(authenticationProviderId)).thenReturn(authenticationProviderEntry); - - // mocking the required object - StatisticsGatherer statisticsGatherer = mock(StatisticsGatherer.class); - VirtualHostRegistry virtualHostRegistry = mock(VirtualHostRegistry.class); - LogRecorder logRecorder = mock(LogRecorder.class); - RootMessageLogger rootMessageLogger = mock(RootMessageLogger.class); - - // recover the broker from the store - RecovererProvider provider = new DefaultRecovererProvider(statisticsGatherer, virtualHostRegistry, logRecorder, rootMessageLogger, _taskExecutor, mock(BrokerOptions.class)); - ConfiguredObjectRecoverer<? extends ConfiguredObject> brokerRecoverer = provider.getRecoverer(Broker.class.getSimpleName()); - - Broker broker = (Broker) brokerRecoverer.create(provider, store.getRootEntry()); - - // start broker - broker.setDesiredState(State.INITIALISING, State.ACTIVE); - return broker; - } - - private void stopBroker() - { - _broker.setDesiredState(State.ACTIVE, State.STOPPED); - } - - /** - * QPID-1399 : Ensure that the Authentication manager unregisters any SASL providers created during - * broker start-up. - * - */ - public void testAuthenticationMangerCleansUp() throws Exception - { - - // Get the providers after initialisation - Provider[] providersAfterInitialisation = Security.getProviders(); - - // Find the additions - List<Provider> additions = new LinkedList<Provider>(); - for (Provider afterInit : providersAfterInitialisation) - { - boolean found = false; - for (Provider defaultProvider : _defaultProviders) - { - if (defaultProvider == afterInit) - { - found = true; - break; - } - } - - // Record added registies - if (!found) - { - additions.add(afterInit); - } - } - - assertFalse("No new SASL mechanisms added by initialisation.", additions.isEmpty()); - - // Close the registry which will perform the close the - // AuthenticationManager - stopBroker(); - - // Validate that the SASL plugins have been removed. - Provider[] providersAfterClose = Security.getProviders(); - - assertTrue("No providers unregistered", providersAfterInitialisation.length > providersAfterClose.length); - - // Ensure that the additions are not still present after close(). - for (Provider afterClose : providersAfterClose) - { - assertFalse("Added provider not unregistered", additions.contains(afterClose)); - } - } - -} diff --git a/qpid/java/broker/src/test/java/org/apache/qpid/server/security/auth/manager/PrincipalDatabaseAuthenticationManagerTest.java b/qpid/java/broker/src/test/java/org/apache/qpid/server/security/auth/manager/PrincipalDatabaseAuthenticationManagerTest.java index b505b361fd..cba6058426 100644 --- a/qpid/java/broker/src/test/java/org/apache/qpid/server/security/auth/manager/PrincipalDatabaseAuthenticationManagerTest.java +++ b/qpid/java/broker/src/test/java/org/apache/qpid/server/security/auth/manager/PrincipalDatabaseAuthenticationManagerTest.java @@ -28,10 +28,6 @@ import java.io.File; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.security.Principal; -import java.security.Provider; -import java.security.Security; -import java.util.Collections; -import java.util.HashMap; import java.util.List; import java.util.Map; @@ -46,7 +42,6 @@ import org.apache.qpid.server.security.auth.AuthenticationResult.AuthenticationS import org.apache.qpid.server.security.auth.UsernamePrincipal; import org.apache.qpid.server.security.auth.database.PlainPasswordFilePrincipalDatabase; import org.apache.qpid.server.security.auth.database.PrincipalDatabase; -import org.apache.qpid.server.security.auth.sasl.AuthenticationProviderInitialiser; import org.apache.qpid.server.security.auth.sasl.UsernamePasswordInitialiser; import org.apache.qpid.test.utils.QpidTestCase; @@ -56,6 +51,7 @@ import org.apache.qpid.test.utils.QpidTestCase; */ public class PrincipalDatabaseAuthenticationManagerTest extends QpidTestCase { + private static final String LOCALHOST = "localhost"; private static final String MOCK_MECH_NAME = "MOCK-MECH-NAME"; private static final UsernamePrincipal PRINCIPAL = new UsernamePrincipal("guest"); @@ -92,40 +88,8 @@ public class PrincipalDatabaseAuthenticationManagerTest extends QpidTestCase { _principalDatabase = mock(PrincipalDatabase.class); - AuthenticationProviderInitialiser _mockMechInitialiser = mock(AuthenticationProviderInitialiser.class); - Map<String, AuthenticationProviderInitialiser> _initialisers = Collections.singletonMap(MOCK_MECH_NAME, _mockMechInitialiser); - - when(_principalDatabase.getMechanisms()).thenReturn(_initialisers); - - _manager = new PrincipalDatabaseAuthenticationManager(_principalDatabase, _passwordFileLocation); - _manager.initialise(); - } - - private void setupMocksWithInitialiser() throws Exception - { - _principalDatabase = mock(PrincipalDatabase.class); - - UsernamePasswordInitialiser usernamePasswordInitialiser = new UsernamePasswordInitialiser() - { - @Override - public Class<? extends SaslServerFactory> getServerFactoryClassForJCARegistration() - { - return MySaslServerFactory.class; - } - - @Override - public String getMechanismName() - { - return MOCK_MECH_NAME; - } - }; - - Map<String,AuthenticationProviderInitialiser> initialisers = new HashMap<String, AuthenticationProviderInitialiser>(); - initialisers.put(MOCK_MECH_NAME, usernamePasswordInitialiser); - - when(_principalDatabase.getMechanisms()).thenReturn(initialisers); - - usernamePasswordInitialiser.initialise(_principalDatabase); + when(_principalDatabase.getMechanisms()).thenReturn(MOCK_MECH_NAME); + when(_principalDatabase.createSaslServer(MOCK_MECH_NAME, LOCALHOST, null)).thenReturn(new MySaslServer(false, true)); _manager = new PrincipalDatabaseAuthenticationManager(_principalDatabase, _passwordFileLocation); _manager.initialise(); @@ -175,32 +139,14 @@ public class PrincipalDatabaseAuthenticationManagerTest extends QpidTestCase } /** - * Tests that the PDAM registers SASL mechanisms correctly with the runtime. - */ - public void testRegisteredMechanisms() throws Exception - { - //Ensure we haven't registered anything yet (though this would really indicate a prior test failure!) - Provider qpidProvider = Security.getProvider(AuthenticationManager.PROVIDER_NAME); - assertNull(qpidProvider); - - setupMocksWithInitialiser(); - - assertNotNull(_manager.getMechanisms()); - assertEquals(MOCK_MECH_NAME, _manager.getMechanisms()); - - qpidProvider = Security.getProvider(AuthenticationManager.PROVIDER_NAME); - assertNotNull(qpidProvider); - } - - /** * Tests that the SASL factory method createSaslServer correctly * returns a non-null implementation. */ public void testSaslMechanismCreation() throws Exception { - setupMocksWithInitialiser(); + setupMocks(); - SaslServer server = _manager.createSaslServer(MOCK_MECH_NAME, "localhost", null); + SaslServer server = _manager.createSaslServer(MOCK_MECH_NAME, LOCALHOST, null); assertNotNull(server); // Merely tests the creation of the mechanism. Mechanisms themselves are tested // by their own tests. @@ -280,24 +226,6 @@ public class PrincipalDatabaseAuthenticationManagerTest extends QpidTestCase assertEquals(AuthenticationStatus.CONTINUE, result.getStatus()); } - /** - * Tests the ability to de-register the provider. - */ - public void testClose() throws Exception - { - setupMocksWithInitialiser(); - - assertEquals(MOCK_MECH_NAME, _manager.getMechanisms()); - assertNotNull(Security.getProvider(AuthenticationManager.PROVIDER_NAME)); - - _manager.close(); - - // Check provider has been removed. - assertNull(_manager.getMechanisms()); - assertNull(Security.getProvider(AuthenticationManager.PROVIDER_NAME)); - _manager = null; - } - public void testOnCreate() throws Exception { setupMocks(); diff --git a/qpid/java/broker/src/test/java/org/apache/qpid/server/security/auth/sasl/CRAMMD5HexServerTest.java b/qpid/java/broker/src/test/java/org/apache/qpid/server/security/auth/sasl/CRAMMD5HexServerTest.java index 629e1b4cf5..b3e929dd6c 100644 --- a/qpid/java/broker/src/test/java/org/apache/qpid/server/security/auth/sasl/CRAMMD5HexServerTest.java +++ b/qpid/java/broker/src/test/java/org/apache/qpid/server/security/auth/sasl/CRAMMD5HexServerTest.java @@ -69,7 +69,7 @@ public class CRAMMD5HexServerTest extends TestCase _saslServer = _saslFactory.createSaslServer(CRAMMD5HexSaslServer.MECHANISM, "AMQP", "localhost", - _initializer.getProperties(), + null, _initializer.getCallbackHandler()); assertNotNull("Unable to create saslServer with mechanism type " + CRAMMD5HexSaslServer.MECHANISM, _saslServer); diff --git a/qpid/java/broker/src/test/java/org/apache/qpid/server/security/auth/sasl/TestPrincipalDatabase.java b/qpid/java/broker/src/test/java/org/apache/qpid/server/security/auth/sasl/TestPrincipalDatabase.java index 5e66bc9336..17c63d738c 100644 --- a/qpid/java/broker/src/test/java/org/apache/qpid/server/security/auth/sasl/TestPrincipalDatabase.java +++ b/qpid/java/broker/src/test/java/org/apache/qpid/server/security/auth/sasl/TestPrincipalDatabase.java @@ -21,16 +21,17 @@ package org.apache.qpid.server.security.auth.sasl; -import org.apache.qpid.server.security.auth.database.PrincipalDatabase; - -import javax.security.auth.callback.PasswordCallback; -import javax.security.auth.login.AccountNotFoundException; - import java.io.File; import java.io.IOException; import java.security.Principal; import java.util.List; -import java.util.Map; + +import javax.security.auth.callback.PasswordCallback; +import javax.security.auth.login.AccountNotFoundException; +import javax.security.sasl.SaslException; +import javax.security.sasl.SaslServer; + +import org.apache.qpid.server.security.auth.database.PrincipalDatabase; public class TestPrincipalDatabase implements PrincipalDatabase { @@ -47,12 +48,6 @@ public class TestPrincipalDatabase implements PrincipalDatabase return false; } - public Map<String, AuthenticationProviderInitialiser> getMechanisms() - { - // TODO Auto-generated method stub - return null; - } - public Principal getUser(String username) { // TODO Auto-generated method stub @@ -94,4 +89,19 @@ public class TestPrincipalDatabase implements PrincipalDatabase // TODO Auto-generated method stub } + @Override + public String getMechanisms() + { + // TODO Auto-generated method stub + return null; + } + + @Override + public SaslServer createSaslServer(String mechanism, String localFQDN, + Principal externalPrincipal) throws SaslException + { + // TODO Auto-generated method stub + return null; + } + } |
