diff options
author | Alex Rudyy <orudyy@apache.org> | 2013-10-05 00:22:31 +0000 |
---|---|---|
committer | Alex Rudyy <orudyy@apache.org> | 2013-10-05 00:22:31 +0000 |
commit | b1e78aeaaa374515af41e2632df1ac7daa084aad (patch) | |
tree | 4db8d72f1bf31a532d1d2a885cc27d55c5443303 | |
parent | b2f4885938aad11dbbcb67024cb098f4a216f1da (diff) | |
download | qpid-python-b1e78aeaaa374515af41e2632df1ac7daa084aad.tar.gz |
QPID-5138: Replace PreferencesProviderCreator with the static code in PreferencesProviderFactory
git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk@1529358 13f79535-47bb-0310-9956-ffa450edef68
12 files changed, 141 insertions, 122 deletions
diff --git a/qpid/java/broker-core/src/main/java/org/apache/qpid/server/configuration/startup/BrokerRecoverer.java b/qpid/java/broker-core/src/main/java/org/apache/qpid/server/configuration/startup/BrokerRecoverer.java index 4923565e26..8958313fa2 100644 --- a/qpid/java/broker-core/src/main/java/org/apache/qpid/server/configuration/startup/BrokerRecoverer.java +++ b/qpid/java/broker-core/src/main/java/org/apache/qpid/server/configuration/startup/BrokerRecoverer.java @@ -47,7 +47,6 @@ import org.apache.qpid.server.model.adapter.AuthenticationProviderFactory; import org.apache.qpid.server.model.adapter.BrokerAdapter; import org.apache.qpid.server.model.adapter.GroupProviderFactory; import org.apache.qpid.server.model.adapter.PortFactory; -import org.apache.qpid.server.model.adapter.PreferencesProviderCreator; import org.apache.qpid.server.stats.StatisticsGatherer; import org.apache.qpid.server.util.MapValueConverter; import org.apache.qpid.server.virtualhost.VirtualHostRegistry; @@ -67,10 +66,9 @@ public class BrokerRecoverer implements ConfiguredObjectRecoverer<Broker> private final BrokerOptions _brokerOptions; private final GroupProviderFactory _groupProviderFactory; private final StoreConfigurationChangeListener _storeChangeListener; - private final PreferencesProviderCreator _preferencesProviderCreator; public BrokerRecoverer(AuthenticationProviderFactory authenticationProviderFactory, GroupProviderFactory groupProviderFactory, - AccessControlProviderFactory accessControlProviderFactory, PortFactory portFactory, PreferencesProviderCreator preferencesProviderFactory, StatisticsGatherer statisticsGatherer, + AccessControlProviderFactory accessControlProviderFactory, PortFactory portFactory, StatisticsGatherer statisticsGatherer, VirtualHostRegistry virtualHostRegistry, LogRecorder logRecorder, RootMessageLogger rootMessageLogger, TaskExecutor taskExecutor, BrokerOptions brokerOptions, StoreConfigurationChangeListener storeChangeListener) { @@ -85,7 +83,6 @@ public class BrokerRecoverer implements ConfiguredObjectRecoverer<Broker> _taskExecutor = taskExecutor; _brokerOptions = brokerOptions; _storeChangeListener = storeChangeListener; - _preferencesProviderCreator = preferencesProviderFactory; } @Override @@ -98,7 +95,7 @@ public class BrokerRecoverer implements ConfiguredObjectRecoverer<Broker> BrokerAdapter broker = new BrokerAdapter(entry.getId(), attributesCopy, _statisticsGatherer, _virtualHostRegistry, _logRecorder, _rootMessageLogger, _authenticationProviderFactory,_groupProviderFactory, _accessControlProviderFactory, - _portFactory , _preferencesProviderCreator, _taskExecutor, entry.getStore(), _brokerOptions); + _portFactory, _taskExecutor, entry.getStore(), _brokerOptions); broker.addChangeListener(_storeChangeListener); diff --git a/qpid/java/broker-core/src/main/java/org/apache/qpid/server/configuration/startup/DefaultRecovererProvider.java b/qpid/java/broker-core/src/main/java/org/apache/qpid/server/configuration/startup/DefaultRecovererProvider.java index 67268c9854..14b6d9f118 100644 --- a/qpid/java/broker-core/src/main/java/org/apache/qpid/server/configuration/startup/DefaultRecovererProvider.java +++ b/qpid/java/broker-core/src/main/java/org/apache/qpid/server/configuration/startup/DefaultRecovererProvider.java @@ -39,7 +39,6 @@ import org.apache.qpid.server.model.adapter.AccessControlProviderFactory; import org.apache.qpid.server.model.adapter.AuthenticationProviderFactory; import org.apache.qpid.server.model.adapter.GroupProviderFactory; import org.apache.qpid.server.model.adapter.PortFactory; -import org.apache.qpid.server.model.adapter.PreferencesProviderCreator; import org.apache.qpid.server.configuration.store.StoreConfigurationChangeListener; import org.apache.qpid.server.configuration.updater.TaskExecutor; import org.apache.qpid.server.plugin.AccessControlFactory; @@ -65,13 +64,11 @@ public class DefaultRecovererProvider implements RecovererProvider private final TaskExecutor _taskExecutor; private final BrokerOptions _brokerOptions; private final StoreConfigurationChangeListener _storeChangeListener; - private final PreferencesProviderCreator _preferencesProviderCreator; public DefaultRecovererProvider(StatisticsGatherer brokerStatisticsGatherer, VirtualHostRegistry virtualHostRegistry, LogRecorder logRecorder, RootMessageLogger rootMessageLogger, TaskExecutor taskExecutor, BrokerOptions brokerOptions, StoreConfigurationChangeListener storeChangeListener) { - _preferencesProviderCreator = new PreferencesProviderCreator(); - _authenticationProviderFactory = new AuthenticationProviderFactory(new QpidServiceLoader<AuthenticationManagerFactory>(), _preferencesProviderCreator); + _authenticationProviderFactory = new AuthenticationProviderFactory(new QpidServiceLoader<AuthenticationManagerFactory>()); _accessControlProviderFactory = new AccessControlProviderFactory(new QpidServiceLoader<AccessControlFactory>()); _groupProviderFactory = new GroupProviderFactory(new QpidServiceLoader<GroupManagerFactory>()); _portFactory = new PortFactory(); @@ -90,7 +87,7 @@ public class DefaultRecovererProvider implements RecovererProvider { if (Broker.class.getSimpleName().equals(type)) { - return new BrokerRecoverer(_authenticationProviderFactory, _groupProviderFactory, _accessControlProviderFactory, _portFactory, _preferencesProviderCreator, + return new BrokerRecoverer(_authenticationProviderFactory, _groupProviderFactory, _accessControlProviderFactory, _portFactory, _brokerStatisticsGatherer, _virtualHostRegistry, _logRecorder, _rootMessageLogger, _taskExecutor, _brokerOptions, _storeChangeListener); } else if(VirtualHost.class.getSimpleName().equals(type)) @@ -123,7 +120,7 @@ public class DefaultRecovererProvider implements RecovererProvider } else if(PreferencesProvider.class.getSimpleName().equals(type)) { - return new PreferencesProviderRecoverer(_preferencesProviderCreator); + return new PreferencesProviderRecoverer(); } else if(Plugin.class.getSimpleName().equals(type)) { diff --git a/qpid/java/broker-core/src/main/java/org/apache/qpid/server/configuration/startup/PreferencesProviderRecoverer.java b/qpid/java/broker-core/src/main/java/org/apache/qpid/server/configuration/startup/PreferencesProviderRecoverer.java index a455a61fee..72480a2795 100644 --- a/qpid/java/broker-core/src/main/java/org/apache/qpid/server/configuration/startup/PreferencesProviderRecoverer.java +++ b/qpid/java/broker-core/src/main/java/org/apache/qpid/server/configuration/startup/PreferencesProviderRecoverer.java @@ -1,23 +1,39 @@ +/* + * + * 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.configuration.startup; +import java.util.Map; + import org.apache.qpid.server.configuration.ConfigurationEntry; import org.apache.qpid.server.configuration.ConfiguredObjectRecoverer; import org.apache.qpid.server.configuration.RecovererProvider; import org.apache.qpid.server.model.AuthenticationProvider; import org.apache.qpid.server.model.ConfiguredObject; import org.apache.qpid.server.model.PreferencesProvider; -import org.apache.qpid.server.model.adapter.PreferencesProviderCreator; +import org.apache.qpid.server.plugin.PreferencesProviderFactory; +import org.apache.qpid.server.util.MapValueConverter; public class PreferencesProviderRecoverer implements ConfiguredObjectRecoverer<PreferencesProvider> { - private PreferencesProviderCreator _preferencesProviderCreator; - - public PreferencesProviderRecoverer(PreferencesProviderCreator preferencesProviderCreator) - { - _preferencesProviderCreator = preferencesProviderCreator; - } - @Override public PreferencesProvider create(RecovererProvider recovererProvider, ConfigurationEntry entry, ConfiguredObject... parents) @@ -35,7 +51,10 @@ public class PreferencesProviderRecoverer implements ConfiguredObjectRecoverer<P throw new IllegalArgumentException("Parent is not a AuthenticationProvider"); } AuthenticationProvider authenticationProvider = (AuthenticationProvider)parents[0]; - return _preferencesProviderCreator.recover(entry.getId(), entry.getAttributes(), authenticationProvider); + Map<String, Object> attributes = entry.getAttributes(); + String type = MapValueConverter.getStringAttribute(PreferencesProvider.TYPE, attributes); + PreferencesProviderFactory factory = PreferencesProviderFactory.FACTORIES.get(type); + return factory.createInstance(entry.getId(), attributes, authenticationProvider); } } diff --git a/qpid/java/broker-core/src/main/java/org/apache/qpid/server/model/adapter/AuthenticationProviderAdapter.java b/qpid/java/broker-core/src/main/java/org/apache/qpid/server/model/adapter/AuthenticationProviderAdapter.java index cbf8e1ba30..bb734ba5bd 100644 --- a/qpid/java/broker-core/src/main/java/org/apache/qpid/server/model/adapter/AuthenticationProviderAdapter.java +++ b/qpid/java/broker-core/src/main/java/org/apache/qpid/server/model/adapter/AuthenticationProviderAdapter.java @@ -50,6 +50,7 @@ import org.apache.qpid.server.model.UUIDGenerator; import org.apache.qpid.server.model.User; import org.apache.qpid.server.model.VirtualHostAlias; import org.apache.qpid.server.plugin.AuthenticationManagerFactory; +import org.apache.qpid.server.plugin.PreferencesProviderFactory; import org.apache.qpid.server.plugin.QpidServiceLoader; import org.apache.qpid.server.configuration.IllegalConfigurationException; import org.apache.qpid.server.security.SubjectCreator; @@ -72,10 +73,9 @@ public abstract class AuthenticationProviderAdapter<T extends AuthenticationMana protected Collection<String> _supportedAttributes; protected Map<String, AuthenticationManagerFactory> _factories; private final AtomicReference<State> _state; - private PreferencesProviderCreator _preferencesProviderCreator; private PreferencesProvider _preferencesProvider; - private AuthenticationProviderAdapter(UUID id, Broker broker, final T authManager, Map<String, Object> attributes, Collection<String> attributeNames, PreferencesProviderCreator preferencesProviderCreator) + private AuthenticationProviderAdapter(UUID id, Broker broker, final T authManager, Map<String, Object> attributes, Collection<String> attributeNames) { super(id, null, null, broker.getTaskExecutor()); _authManager = authManager; @@ -87,8 +87,6 @@ public abstract class AuthenticationProviderAdapter<T extends AuthenticationMana _state = new AtomicReference<State>(state); addParent(Broker.class, broker); - _preferencesProviderCreator = preferencesProviderCreator; - // set attributes now after all attribute names are known if (attributes != null) { @@ -440,7 +438,10 @@ public abstract class AuthenticationProviderAdapter<T extends AuthenticationMana if(childClass == PreferencesProvider.class) { String name = MapValueConverter.getStringAttribute(PreferencesProvider.NAME, attributes); - PreferencesProvider pp = _preferencesProviderCreator.create(UUIDGenerator.generatePreferencesProviderUUID(name, getName()), attributes, this); + String type = MapValueConverter.getStringAttribute(PreferencesProvider.TYPE, attributes); + PreferencesProviderFactory factory = PreferencesProviderFactory.FACTORIES.get(type); + UUID id = UUIDGenerator.generatePreferencesProviderUUID(name, getName()); + PreferencesProvider pp = factory.createInstance(id, attributes, this); pp.setDesiredState(State.INITIALISING, State.ACTIVE); _preferencesProvider = pp; return (C)pp; @@ -452,9 +453,9 @@ public abstract class AuthenticationProviderAdapter<T extends AuthenticationMana { public SimpleAuthenticationProviderAdapter( - UUID id, Broker broker, AuthenticationManager authManager, Map<String, Object> attributes, Collection<String> attributeNames, PreferencesProviderCreator preferencesProviderCreator) + UUID id, Broker broker, AuthenticationManager authManager, Map<String, Object> attributes, Collection<String> attributeNames) { - super(id, broker,authManager, attributes, attributeNames, preferencesProviderCreator); + super(id, broker,authManager, attributes, attributeNames); } } @@ -463,9 +464,9 @@ public abstract class AuthenticationProviderAdapter<T extends AuthenticationMana implements PasswordCredentialManagingAuthenticationProvider { public PrincipalDatabaseAuthenticationManagerAdapter( - UUID id, Broker broker, PrincipalDatabaseAuthenticationManager authManager, Map<String, Object> attributes, Collection<String> attributeNames, PreferencesProviderCreator preferencesProviderCreator) + UUID id, Broker broker, PrincipalDatabaseAuthenticationManager authManager, Map<String, Object> attributes, Collection<String> attributeNames) { - super(id, broker, authManager, attributes, attributeNames, preferencesProviderCreator); + super(id, broker, authManager, attributes, attributeNames); } @Override diff --git a/qpid/java/broker-core/src/main/java/org/apache/qpid/server/model/adapter/AuthenticationProviderFactory.java b/qpid/java/broker-core/src/main/java/org/apache/qpid/server/model/adapter/AuthenticationProviderFactory.java index 71bc3c631d..eb16d3bbfb 100644 --- a/qpid/java/broker-core/src/main/java/org/apache/qpid/server/model/adapter/AuthenticationProviderFactory.java +++ b/qpid/java/broker-core/src/main/java/org/apache/qpid/server/model/adapter/AuthenticationProviderFactory.java @@ -27,10 +27,8 @@ import java.util.List; import java.util.Map; import java.util.UUID; -import org.apache.qpid.server.configuration.IllegalConfigurationException; import org.apache.qpid.server.model.AuthenticationProvider; import org.apache.qpid.server.model.Broker; -import org.apache.qpid.server.model.PasswordCredentialManagingAuthenticationProvider; import org.apache.qpid.server.plugin.AuthenticationManagerFactory; import org.apache.qpid.server.plugin.QpidServiceLoader; import org.apache.qpid.server.security.auth.manager.AuthenticationManager; @@ -42,11 +40,9 @@ public class AuthenticationProviderFactory { private final Iterable<AuthenticationManagerFactory> _factories; private Collection<String> _supportedAuthenticationProviders; - private final PreferencesProviderCreator _preferencesProviderCreator; - public AuthenticationProviderFactory(QpidServiceLoader<AuthenticationManagerFactory> authManagerFactoryServiceLoader, PreferencesProviderCreator preferencesProviderCreator) + public AuthenticationProviderFactory(QpidServiceLoader<AuthenticationManagerFactory> authManagerFactoryServiceLoader) { - _preferencesProviderCreator = preferencesProviderCreator; _factories = authManagerFactoryServiceLoader.atLeastOneInstanceOf(AuthenticationManagerFactory.class); List<String> supportedAuthenticationProviders = new ArrayList<String>(); for (AuthenticationManagerFactory factory : _factories) @@ -91,11 +87,11 @@ public class AuthenticationProviderFactory if (manager instanceof PrincipalDatabaseAuthenticationManager) { authenticationProvider = new PrincipalDatabaseAuthenticationManagerAdapter(id, broker, - (PrincipalDatabaseAuthenticationManager) manager, attributes, factory.getAttributeNames(), _preferencesProviderCreator); + (PrincipalDatabaseAuthenticationManager) manager, attributes, factory.getAttributeNames()); } else { - authenticationProvider = new SimpleAuthenticationProviderAdapter(id, broker, manager, attributes, factory.getAttributeNames(), _preferencesProviderCreator); + authenticationProvider = new SimpleAuthenticationProviderAdapter(id, broker, manager, attributes, factory.getAttributeNames()); } return authenticationProvider; } diff --git a/qpid/java/broker-core/src/main/java/org/apache/qpid/server/model/adapter/BrokerAdapter.java b/qpid/java/broker-core/src/main/java/org/apache/qpid/server/model/adapter/BrokerAdapter.java index aec78ba414..2fa185ce98 100644 --- a/qpid/java/broker-core/src/main/java/org/apache/qpid/server/model/adapter/BrokerAdapter.java +++ b/qpid/java/broker-core/src/main/java/org/apache/qpid/server/model/adapter/BrokerAdapter.java @@ -60,6 +60,7 @@ import org.apache.qpid.server.model.TrustStore; import org.apache.qpid.server.model.UUIDGenerator; import org.apache.qpid.server.model.VirtualHost; import org.apache.qpid.server.model.adapter.AuthenticationProviderAdapter.SimpleAuthenticationProviderAdapter; +import org.apache.qpid.server.plugin.PreferencesProviderFactory; import org.apache.qpid.server.plugin.VirtualHostFactory; import org.apache.qpid.server.security.SecurityManager; import org.apache.qpid.server.security.SubjectCreator; @@ -178,7 +179,6 @@ public class BrokerAdapter extends AbstractAdapter implements Broker, Configurat private final GroupProviderFactory _groupProviderFactory; private final AuthenticationProviderFactory _authenticationProviderFactory; private final AccessControlProviderFactory _accessControlProviderFactory; - private final PreferencesProviderCreator _preferencesProviderCreator; private final PortFactory _portFactory; private final SecurityManager _securityManager; @@ -192,7 +192,7 @@ public class BrokerAdapter extends AbstractAdapter implements Broker, Configurat public BrokerAdapter(UUID id, Map<String, Object> attributes, StatisticsGatherer statisticsGatherer, VirtualHostRegistry virtualHostRegistry, LogRecorder logRecorder, RootMessageLogger rootMessageLogger, AuthenticationProviderFactory authenticationProviderFactory, GroupProviderFactory groupProviderFactory, AccessControlProviderFactory accessControlProviderFactory, PortFactory portFactory, - PreferencesProviderCreator preferencesProviderCreatory, TaskExecutor taskExecutor, ConfigurationEntryStore brokerStore, BrokerOptions brokerOptions) + TaskExecutor taskExecutor, ConfigurationEntryStore brokerStore, BrokerOptions brokerOptions) { super(id, DEFAULTS, MapValueConverter.convert(attributes, ATTRIBUTE_TYPES), taskExecutor); _statisticsGatherer = statisticsGatherer; @@ -201,7 +201,6 @@ public class BrokerAdapter extends AbstractAdapter implements Broker, Configurat _rootMessageLogger = rootMessageLogger; _statistics = new StatisticsAdapter(statisticsGatherer); _authenticationProviderFactory = authenticationProviderFactory; - _preferencesProviderCreator = preferencesProviderCreatory; _groupProviderFactory = groupProviderFactory; _accessControlProviderFactory = accessControlProviderFactory; _portFactory = portFactory; @@ -214,7 +213,7 @@ public class BrokerAdapter extends AbstractAdapter implements Broker, Configurat { AuthenticationManager authManager = new SimpleAuthenticationManager(BrokerOptions.MANAGEMENT_MODE_USER_NAME, _brokerOptions.getManagementModePassword()); AuthenticationProvider authenticationProvider = new SimpleAuthenticationProviderAdapter(UUID.randomUUID(), this, - authManager, Collections.<String, Object> emptyMap(), Collections.<String> emptySet(), _preferencesProviderCreator); + authManager, Collections.<String, Object> emptyMap(), Collections.<String> emptySet()); _managementAuthenticationProvider = authenticationProvider; } } @@ -786,7 +785,7 @@ public class BrokerAdapter extends AbstractAdapter implements Broker, Configurat } else if (SUPPORTED_PREFERENCES_PROVIDERS_TYPES.equals(name)) { - return _preferencesProviderCreator.getSupportedPreferencesProviders(); + return PreferencesProviderFactory.TYPES.get(); } else if (MODEL_VERSION.equals(name)) { diff --git a/qpid/java/broker-core/src/main/java/org/apache/qpid/server/model/adapter/PreferencesProviderCreator.java b/qpid/java/broker-core/src/main/java/org/apache/qpid/server/model/adapter/PreferencesProviderCreator.java deleted file mode 100644 index 4bcca0e300..0000000000 --- a/qpid/java/broker-core/src/main/java/org/apache/qpid/server/model/adapter/PreferencesProviderCreator.java +++ /dev/null @@ -1,66 +0,0 @@ -package org.apache.qpid.server.model.adapter; - -import java.util.Collection; -import java.util.Collections; -import java.util.HashMap; -import java.util.Map; -import java.util.UUID; - -import org.apache.qpid.server.configuration.IllegalConfigurationException; -import org.apache.qpid.server.model.AuthenticationProvider; -import org.apache.qpid.server.model.PreferencesProvider; -import org.apache.qpid.server.plugin.PreferencesProviderFactory; -import org.apache.qpid.server.plugin.QpidServiceLoader; - -public class PreferencesProviderCreator -{ - private final Map<String, PreferencesProviderFactory> _factories; - private Collection<String> _supportedPreferencesProviders; - - public PreferencesProviderCreator() - { - QpidServiceLoader<PreferencesProviderFactory> preferencesProviderFactoriess = new QpidServiceLoader<PreferencesProviderFactory>(); - - Iterable<PreferencesProviderFactory> factories = preferencesProviderFactoriess - .instancesOf(PreferencesProviderFactory.class); - - Map<String, PreferencesProviderFactory> registeredPreferencesProviderFactories = new HashMap<String, PreferencesProviderFactory>(); - for (PreferencesProviderFactory factory : factories) - { - PreferencesProviderFactory existingFactory = registeredPreferencesProviderFactories.put(factory.getType(), - factory); - if (existingFactory != null) - { - throw new IllegalConfigurationException("Preferences provider factory of the same type '" - + factory.getType() + "' is already registered using class '" + existingFactory.getClass().getName() - + "', can not register class '" + factory.getClass().getName() + "'"); - } - } - _factories = registeredPreferencesProviderFactories; - _supportedPreferencesProviders = Collections.unmodifiableCollection(registeredPreferencesProviderFactories.keySet()); - } - - public Collection<String> getSupportedPreferencesProviders() - { - return _supportedPreferencesProviders; - } - - public PreferencesProvider create(UUID id, Map<String, Object> attributes, AuthenticationProvider authenticationProvider) - { - return createPreferencesProvider(id, attributes, authenticationProvider); - } - - public PreferencesProvider recover(UUID id, Map<String, Object> attributes, AuthenticationProvider authenticationProviderr) - { - return createPreferencesProvider(id, attributes, authenticationProviderr); - } - - private PreferencesProvider createPreferencesProvider(UUID id, Map<String, Object> attributes, AuthenticationProvider authenticationProvider) - { - for (PreferencesProviderFactory factory : _factories.values()) - { - return factory.createInstance(id, attributes, authenticationProvider); - } - throw new IllegalConfigurationException("No group provider factory found for configuration attributes " + attributes); - } -} diff --git a/qpid/java/broker-core/src/main/java/org/apache/qpid/server/plugin/PreferencesProviderFactory.java b/qpid/java/broker-core/src/main/java/org/apache/qpid/server/plugin/PreferencesProviderFactory.java index 5a95b88591..24f3a0bc85 100644 --- a/qpid/java/broker-core/src/main/java/org/apache/qpid/server/plugin/PreferencesProviderFactory.java +++ b/qpid/java/broker-core/src/main/java/org/apache/qpid/server/plugin/PreferencesProviderFactory.java @@ -1,5 +1,27 @@ +/* + * 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.plugin; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.List; import java.util.Map; import java.util.UUID; @@ -9,4 +31,45 @@ import org.apache.qpid.server.model.PreferencesProvider; public interface PreferencesProviderFactory extends Pluggable { PreferencesProvider createInstance(UUID id, Map<String, Object> attributes, AuthenticationProvider authenticationProvider); + + static final class TYPES + { + private TYPES() + { + } + + public static Collection<String> get() + { + QpidServiceLoader<PreferencesProviderFactory> qpidServiceLoader = new QpidServiceLoader<PreferencesProviderFactory>(); + Iterable<PreferencesProviderFactory> factories = qpidServiceLoader.atLeastOneInstanceOf(PreferencesProviderFactory.class); + List<String> names = new ArrayList<String>(); + for(PreferencesProviderFactory factory : factories) + { + names.add(factory.getType()); + } + return Collections.unmodifiableCollection(names); + } + } + + + static final class FACTORIES + { + private FACTORIES() + { + } + + public static PreferencesProviderFactory get(String type) + { + QpidServiceLoader<PreferencesProviderFactory> qpidServiceLoader = new QpidServiceLoader<PreferencesProviderFactory>(); + Iterable<PreferencesProviderFactory> factories = qpidServiceLoader.atLeastOneInstanceOf(PreferencesProviderFactory.class); + for(PreferencesProviderFactory factory : factories) + { + if(factory.getType().equals(type)) + { + return factory; + } + } + return null; + } + } } diff --git a/qpid/java/broker-core/src/test/java/org/apache/qpid/server/configuration/startup/AuthenticationProviderRecovererTest.java b/qpid/java/broker-core/src/test/java/org/apache/qpid/server/configuration/startup/AuthenticationProviderRecovererTest.java index eed54ef5bf..ab5147c1e3 100644 --- a/qpid/java/broker-core/src/test/java/org/apache/qpid/server/configuration/startup/AuthenticationProviderRecovererTest.java +++ b/qpid/java/broker-core/src/test/java/org/apache/qpid/server/configuration/startup/AuthenticationProviderRecovererTest.java @@ -40,7 +40,6 @@ import org.apache.qpid.server.model.ConfiguredObject; import org.apache.qpid.server.model.PreferencesProvider; import org.apache.qpid.server.model.adapter.AuthenticationProviderFactory; import org.apache.qpid.server.model.adapter.FileSystemPreferencesProvider; -import org.apache.qpid.server.model.adapter.PreferencesProviderCreator; import org.apache.qpid.server.plugin.AuthenticationManagerFactory; import org.apache.qpid.server.plugin.QpidServiceLoader; import org.apache.qpid.server.security.auth.manager.PlainPasswordFileAuthenticationManagerFactory; @@ -53,16 +52,14 @@ public class AuthenticationProviderRecovererTest extends QpidTestCase private Broker _broker; private AuthenticationProviderRecoverer _recoverer; private ConfigurationEntryStore _configurationStore; - private PreferencesProviderCreator _preferencesProviderCreator; public void setUp() throws Exception { super.setUp(); BrokerTestHelper.setUp(); _broker = BrokerTestHelper.createBrokerMock(); - _preferencesProviderCreator = new PreferencesProviderCreator(); QpidServiceLoader<AuthenticationManagerFactory> serviceLoader = new QpidServiceLoader<AuthenticationManagerFactory>(); - AuthenticationProviderFactory authenticationProviderFactory = new AuthenticationProviderFactory(serviceLoader, _preferencesProviderCreator); + AuthenticationProviderFactory authenticationProviderFactory = new AuthenticationProviderFactory(serviceLoader); StoreConfigurationChangeListener storeChangeListener = mock(StoreConfigurationChangeListener.class); _recoverer = new AuthenticationProviderRecoverer(authenticationProviderFactory, storeChangeListener); _configurationStore = mock(ConfigurationEntryStore.class); @@ -93,7 +90,7 @@ public class AuthenticationProviderRecovererTest extends QpidTestCase authenticationProviderFile.getAbsolutePath()); UUID authenticationId = UUID.randomUUID(); - final PreferencesProviderRecoverer preferencesRecoverer = new PreferencesProviderRecoverer(_preferencesProviderCreator); + final PreferencesProviderRecoverer preferencesRecoverer = new PreferencesProviderRecoverer(); RecovererProvider recovererProvider = new RecovererProvider() { @Override @@ -105,7 +102,7 @@ public class AuthenticationProviderRecovererTest extends QpidTestCase Map<String, Object> preferencesAttributes = new HashMap<String, Object>(); UUID preferencesId = UUID.randomUUID(); - preferencesAttributes.put(PreferencesProvider.TYPE, FileSystemPreferencesProvider.class); + preferencesAttributes.put(PreferencesProvider.TYPE, FileSystemPreferencesProvider.PROVIDER_TYPE); preferencesAttributes.put(PreferencesProvider.NAME, "test-provider"); File file = TestFileUtils.createTempFile(this, ".prefs.json", "{\"test_user\":{\"pref1\": \"pref1Value\", \"pref2\": 1.0} }"); diff --git a/qpid/java/broker-core/src/test/java/org/apache/qpid/server/configuration/startup/BrokerRecovererTest.java b/qpid/java/broker-core/src/test/java/org/apache/qpid/server/configuration/startup/BrokerRecovererTest.java index e6db5af222..c45f4f72a8 100644 --- a/qpid/java/broker-core/src/test/java/org/apache/qpid/server/configuration/startup/BrokerRecovererTest.java +++ b/qpid/java/broker-core/src/test/java/org/apache/qpid/server/configuration/startup/BrokerRecovererTest.java @@ -55,7 +55,6 @@ import org.apache.qpid.server.model.adapter.AccessControlProviderFactory; import org.apache.qpid.server.model.adapter.AuthenticationProviderFactory; import org.apache.qpid.server.model.adapter.GroupProviderFactory; import org.apache.qpid.server.model.adapter.PortFactory; -import org.apache.qpid.server.model.adapter.PreferencesProviderCreator; import org.apache.qpid.server.configuration.store.StoreConfigurationChangeListener; import org.apache.qpid.server.configuration.updater.TaskExecutor; import org.apache.qpid.server.stats.StatisticsGatherer; @@ -78,7 +77,6 @@ public class BrokerRecovererTest extends TestCase super.setUp(); _brokerRecoverer = new BrokerRecoverer(mock(AuthenticationProviderFactory.class), mock(GroupProviderFactory.class), mock(AccessControlProviderFactory.class), mock(PortFactory.class), - mock(PreferencesProviderCreator.class), mock(StatisticsGatherer.class), mock(VirtualHostRegistry.class), mock(LogRecorder.class), mock(RootMessageLogger.class), mock(TaskExecutor.class), mock(BrokerOptions.class), mock(StoreConfigurationChangeListener.class)); when(_brokerEntry.getId()).thenReturn(_brokerId); diff --git a/qpid/java/broker-core/src/test/java/org/apache/qpid/server/configuration/startup/PreferencesProviderRecovererTest.java b/qpid/java/broker-core/src/test/java/org/apache/qpid/server/configuration/startup/PreferencesProviderRecovererTest.java index 8c316b5f53..1fc630dae0 100644 --- a/qpid/java/broker-core/src/test/java/org/apache/qpid/server/configuration/startup/PreferencesProviderRecovererTest.java +++ b/qpid/java/broker-core/src/test/java/org/apache/qpid/server/configuration/startup/PreferencesProviderRecovererTest.java @@ -37,11 +37,30 @@ import org.apache.qpid.server.model.AuthenticationProvider; import org.apache.qpid.server.model.Broker; import org.apache.qpid.server.model.PreferencesProvider; import org.apache.qpid.server.model.adapter.FileSystemPreferencesProvider; -import org.apache.qpid.server.model.adapter.PreferencesProviderCreator; import org.apache.qpid.server.util.BrokerTestHelper; import org.apache.qpid.test.utils.QpidTestCase; import org.apache.qpid.test.utils.TestFileUtils; +/* +* +* 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. +* +*/ public class PreferencesProviderRecovererTest extends QpidTestCase { private AuthenticationProvider _authenticationProvider; @@ -70,11 +89,11 @@ public class PreferencesProviderRecovererTest extends QpidTestCase public void testRecoverFileSystemPreferencesProvider() { - PreferencesProviderRecoverer recoverer = new PreferencesProviderRecoverer(new PreferencesProviderCreator()); + PreferencesProviderRecoverer recoverer = new PreferencesProviderRecoverer(); Map<String, Object> attributes = new HashMap<String, Object>(); UUID id = UUID.randomUUID(); - attributes.put(PreferencesProvider.TYPE, FileSystemPreferencesProvider.class); + attributes.put(PreferencesProvider.TYPE, FileSystemPreferencesProvider.PROVIDER_TYPE); attributes.put(PreferencesProvider.NAME, "test-provider"); File file = TestFileUtils.createTempFile(this, ".prefs.json", "{\"test_user\":{\"pref1\": \"pref1Value\", \"pref2\": 1.0} }"); try diff --git a/qpid/java/broker-core/src/test/java/org/apache/qpid/server/model/adapter/AuthenticationProviderFactoryTest.java b/qpid/java/broker-core/src/test/java/org/apache/qpid/server/model/adapter/AuthenticationProviderFactoryTest.java index ed22843e07..fbb1e4105f 100644 --- a/qpid/java/broker-core/src/test/java/org/apache/qpid/server/model/adapter/AuthenticationProviderFactoryTest.java +++ b/qpid/java/broker-core/src/test/java/org/apache/qpid/server/model/adapter/AuthenticationProviderFactoryTest.java @@ -43,7 +43,6 @@ import org.apache.qpid.server.security.auth.manager.PrincipalDatabaseAuthenticat public class AuthenticationProviderFactoryTest extends TestCase { - private PreferencesProviderCreator _preferencesProviderCreator = mock(PreferencesProviderCreator.class); public void testCreatePasswordCredentialManagingAuthenticationProvider() { @@ -96,7 +95,7 @@ public class AuthenticationProviderFactoryTest extends TestCase Collections.singleton(authenticationManagerFactory)); when(authenticationManagerFactory.createInstance(attributes)).thenReturn(authenticationManager); - AuthenticationProviderFactory providerFactory = new AuthenticationProviderFactory(authManagerFactoryServiceLoader, _preferencesProviderCreator); + AuthenticationProviderFactory providerFactory = new AuthenticationProviderFactory(authManagerFactoryServiceLoader); AuthenticationProvider provider = null; if (create) @@ -125,7 +124,7 @@ public class AuthenticationProviderFactoryTest extends TestCase when(managerFactory.createInstance(any(Map.class))).thenReturn(mock(PrincipalDatabaseAuthenticationManager.class)); when(loader.atLeastOneInstanceOf(AuthenticationManagerFactory.class)).thenReturn(Collections.singleton(managerFactory)); - AuthenticationProviderFactory providerFactory = new AuthenticationProviderFactory(loader, _preferencesProviderCreator); + AuthenticationProviderFactory providerFactory = new AuthenticationProviderFactory(loader); UUID randomUUID = UUID.randomUUID(); AuthenticationProvider provider = providerFactory.create(randomUUID, broker, new HashMap<String, Object>()); @@ -146,7 +145,7 @@ public class AuthenticationProviderFactoryTest extends TestCase when(managerFactory.createInstance(any(Map.class))).thenReturn(mock(AuthenticationManager.class)); when(loader.atLeastOneInstanceOf(AuthenticationManagerFactory.class)).thenReturn(Collections.singleton(managerFactory)); - AuthenticationProviderFactory providerFactory = new AuthenticationProviderFactory(loader, _preferencesProviderCreator); + AuthenticationProviderFactory providerFactory = new AuthenticationProviderFactory(loader); UUID id = UUID.randomUUID(); AuthenticationProvider provider = providerFactory.create(id, broker, new HashMap<String, Object>()); |