diff options
| author | Robert Godfrey <rgodfrey@apache.org> | 2014-04-30 01:22:13 +0000 |
|---|---|---|
| committer | Robert Godfrey <rgodfrey@apache.org> | 2014-04-30 01:22:13 +0000 |
| commit | ae71aa7102a41735e49ec5c98409bc69fffd9a8f (patch) | |
| tree | f0709ee8c5993d6995e5de59c0cdc855a540614e /qpid/java/broker-plugins/access-control/src | |
| parent | 0d49f2fa419a414e1c9548001fcbde03d442f5c1 (diff) | |
| download | qpid-python-ae71aa7102a41735e49ec5c98409bc69fffd9a8f.tar.gz | |
QPID-5578 : [Java Broker] Use annotation to allow registration of all ConfiguredObject types at startup. Use this meta data for REST servlets. Remove unnecessary pluggable factory interfaces
git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk@1591170 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'qpid/java/broker-plugins/access-control/src')
6 files changed, 16 insertions, 91 deletions
diff --git a/qpid/java/broker-plugins/access-control/src/main/java/org/apache/qpid/server/security/access/plugins/ACLFileAccessControlProvider.java b/qpid/java/broker-plugins/access-control/src/main/java/org/apache/qpid/server/security/access/plugins/ACLFileAccessControlProvider.java index 961eb25236..d54f226a00 100644 --- a/qpid/java/broker-plugins/access-control/src/main/java/org/apache/qpid/server/security/access/plugins/ACLFileAccessControlProvider.java +++ b/qpid/java/broker-plugins/access-control/src/main/java/org/apache/qpid/server/security/access/plugins/ACLFileAccessControlProvider.java @@ -27,6 +27,6 @@ import org.apache.qpid.server.model.ManagedObject; @ManagedObject( category = false, type="AclFile" ) public interface ACLFileAccessControlProvider<X extends ACLFileAccessControlProvider<X>> extends AccessControlProvider<X> { - @ManagedAttribute( automate = true, mandatory = true ) + @ManagedAttribute( automate = true, mandatory = true, description = "File location" ) String getPath(); } diff --git a/qpid/java/broker-plugins/access-control/src/main/java/org/apache/qpid/server/security/access/plugins/ACLFileAccessControlProviderFactory.java b/qpid/java/broker-plugins/access-control/src/main/java/org/apache/qpid/server/security/access/plugins/ACLFileAccessControlProviderFactory.java deleted file mode 100644 index 1547adc6e5..0000000000 --- a/qpid/java/broker-plugins/access-control/src/main/java/org/apache/qpid/server/security/access/plugins/ACLFileAccessControlProviderFactory.java +++ /dev/null @@ -1,55 +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.security.access.plugins; - -import java.util.Map; - -import org.apache.qpid.server.model.AbstractConfiguredObjectTypeFactory; -import org.apache.qpid.server.model.Broker; -import org.apache.qpid.server.model.ConfiguredObject; -import org.apache.qpid.server.plugin.AccessControlProviderFactory; -import org.apache.qpid.server.plugin.PluggableService; -import org.apache.qpid.server.util.ResourceBundleLoader; - -@PluggableService -public class ACLFileAccessControlProviderFactory extends AbstractConfiguredObjectTypeFactory<ACLFileAccessControlProviderImpl> implements AccessControlProviderFactory<ACLFileAccessControlProviderImpl> -{ - public static final String RESOURCE_BUNDLE = "org.apache.qpid.server.security.access.plugins.FileAccessControlProviderAttributeDescriptions"; - - public ACLFileAccessControlProviderFactory() - { - super(ACLFileAccessControlProviderImpl.class); - } - - @Override - public Map<String, String> getAttributeDescriptions() - { - return ResourceBundleLoader.getResources(RESOURCE_BUNDLE); - } - - @Override - public ACLFileAccessControlProviderImpl createInstance(final Map<String, Object> attributes, - final ConfiguredObject<?>... parents) - { - return new ACLFileAccessControlProviderImpl(attributes, getParent(Broker.class,parents)); - } - -} diff --git a/qpid/java/broker-plugins/access-control/src/main/java/org/apache/qpid/server/security/access/plugins/ACLFileAccessControlProviderImpl.java b/qpid/java/broker-plugins/access-control/src/main/java/org/apache/qpid/server/security/access/plugins/ACLFileAccessControlProviderImpl.java index c3ce92f5b1..554f2f46c5 100644 --- a/qpid/java/broker-plugins/access-control/src/main/java/org/apache/qpid/server/security/access/plugins/ACLFileAccessControlProviderImpl.java +++ b/qpid/java/broker-plugins/access-control/src/main/java/org/apache/qpid/server/security/access/plugins/ACLFileAccessControlProviderImpl.java @@ -35,8 +35,8 @@ import org.apache.qpid.server.model.Broker; import org.apache.qpid.server.model.ConfiguredObject; import org.apache.qpid.server.model.IllegalStateTransitionException; import org.apache.qpid.server.model.ManagedAttributeField; +import org.apache.qpid.server.model.ManagedObjectFactoryConstructor; import org.apache.qpid.server.model.State; -import org.apache.qpid.server.plugin.AccessControlProviderFactory; import org.apache.qpid.server.security.AccessControl; import org.apache.qpid.server.security.access.Operation; import org.apache.qpid.server.util.MapValueConverter; @@ -50,12 +50,12 @@ public class ACLFileAccessControlProviderImpl protected DefaultAccessControl _accessControl; protected final Broker _broker; - protected Map<String, AccessControlProviderFactory> _factories; private AtomicReference<State> _state; @ManagedAttributeField private String _path; + @ManagedObjectFactoryConstructor public ACLFileAccessControlProviderImpl(Map<String, Object> attributes, Broker broker) { super(parentsMap(broker), attributes); diff --git a/qpid/java/broker-plugins/access-control/src/main/java/org/apache/qpid/server/security/access/plugins/FileAccessControlProviderAttributeDescriptions.properties b/qpid/java/broker-plugins/access-control/src/main/java/org/apache/qpid/server/security/access/plugins/FileAccessControlProviderAttributeDescriptions.properties deleted file mode 100644 index e847e90f57..0000000000 --- a/qpid/java/broker-plugins/access-control/src/main/java/org/apache/qpid/server/security/access/plugins/FileAccessControlProviderAttributeDescriptions.properties +++ /dev/null @@ -1,19 +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. - -path=File location*
\ No newline at end of file diff --git a/qpid/java/broker-plugins/access-control/src/test/java/org/apache/qpid/server/security/access/plugins/ACLFileAccessControlProviderFactoryTest.java b/qpid/java/broker-plugins/access-control/src/test/java/org/apache/qpid/server/security/access/plugins/ACLFileAccessControlProviderFactoryTest.java index fab6ad1750..01da01eb97 100644 --- a/qpid/java/broker-plugins/access-control/src/test/java/org/apache/qpid/server/security/access/plugins/ACLFileAccessControlProviderFactoryTest.java +++ b/qpid/java/broker-plugins/access-control/src/test/java/org/apache/qpid/server/security/access/plugins/ACLFileAccessControlProviderFactoryTest.java @@ -33,9 +33,7 @@ import org.apache.qpid.server.configuration.IllegalConfigurationException; import org.apache.qpid.server.model.AccessControlProvider; 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.GroupProvider; import org.apache.qpid.server.security.access.FileAccessControlProviderConstants; import org.apache.qpid.test.utils.QpidTestCase; import org.apache.qpid.test.utils.TestFileUtils; @@ -43,28 +41,30 @@ import org.apache.qpid.test.utils.TestFileUtils; public class ACLFileAccessControlProviderFactoryTest extends QpidTestCase { private Broker _broker; + private ConfiguredObjectFactoryImpl _objectFactory; @Override public void setUp() throws Exception { super.setUp(); _broker = mock(Broker.class); - ConfiguredObjectFactory objectFactory = new ConfiguredObjectFactoryImpl(BrokerModel.getInstance()); + _objectFactory = new ConfiguredObjectFactoryImpl(BrokerModel.getInstance()); - when(_broker.getObjectFactory()).thenReturn(objectFactory); - when(_broker.getModel()).thenReturn(objectFactory.getModel()); + when(_broker.getObjectFactory()).thenReturn(_objectFactory); + when(_broker.getModel()).thenReturn(_objectFactory.getModel()); when(_broker.getCategoryClass()).thenReturn(Broker.class); } public void testCreateInstanceWhenAclFileIsNotPresent() { - ACLFileAccessControlProviderFactory factory = new ACLFileAccessControlProviderFactory(); Map<String, Object> attributes = new HashMap<String, Object>(); attributes.put(AccessControlProvider.ID, UUID.randomUUID()); attributes.put(AccessControlProvider.NAME, "acl"); + attributes.put(AccessControlProvider.TYPE, FileAccessControlProviderConstants.ACL_FILE_PROVIDER_TYPE); + try { - AccessControlProvider acl = factory.create(null, attributes, _broker); + AccessControlProvider acl = _objectFactory.create(AccessControlProvider.class, attributes, _broker); fail("ACL was created without a configuration file path specified"); } catch(IllegalArgumentException e) @@ -73,16 +73,16 @@ public class ACLFileAccessControlProviderFactoryTest extends QpidTestCase } } + public void testCreateInstanceWhenAclFileIsSpecified() { File aclFile = TestFileUtils.createTempFile(this, ".acl", "ACL ALLOW all all"); - ACLFileAccessControlProviderFactory factory = new ACLFileAccessControlProviderFactory(); Map<String, Object> attributes = new HashMap<String, Object>(); attributes.put(AccessControlProvider.ID, UUID.randomUUID()); attributes.put(AccessControlProvider.NAME, "acl"); - attributes.put(GroupProvider.TYPE, FileAccessControlProviderConstants.ACL_FILE_PROVIDER_TYPE); + attributes.put(AccessControlProvider.TYPE, FileAccessControlProviderConstants.ACL_FILE_PROVIDER_TYPE); attributes.put(FileAccessControlProviderConstants.PATH, aclFile.getAbsolutePath()); - AccessControlProvider acl = factory.create(null, attributes, _broker); + AccessControlProvider acl = _objectFactory.create(AccessControlProvider.class, attributes, _broker); acl.getAccessControl().open(); assertNotNull("ACL was not created from acl file: " + aclFile.getAbsolutePath(), acl); @@ -92,15 +92,14 @@ public class ACLFileAccessControlProviderFactoryTest extends QpidTestCase { File aclFile = new File(TMP_FOLDER, "my-non-existing-acl-" + System.currentTimeMillis()); assertFalse("ACL file " + aclFile.getAbsolutePath() + " actually exists but should not", aclFile.exists()); - ACLFileAccessControlProviderFactory factory = new ACLFileAccessControlProviderFactory(); Map<String, Object> attributes = new HashMap<String, Object>(); attributes.put(AccessControlProvider.ID, UUID.randomUUID()); attributes.put(AccessControlProvider.NAME, "acl"); - attributes.put(GroupProvider.TYPE, FileAccessControlProviderConstants.ACL_FILE_PROVIDER_TYPE); + attributes.put(AccessControlProvider.TYPE, FileAccessControlProviderConstants.ACL_FILE_PROVIDER_TYPE); attributes.put(FileAccessControlProviderConstants.PATH, aclFile.getAbsolutePath()); try { - AccessControlProvider control = factory.create(null, attributes, _broker); + AccessControlProvider control = _objectFactory.create(AccessControlProvider.class, attributes, _broker); control.getAccessControl().open(); fail("It should not be possible to create and initialise ACL with non existing file"); } diff --git a/qpid/java/broker-plugins/access-control/src/test/java/org/apache/qpid/server/security/access/plugins/RuleSetTest.java b/qpid/java/broker-plugins/access-control/src/test/java/org/apache/qpid/server/security/access/plugins/RuleSetTest.java index 523640adad..0ce2555bcf 100644 --- a/qpid/java/broker-plugins/access-control/src/test/java/org/apache/qpid/server/security/access/plugins/RuleSetTest.java +++ b/qpid/java/broker-plugins/access-control/src/test/java/org/apache/qpid/server/security/access/plugins/RuleSetTest.java @@ -192,7 +192,7 @@ public class RuleSetTest extends QpidTestCase ExchangeImpl<?> exchange = mock(ExchangeImpl.class); when(exchange.getParent(VirtualHost.class)).thenReturn(_virtualHost); - when(exchange.getTypeName()).thenReturn(_exchangeType); + when(exchange.getType()).thenReturn(_exchangeType); when(_virtualHost.getName()).thenReturn(ALLOWED_VH); assertEquals(Result.ALLOWED, _ruleSet.check(_testSubject, Operation.CREATE, ObjectType.EXCHANGE, new ObjectProperties(exchange))); |
