diff options
| author | Robert Godfrey <rgodfrey@apache.org> | 2014-04-04 22:34:26 +0000 |
|---|---|---|
| committer | Robert Godfrey <rgodfrey@apache.org> | 2014-04-04 22:34:26 +0000 |
| commit | 7344c8879c319c4ca6ab57963e6147d878a4e154 (patch) | |
| tree | 230bbd0d3b9aa28b0a6298ae5156a40c996ddcdb /qpid/java/broker-plugins | |
| parent | db86d03af2ce0f704398c2a9392e91e9637154ec (diff) | |
| download | qpid-python-7344c8879c319c4ca6ab57963e6147d878a4e154.tar.gz | |
QPID-5615 : [Java Broker] Migrate broker config store to use same API as VirtualHost config store
git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk@1584931 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'qpid/java/broker-plugins')
20 files changed, 473 insertions, 210 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 new file mode 100644 index 0000000000..7772925382 --- /dev/null +++ b/qpid/java/broker-plugins/access-control/src/main/java/org/apache/qpid/server/security/access/plugins/ACLFileAccessControlProvider.java @@ -0,0 +1,245 @@ +/* + * + * 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.security.AccessControlException; +import java.util.Collection; +import java.util.Collections; +import java.util.Map; +import java.util.concurrent.atomic.AtomicReference; + +import org.apache.log4j.Logger; +import org.apache.qpid.server.model.*; +import org.apache.qpid.server.model.AbstractConfiguredObject; +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; + +@ManagedObject( category = false, type="AclFile" ) +public class ACLFileAccessControlProvider + extends AbstractConfiguredObject<ACLFileAccessControlProvider> + implements AccessControlProvider<ACLFileAccessControlProvider> +{ + private static final Logger LOGGER = Logger.getLogger(ACLFileAccessControlProvider.class); + + protected DefaultAccessControl _accessControl; + protected final Broker _broker; + + protected Map<String, AccessControlProviderFactory> _factories; + private AtomicReference<State> _state; + + @ManagedAttributeField + private String _path; + + @ManagedAttributeField + private String _type; + + public ACLFileAccessControlProvider(Broker broker, + Map<String, Object> attributes) + { + super(Collections.<Class<? extends ConfiguredObject>,ConfiguredObject<?>>singletonMap(Broker.class, broker), + Collections.<String,Object>emptyMap(), attributes, broker.getTaskExecutor()); + + + _accessControl = new DefaultAccessControl(getPath(), broker); + _broker = broker; + + State state = MapValueConverter.getEnumAttribute(State.class, STATE, attributes, State.INITIALISING); + _state = new AtomicReference<State>(state); + + } + + @ManagedAttribute( automate = true, mandatory = true ) + public String getPath() + { + return _path; + } + + @ManagedAttribute( automate = true ) + public String getType() + { + return _type; + } + + @Override + public String setName(String currentName, String desiredName) throws IllegalStateException, AccessControlException + { + return null; + } + + @Override + public State getState() + { + return _state.get(); + } + + @Override + public boolean isDurable() + { + return true; + } + + @Override + public void setDurable(boolean durable) + throws IllegalStateException, AccessControlException, IllegalArgumentException + { + } + + @Override + public LifetimePolicy getLifetimePolicy() + { + return LifetimePolicy.PERMANENT; + } + + @Override + public LifetimePolicy setLifetimePolicy(LifetimePolicy expected, LifetimePolicy desired) + throws IllegalStateException, AccessControlException, IllegalArgumentException + { + return null; + } + + @Override + public Collection<String> getAttributeNames() + { + return getAttributeNames(getClass()); + } + + @Override + public Object getAttribute(String name) + { + if(DURABLE.equals(name)) + { + return true; + } + else if(LIFETIME_POLICY.equals(name)) + { + return LifetimePolicy.PERMANENT; + } + else if(STATE.equals(name)) + { + return getState(); + } + return super.getAttribute(name); + } + + @Override + public <C extends ConfiguredObject> Collection<C> getChildren(Class<C> clazz) + { + return Collections.emptySet(); + } + + @Override + public boolean setState(State currentState, State desiredState) + throws IllegalStateTransitionException, AccessControlException + { + State state = _state.get(); + + if(desiredState == State.DELETED) + { + return _state.compareAndSet(state, State.DELETED); + } + else if (desiredState == State.QUIESCED) + { + return _state.compareAndSet(state, State.QUIESCED); + } + else if(desiredState == State.ACTIVE) + { + if ((state == State.INITIALISING || state == State.QUIESCED) && _state.compareAndSet(state, State.ACTIVE)) + { + try + { + _accessControl.open(); + return true; + } + catch(RuntimeException e) + { + _state.compareAndSet(State.ACTIVE, State.ERRORED); + if (_broker.isManagementMode()) + { + LOGGER.warn("Failed to activate ACL provider: " + getName(), e); + } + else + { + throw e; + } + } + } + else + { + throw new IllegalStateException("Can't activate access control provider in " + state + " state"); + } + } + else if(desiredState == State.STOPPED) + { + if(_state.compareAndSet(state, State.STOPPED)) + { + _accessControl.close(); + return true; + } + + return false; + } + return false; + } + + + @Override + protected void changeAttributes(Map<String, Object> attributes) + { + throw new UnsupportedOperationException("Changing attributes on AccessControlProvider is not supported"); + } + + @Override + protected void authoriseSetDesiredState(State currentState, State desiredState) throws AccessControlException + { + if(desiredState == State.DELETED) + { + if (!_broker.getSecurityManager().authoriseConfiguringBroker(getName(), AccessControlProvider.class, Operation.DELETE)) + { + throw new AccessControlException("Deletion of AccessControlProvider is denied"); + } + } + } + + @Override + protected void authoriseSetAttribute(String name, Object expected, Object desired) throws AccessControlException + { + if (!_broker.getSecurityManager().authoriseConfiguringBroker(getName(), AccessControlProvider.class, Operation.UPDATE)) + { + throw new AccessControlException("Setting of AccessControlProvider attributes is denied"); + } + } + + @Override + protected void authoriseSetAttributes(Map<String, Object> attributes) throws AccessControlException + { + if (!_broker.getSecurityManager().authoriseConfiguringBroker(getName(), AccessControlProvider.class, Operation.UPDATE)) + { + throw new AccessControlException("Setting of AccessControlProvider attributes is denied"); + } + } + + public AccessControl getAccessControl() + { + return _accessControl; + } +} 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 new file mode 100644 index 0000000000..e9de449804 --- /dev/null +++ b/qpid/java/broker-plugins/access-control/src/main/java/org/apache/qpid/server/security/access/plugins/ACLFileAccessControlProviderFactory.java @@ -0,0 +1,53 @@ +/* + * + * 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 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.util.ResourceBundleLoader; + +import java.util.Map; + +public class ACLFileAccessControlProviderFactory extends AbstractConfiguredObjectTypeFactory<ACLFileAccessControlProvider> implements AccessControlProviderFactory<ACLFileAccessControlProvider> +{ + public static final String RESOURCE_BUNDLE = "org.apache.qpid.server.security.access.plugins.FileAccessControlProviderAttributeDescriptions"; + + public ACLFileAccessControlProviderFactory() + { + super(ACLFileAccessControlProvider.class); + } + + @Override + public Map<String, String> getAttributeDescriptions() + { + return ResourceBundleLoader.getResources(RESOURCE_BUNDLE); + } + + @Override + public ACLFileAccessControlProvider createInstance(final Map<String, Object> attributes, + final ConfiguredObject<?>... parents) + { + return new ACLFileAccessControlProvider(getParent(Broker.class,parents), attributes); + } + +} diff --git a/qpid/java/broker-plugins/access-control/src/main/java/org/apache/qpid/server/security/access/plugins/DefaultAccessControlFactory.java b/qpid/java/broker-plugins/access-control/src/main/java/org/apache/qpid/server/security/access/plugins/DefaultAccessControlFactory.java deleted file mode 100644 index 0d4734df88..0000000000 --- a/qpid/java/broker-plugins/access-control/src/main/java/org/apache/qpid/server/security/access/plugins/DefaultAccessControlFactory.java +++ /dev/null @@ -1,81 +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 static org.apache.qpid.server.security.access.FileAccessControlProviderConstants.ACL_FILE_PROVIDER_TYPE; -import static org.apache.qpid.server.security.access.FileAccessControlProviderConstants.PATH; -import static org.apache.qpid.server.util.MapValueConverter.getStringAttribute; - -import java.util.Arrays; -import java.util.Collection; -import java.util.Collections; -import java.util.Map; - -import org.apache.qpid.server.configuration.IllegalConfigurationException; -import org.apache.qpid.server.logging.EventLogger; -import org.apache.qpid.server.logging.EventLoggerProvider; -import org.apache.qpid.server.plugin.AccessControlFactory; -import org.apache.qpid.server.security.AccessControl; -import org.apache.qpid.server.util.ResourceBundleLoader; - -public class DefaultAccessControlFactory implements AccessControlFactory -{ - public static final String RESOURCE_BUNDLE = "org.apache.qpid.server.security.access.plugins.FileAccessControlProviderAttributeDescriptions"; - - public static final Collection<String> ATTRIBUTES = Collections.<String> unmodifiableList(Arrays.asList( - ATTRIBUTE_TYPE, - PATH - )); - - public AccessControl createInstance(Map<String, Object> attributes, final EventLoggerProvider eventLogger) - { - if(attributes == null || !ACL_FILE_PROVIDER_TYPE.equals(attributes.get(ATTRIBUTE_TYPE))) - { - return null; - } - - String path = getStringAttribute(PATH, attributes, null); - if (path == null || "".equals(path.trim())) - { - throw new IllegalConfigurationException("Path to ACL was not specified!"); - } - - return new DefaultAccessControl(path, eventLogger); - } - - @Override - public String getType() - { - return ACL_FILE_PROVIDER_TYPE; - } - - @Override - public Collection<String> getAttributeNames() - { - return ATTRIBUTES; - } - - @Override - public Map<String, String> getAttributeDescriptions() - { - return ResourceBundleLoader.getResources(RESOURCE_BUNDLE); - } -} diff --git a/qpid/java/broker-plugins/access-control/src/main/resources/META-INF/services/org.apache.qpid.server.plugin.AccessControlProviderFactory b/qpid/java/broker-plugins/access-control/src/main/resources/META-INF/services/org.apache.qpid.server.plugin.AccessControlProviderFactory new file mode 100644 index 0000000000..2c5a643ab1 --- /dev/null +++ b/qpid/java/broker-plugins/access-control/src/main/resources/META-INF/services/org.apache.qpid.server.plugin.AccessControlProviderFactory @@ -0,0 +1,19 @@ +# +# 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. +# +org.apache.qpid.server.security.access.plugins.ACLFileAccessControlProviderFactory diff --git a/qpid/java/broker-plugins/access-control/src/main/resources/META-INF/services/org.apache.qpid.server.plugin.ConfiguredObjectTypeFactory b/qpid/java/broker-plugins/access-control/src/main/resources/META-INF/services/org.apache.qpid.server.plugin.ConfiguredObjectTypeFactory new file mode 100644 index 0000000000..2c5a643ab1 --- /dev/null +++ b/qpid/java/broker-plugins/access-control/src/main/resources/META-INF/services/org.apache.qpid.server.plugin.ConfiguredObjectTypeFactory @@ -0,0 +1,19 @@ +# +# 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. +# +org.apache.qpid.server.security.access.plugins.ACLFileAccessControlProviderFactory diff --git a/qpid/java/broker-plugins/access-control/src/test/java/org/apache/qpid/server/security/access/plugins/DefaultAccessControlFactoryTest.java b/qpid/java/broker-plugins/access-control/src/test/java/org/apache/qpid/server/security/access/plugins/ACLFileAccessControlProviderFactoryTest.java index c4c36df6d9..102cfb4be1 100644 --- a/qpid/java/broker-plugins/access-control/src/test/java/org/apache/qpid/server/security/access/plugins/DefaultAccessControlFactoryTest.java +++ b/qpid/java/broker-plugins/access-control/src/test/java/org/apache/qpid/server/security/access/plugins/ACLFileAccessControlProviderFactoryTest.java @@ -23,11 +23,13 @@ package org.apache.qpid.server.security.access.plugins; import java.io.File; import java.util.HashMap; import java.util.Map; +import java.util.UUID; import java.util.regex.Pattern; import org.apache.qpid.server.configuration.IllegalConfigurationException; -import org.apache.qpid.server.logging.EventLogger; import org.apache.qpid.server.logging.EventLoggerProvider; +import org.apache.qpid.server.model.AccessControlProvider; +import org.apache.qpid.server.model.Broker; import org.apache.qpid.server.model.GroupProvider; import org.apache.qpid.server.security.AccessControl; import org.apache.qpid.server.security.access.FileAccessControlProviderConstants; @@ -36,25 +38,36 @@ import org.apache.qpid.test.utils.TestFileUtils; import static org.mockito.Mockito.mock; -public class DefaultAccessControlFactoryTest extends QpidTestCase +public class ACLFileAccessControlProviderFactoryTest extends QpidTestCase { public void testCreateInstanceWhenAclFileIsNotPresent() { - DefaultAccessControlFactory factory = new DefaultAccessControlFactory(); + ACLFileAccessControlProviderFactory factory = new ACLFileAccessControlProviderFactory(); Map<String, Object> attributes = new HashMap<String, Object>(); - AccessControl acl = factory.createInstance(attributes, mock(EventLoggerProvider.class)); - assertNull("ACL was created without a configuration file", acl); + attributes.put(AccessControlProvider.ID, UUID.randomUUID()); + attributes.put(AccessControlProvider.NAME, "acl"); + try + { + AccessControlProvider acl = factory.create(attributes, mock(Broker.class)); + fail("ACL was created without a configuration file path specified"); + } + catch(IllegalArgumentException e) + { + // pass + } } public void testCreateInstanceWhenAclFileIsSpecified() { File aclFile = TestFileUtils.createTempFile(this, ".acl", "ACL ALLOW all all"); - DefaultAccessControlFactory factory = new DefaultAccessControlFactory(); + 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(FileAccessControlProviderConstants.PATH, aclFile.getAbsolutePath()); - AccessControl acl = factory.createInstance(attributes, mock(EventLoggerProvider.class)); - acl.open(); + AccessControlProvider acl = factory.create(attributes, mock(Broker.class)); + acl.getAccessControl().open(); assertNotNull("ACL was not created from acl file: " + aclFile.getAbsolutePath(), acl); } @@ -63,14 +76,16 @@ public class DefaultAccessControlFactoryTest 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()); - DefaultAccessControlFactory factory = new DefaultAccessControlFactory(); + 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(FileAccessControlProviderConstants.PATH, aclFile.getAbsolutePath()); try { - AccessControl control = factory.createInstance(attributes, mock(EventLoggerProvider.class)); - control.open(); + AccessControlProvider control = factory.create(attributes, mock(Broker.class)); + control.getAccessControl().open(); fail("It should not be possible to create and initialise ACL with non existing file"); } catch (IllegalConfigurationException e) diff --git a/qpid/java/broker-plugins/jdbc-provider-bone/src/main/java/org/apache/qpid/server/store/jdbc/bonecp/BoneCPConnectionProvider.java b/qpid/java/broker-plugins/jdbc-provider-bone/src/main/java/org/apache/qpid/server/store/jdbc/bonecp/BoneCPConnectionProvider.java index 2b45aad5e5..8bc3a10320 100644 --- a/qpid/java/broker-plugins/jdbc-provider-bone/src/main/java/org/apache/qpid/server/store/jdbc/bonecp/BoneCPConnectionProvider.java +++ b/qpid/java/broker-plugins/jdbc-provider-bone/src/main/java/org/apache/qpid/server/store/jdbc/bonecp/BoneCPConnectionProvider.java @@ -20,15 +20,14 @@ */ package org.apache.qpid.server.store.jdbc.bonecp; -import java.sql.Connection; -import java.sql.SQLException; -import java.util.Map; - +import com.jolbox.bonecp.BoneCP; +import com.jolbox.bonecp.BoneCPConfig; import org.apache.qpid.server.store.jdbc.ConnectionProvider; import org.apache.qpid.server.util.MapValueConverter; -import com.jolbox.bonecp.BoneCP; -import com.jolbox.bonecp.BoneCPConfig; +import java.sql.Connection; +import java.sql.SQLException; +import java.util.Map; public class BoneCPConnectionProvider implements ConnectionProvider { diff --git a/qpid/java/broker-plugins/jdbc-provider-bone/src/main/java/org/apache/qpid/server/store/jdbc/bonecp/BoneCPConnectionProviderFactory.java b/qpid/java/broker-plugins/jdbc-provider-bone/src/main/java/org/apache/qpid/server/store/jdbc/bonecp/BoneCPConnectionProviderFactory.java index 58206b270c..3668ba308e 100644 --- a/qpid/java/broker-plugins/jdbc-provider-bone/src/main/java/org/apache/qpid/server/store/jdbc/bonecp/BoneCPConnectionProviderFactory.java +++ b/qpid/java/broker-plugins/jdbc-provider-bone/src/main/java/org/apache/qpid/server/store/jdbc/bonecp/BoneCPConnectionProviderFactory.java @@ -34,7 +34,6 @@ public class BoneCPConnectionProviderFactory implements JDBCConnectionProviderFa return "BONECP"; } - @Override public ConnectionProvider getConnectionProvider(String connectionUrl, Map<String, Object> storeSettings) throws SQLException { diff --git a/qpid/java/broker-plugins/management-amqp/src/main/java/org/apache/qpid/server/management/amqp/ManagementNode.java b/qpid/java/broker-plugins/management-amqp/src/main/java/org/apache/qpid/server/management/amqp/ManagementNode.java index 788ce63c8f..42a04b3c0f 100644 --- a/qpid/java/broker-plugins/management-amqp/src/main/java/org/apache/qpid/server/management/amqp/ManagementNode.java +++ b/qpid/java/broker-plugins/management-amqp/src/main/java/org/apache/qpid/server/management/amqp/ManagementNode.java @@ -37,7 +37,7 @@ import org.apache.qpid.server.model.ConfigurationChangeListener; import org.apache.qpid.server.model.ConfiguredObject; import org.apache.qpid.server.model.Model; import org.apache.qpid.server.model.State; -import org.apache.qpid.server.model.adapter.AbstractConfiguredObject; +import org.apache.qpid.server.model.AbstractConfiguredObject; import org.apache.qpid.server.plugin.MessageConverter; import org.apache.qpid.server.plugin.SystemNodeCreator; import org.apache.qpid.server.protocol.AMQSessionModel; diff --git a/qpid/java/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/HttpManagement.java b/qpid/java/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/HttpManagement.java index eed387f8c5..b4ce0ccf9a 100644 --- a/qpid/java/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/HttpManagement.java +++ b/qpid/java/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/HttpManagement.java @@ -20,17 +20,6 @@ */ package org.apache.qpid.server.management.plugin; -import java.lang.reflect.Type; -import java.net.SocketAddress; -import java.security.GeneralSecurityException; -import java.util.*; - -import javax.net.ssl.KeyManager; -import javax.net.ssl.SSLContext; -import javax.net.ssl.TrustManager; -import javax.net.ssl.X509TrustManager; -import javax.servlet.DispatcherType; - import org.apache.log4j.Logger; import org.apache.qpid.server.configuration.IllegalConfigurationException; import org.apache.qpid.server.logging.messages.ManagementConsoleMessages; @@ -39,21 +28,10 @@ import org.apache.qpid.server.management.plugin.filter.RedirectingAuthorisationF import org.apache.qpid.server.management.plugin.servlet.DefinedFileServlet; import org.apache.qpid.server.management.plugin.servlet.FileServlet; import org.apache.qpid.server.management.plugin.servlet.LogFileServlet; -import org.apache.qpid.server.management.plugin.servlet.rest.HelperServlet; -import org.apache.qpid.server.management.plugin.servlet.rest.LogFileListingServlet; -import org.apache.qpid.server.management.plugin.servlet.rest.LogRecordsServlet; -import org.apache.qpid.server.management.plugin.servlet.rest.LogoutServlet; -import org.apache.qpid.server.management.plugin.servlet.rest.MessageContentServlet; -import org.apache.qpid.server.management.plugin.servlet.rest.MessageServlet; -import org.apache.qpid.server.management.plugin.servlet.rest.LoggedOnUserPreferencesServlet; -import org.apache.qpid.server.management.plugin.servlet.rest.UserPreferencesServlet; -import org.apache.qpid.server.management.plugin.servlet.rest.RestServlet; -import org.apache.qpid.server.management.plugin.servlet.rest.SaslServlet; -import org.apache.qpid.server.management.plugin.servlet.rest.StructureServlet; +import org.apache.qpid.server.management.plugin.servlet.rest.*; import org.apache.qpid.server.model.*; import org.apache.qpid.server.model.Queue; import org.apache.qpid.server.model.adapter.AbstractPluginAdapter; -import org.apache.qpid.server.plugin.PluginFactory; import org.apache.qpid.server.util.MapValueConverter; import org.apache.qpid.server.util.ServerScopedRuntimeException; import org.apache.qpid.transport.network.security.ssl.QpidMultipleTrustManager; @@ -67,6 +45,17 @@ import org.eclipse.jetty.servlet.ServletContextHandler; import org.eclipse.jetty.servlet.ServletHolder; import org.eclipse.jetty.util.ssl.SslContextFactory; +import javax.net.ssl.KeyManager; +import javax.net.ssl.SSLContext; +import javax.net.ssl.TrustManager; +import javax.net.ssl.X509TrustManager; +import javax.servlet.DispatcherType; +import java.lang.reflect.Type; +import java.net.SocketAddress; +import java.security.GeneralSecurityException; +import java.util.*; + +@ManagedObject( category = false, type = "MANAGEMENT-HTTP" ) public class HttpManagement extends AbstractPluginAdapter<HttpManagement> implements HttpManagementConfiguration<HttpManagement> { private final Logger _logger = Logger.getLogger(HttpManagement.class); @@ -109,7 +98,7 @@ public class HttpManagement extends AbstractPluginAdapter<HttpManagement> implem put(HTTPS_SASL_AUTHENTICATION_ENABLED, Boolean.class); put(NAME, String.class); put(TIME_OUT, Integer.class); - put(PluginFactory.PLUGIN_TYPE, String.class); + put(TYPE, String.class); }}); private static final String JSESSIONID_COOKIE_PREFIX = "JSESSIONID_"; diff --git a/qpid/java/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/HttpManagementConfiguration.java b/qpid/java/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/HttpManagementConfiguration.java index 3b159b1e5d..227271d439 100644 --- a/qpid/java/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/HttpManagementConfiguration.java +++ b/qpid/java/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/HttpManagementConfiguration.java @@ -25,6 +25,7 @@ import java.net.SocketAddress; import org.apache.qpid.server.model.AuthenticationProvider; import org.apache.qpid.server.model.ConfiguredObject; import org.apache.qpid.server.model.ManagedAttribute; +import org.apache.qpid.server.model.ManagedObject; import org.apache.qpid.server.model.Plugin; public interface HttpManagementConfiguration<X extends HttpManagementConfiguration<X>> extends Plugin<X> diff --git a/qpid/java/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/HttpManagementFactory.java b/qpid/java/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/HttpManagementFactory.java index fd40f56ef8..0431954879 100644 --- a/qpid/java/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/HttpManagementFactory.java +++ b/qpid/java/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/HttpManagementFactory.java @@ -18,30 +18,29 @@ */ package org.apache.qpid.server.management.plugin; +import org.apache.qpid.server.model.AbstractConfiguredObjectTypeFactory; +import org.apache.qpid.server.model.Broker; +import org.apache.qpid.server.model.ConfiguredObject; + +import java.util.HashMap; import java.util.Map; import java.util.UUID; -import org.apache.qpid.server.model.Broker; -import org.apache.qpid.server.model.Plugin; -import org.apache.qpid.server.plugin.PluginFactory; - -public class HttpManagementFactory implements PluginFactory +public class HttpManagementFactory extends AbstractConfiguredObjectTypeFactory<HttpManagement> { - @Override - public Plugin createInstance(UUID id, Map<String, Object> attributes, Broker broker) + public HttpManagementFactory() { - if (!HttpManagement.PLUGIN_TYPE.equals(attributes.get(PLUGIN_TYPE))) - { - return null; - } - - return new HttpManagement(id, broker, attributes); + super(HttpManagement.class); } @Override - public String getType() + public HttpManagement createInstance(final Map<String, Object> attributes, final ConfiguredObject<?>... parents) { - return "HTTP Management"; + Map<String,Object> attributesWithoutId = new HashMap<String, Object>(attributes); + Object idObj = attributesWithoutId.remove(ConfiguredObject.ID); + UUID id = idObj == null ? UUID.randomUUID() : idObj instanceof UUID ? (UUID) idObj : UUID.fromString(idObj.toString()); + return new HttpManagement(id, getParent(Broker.class,parents), attributes); } + } diff --git a/qpid/java/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/servlet/rest/RestServlet.java b/qpid/java/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/servlet/rest/RestServlet.java index 005358faf4..00126200f8 100644 --- a/qpid/java/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/servlet/rest/RestServlet.java +++ b/qpid/java/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/servlet/rest/RestServlet.java @@ -458,6 +458,7 @@ public class RestServlet extends AbstractServlet catch (RuntimeException e) { setResponseStatus(response, e); + e.printStackTrace(); } } diff --git a/qpid/java/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/servlet/rest/action/ListAccessControlProviderAttributes.java b/qpid/java/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/servlet/rest/action/ListAccessControlProviderAttributes.java index 6887217016..84d05997b5 100644 --- a/qpid/java/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/servlet/rest/action/ListAccessControlProviderAttributes.java +++ b/qpid/java/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/servlet/rest/action/ListAccessControlProviderAttributes.java @@ -26,21 +26,21 @@ import java.util.TreeMap; import org.apache.qpid.server.management.plugin.servlet.rest.Action; import org.apache.qpid.server.model.Broker; -import org.apache.qpid.server.plugin.AccessControlFactory; +import org.apache.qpid.server.plugin.AccessControlProviderFactory; import org.apache.qpid.server.plugin.QpidServiceLoader; public class ListAccessControlProviderAttributes implements Action { private static final String ATTRIBUTES = "attributes"; private static final String DESCRIPTIONS = "descriptions"; - private Map<String, AccessControlFactory> _factories; + private Map<String, AccessControlProviderFactory> _factories; public ListAccessControlProviderAttributes() { - _factories = new TreeMap<String, AccessControlFactory>(); - Iterable<AccessControlFactory> factories = new QpidServiceLoader<AccessControlFactory>() - .instancesOf(AccessControlFactory.class); - for (AccessControlFactory factory : factories) + _factories = new TreeMap<String, AccessControlProviderFactory>(); + Iterable<AccessControlProviderFactory> factories = new QpidServiceLoader<AccessControlProviderFactory>() + .instancesOf(AccessControlProviderFactory.class); + for (AccessControlProviderFactory factory : factories) { _factories.put(factory.getType(), factory); } @@ -58,10 +58,11 @@ public class ListAccessControlProviderAttributes implements Action Map<String, Object> attributes = new TreeMap<String, Object>(); for (String providerType : _factories.keySet()) { - AccessControlFactory factory = _factories.get(providerType); + AccessControlProviderFactory<?> factory = _factories.get(providerType); Map<String, Object> data = new HashMap<String, Object>(); - data.put(ATTRIBUTES, factory.getAttributeNames()); + // TODO RG - fix + // data.put(ATTRIBUTES, factory.getAttributeNames()); Map<String, String> resources = factory.getAttributeDescriptions(); if (resources != null) { diff --git a/qpid/java/broker-plugins/access-control/src/main/resources/META-INF/services/org.apache.qpid.server.plugin.AccessControlFactory b/qpid/java/broker-plugins/management-http/src/main/resources/META-INF/services/org.apache.qpid.server.plugin.ConfiguredObjectTypeFactory index b6c429baab..316698a10e 100644 --- a/qpid/java/broker-plugins/access-control/src/main/resources/META-INF/services/org.apache.qpid.server.plugin.AccessControlFactory +++ b/qpid/java/broker-plugins/management-http/src/main/resources/META-INF/services/org.apache.qpid.server.plugin.ConfiguredObjectTypeFactory @@ -16,4 +16,6 @@ # specific language governing permissions and limitations # under the License. # -org.apache.qpid.server.security.access.plugins.DefaultAccessControlFactory +org.apache.qpid.server.management.plugin.HttpManagementFactory + + diff --git a/qpid/java/broker-plugins/management-http/src/test/java/org/apache/qpid/server/management/plugin/HttpManagementFactoryTest.java b/qpid/java/broker-plugins/management-http/src/test/java/org/apache/qpid/server/management/plugin/HttpManagementFactoryTest.java index 10bc9f941b..2fd057437a 100644 --- a/qpid/java/broker-plugins/management-http/src/test/java/org/apache/qpid/server/management/plugin/HttpManagementFactoryTest.java +++ b/qpid/java/broker-plugins/management-http/src/test/java/org/apache/qpid/server/management/plugin/HttpManagementFactoryTest.java @@ -18,41 +18,33 @@ */ package org.apache.qpid.server.management.plugin; -import static org.mockito.Mockito.mock; +import org.apache.qpid.server.model.Broker; +import org.apache.qpid.server.model.ConfiguredObject; +import org.apache.qpid.test.utils.QpidTestCase; import java.util.HashMap; import java.util.Map; import java.util.UUID; -import org.apache.qpid.server.model.Broker; -import org.apache.qpid.server.plugin.PluginFactory; -import org.apache.qpid.test.utils.QpidTestCase; +import static org.mockito.Mockito.mock; public class HttpManagementFactoryTest extends QpidTestCase { private static final int SESSION_TIMEOUT = 3600; - private PluginFactory _pluginFactory = new HttpManagementFactory(); + private HttpManagementFactory _pluginFactory = new HttpManagementFactory(); private Map<String, Object> _attributes = new HashMap<String, Object>(); private Broker _broker = mock(Broker.class); private UUID _id = UUID.randomUUID(); - public void testCreateInstanceReturnsNullWhenPluginTypeMissing() throws Exception - { - assertNull(_pluginFactory.createInstance(_id, _attributes, _broker)); - } - public void testCreateInstanceReturnsNullWhenPluginTypeNotHttp() - { - _attributes.put(PluginFactory.PLUGIN_TYPE, "notHttp"); - assertNull(_pluginFactory.createInstance(_id, _attributes, _broker)); - } public void testCreateInstance() throws Exception { - _attributes.put(PluginFactory.PLUGIN_TYPE, HttpManagement.PLUGIN_TYPE); + _attributes.put(ConfiguredObject.TYPE, HttpManagement.PLUGIN_TYPE); _attributes.put(HttpManagement.TIME_OUT, SESSION_TIMEOUT); + _attributes.put(ConfiguredObject.ID, _id); - HttpManagement management = (HttpManagement) _pluginFactory.createInstance(_id, _attributes, _broker); + HttpManagement management = _pluginFactory.createInstance(_attributes, _broker); assertEquals(_broker, management.getParent(Broker.class)); assertEquals(SESSION_TIMEOUT, management.getSessionTimeout()); diff --git a/qpid/java/broker-plugins/management-jmx/src/main/java/org/apache/qpid/server/jmx/JMXManagement.java b/qpid/java/broker-plugins/management-jmx/src/main/java/org/apache/qpid/server/jmx/JMXManagement.java index 64667dc96c..afad673f84 100644 --- a/qpid/java/broker-plugins/management-jmx/src/main/java/org/apache/qpid/server/jmx/JMXManagement.java +++ b/qpid/java/broker-plugins/management-jmx/src/main/java/org/apache/qpid/server/jmx/JMXManagement.java @@ -21,30 +21,30 @@ package org.apache.qpid.server.jmx; -import java.io.IOException; -import java.lang.reflect.Type; -import java.util.Collection; -import java.util.HashMap; -import java.util.Map; -import java.util.UUID; - -import javax.management.JMException; - import org.apache.log4j.Logger; import org.apache.qpid.server.configuration.IllegalConfigurationException; import org.apache.qpid.server.jmx.mbeans.LoggingManagementMBean; -import org.apache.qpid.server.jmx.mbeans.UserManagementMBean; import org.apache.qpid.server.jmx.mbeans.ServerInformationMBean; import org.apache.qpid.server.jmx.mbeans.Shutdown; +import org.apache.qpid.server.jmx.mbeans.UserManagementMBean; import org.apache.qpid.server.jmx.mbeans.VirtualHostMBean; import org.apache.qpid.server.logging.log4j.LoggingManagementFacade; import org.apache.qpid.server.model.*; +import org.apache.qpid.server.model.ManagedObject; import org.apache.qpid.server.model.adapter.AbstractPluginAdapter; -import org.apache.qpid.server.plugin.PluginFactory; import org.apache.qpid.server.plugin.QpidServiceLoader; import org.apache.qpid.server.util.MapValueConverter; import org.apache.qpid.server.util.ServerScopedRuntimeException; +import javax.management.JMException; +import java.io.IOException; +import java.lang.reflect.Type; +import java.util.Collection; +import java.util.HashMap; +import java.util.Map; +import java.util.UUID; + +@ManagedObject( category = false , type = "MANAGEMENT-JMX" ) public class JMXManagement extends AbstractPluginAdapter<JMXManagement> implements ConfigurationChangeListener { private static final Logger LOGGER = Logger.getLogger(JMXManagement.class); @@ -63,14 +63,15 @@ public class JMXManagement extends AbstractPluginAdapter<JMXManagement> implemen private static final Map<String, Object> DEFAULTS = new HashMap<String, Object>(){{ put(USE_PLATFORM_MBEAN_SERVER, DEFAULT_USE_PLATFORM_MBEAN_SERVER); put(NAME, DEFAULT_NAME); - put(PluginFactory.PLUGIN_TYPE, PLUGIN_TYPE); + put(TYPE, PLUGIN_TYPE); }}; @SuppressWarnings("serial") private static final Map<String, Type> ATTRIBUTE_TYPES = new HashMap<String, Type>(){{ put(USE_PLATFORM_MBEAN_SERVER, Boolean.class); put(NAME, String.class); - put(PluginFactory.PLUGIN_TYPE, String.class); + put(TYPE, String.class); + put(TYPE, String.class); }}; private JMXManagedObjectRegistry _objectRegistry; diff --git a/qpid/java/broker-plugins/management-jmx/src/main/java/org/apache/qpid/server/jmx/JMXManagementFactory.java b/qpid/java/broker-plugins/management-jmx/src/main/java/org/apache/qpid/server/jmx/JMXManagementFactory.java index 486ea5e6f1..dd21225099 100644 --- a/qpid/java/broker-plugins/management-jmx/src/main/java/org/apache/qpid/server/jmx/JMXManagementFactory.java +++ b/qpid/java/broker-plugins/management-jmx/src/main/java/org/apache/qpid/server/jmx/JMXManagementFactory.java @@ -18,31 +18,27 @@ */ package org.apache.qpid.server.jmx; +import org.apache.qpid.server.model.AbstractConfiguredObjectTypeFactory; +import org.apache.qpid.server.model.Broker; +import org.apache.qpid.server.model.ConfiguredObject; + +import java.util.HashMap; import java.util.Map; import java.util.UUID; -import org.apache.qpid.server.model.Broker; -import org.apache.qpid.server.model.Plugin; -import org.apache.qpid.server.plugin.PluginFactory; - -public class JMXManagementFactory implements PluginFactory +public class JMXManagementFactory extends AbstractConfiguredObjectTypeFactory<JMXManagement> { - @Override - public Plugin createInstance(UUID id, Map<String, Object> attributes, Broker broker) + public JMXManagementFactory() { - if (JMXManagement.PLUGIN_TYPE.equals(attributes.get(PLUGIN_TYPE))) - { - return new JMXManagement(id, broker, attributes); - } - else - { - return null; - } + super(JMXManagement.class); } @Override - public String getType() + public JMXManagement createInstance(final Map<String, Object> attributes, final ConfiguredObject<?>... parents) { - return "JMX Management"; + Map<String,Object> attributesWithoutId = new HashMap<String, Object>(attributes); + Object idObj = attributesWithoutId.remove(ConfiguredObject.ID); + UUID id = idObj == null ? UUID.randomUUID() : idObj instanceof UUID ? (UUID) idObj : UUID.fromString(idObj.toString()); + return new JMXManagement(id, getParent(Broker.class,parents),attributes); } } diff --git a/qpid/java/broker-plugins/management-jmx/src/main/resources/META-INF/services/org.apache.qpid.server.plugin.ConfiguredObjectTypeFactory b/qpid/java/broker-plugins/management-jmx/src/main/resources/META-INF/services/org.apache.qpid.server.plugin.ConfiguredObjectTypeFactory new file mode 100644 index 0000000000..d77477e044 --- /dev/null +++ b/qpid/java/broker-plugins/management-jmx/src/main/resources/META-INF/services/org.apache.qpid.server.plugin.ConfiguredObjectTypeFactory @@ -0,0 +1,21 @@ +# +# 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. +# +org.apache.qpid.server.jmx.JMXManagementFactory + + diff --git a/qpid/java/broker-plugins/management-jmx/src/test/java/org/apache/qpid/server/jmx/JMXManagementFactoryTest.java b/qpid/java/broker-plugins/management-jmx/src/test/java/org/apache/qpid/server/jmx/JMXManagementFactoryTest.java index 5af1369239..62f0ad558a 100644 --- a/qpid/java/broker-plugins/management-jmx/src/test/java/org/apache/qpid/server/jmx/JMXManagementFactoryTest.java +++ b/qpid/java/broker-plugins/management-jmx/src/test/java/org/apache/qpid/server/jmx/JMXManagementFactoryTest.java @@ -18,15 +18,15 @@ */ package org.apache.qpid.server.jmx; -import static org.mockito.Mockito.mock; +import org.apache.qpid.server.model.Broker; +import org.apache.qpid.server.model.ConfiguredObject; +import org.apache.qpid.test.utils.QpidTestCase; import java.util.HashMap; import java.util.Map; import java.util.UUID; -import org.apache.qpid.server.model.Broker; -import org.apache.qpid.server.plugin.PluginFactory; -import org.apache.qpid.test.utils.QpidTestCase; +import static org.mockito.Mockito.mock; public class JMXManagementFactoryTest extends QpidTestCase { @@ -37,24 +37,16 @@ public class JMXManagementFactoryTest extends QpidTestCase public void testJMXConfigured() throws Exception { - _attributes.put(PluginFactory.PLUGIN_TYPE, JMXManagement.PLUGIN_TYPE); + _attributes.put(ConfiguredObject.ID,UUID.randomUUID()); + _attributes.put(ConfiguredObject.TYPE, JMXManagement.PLUGIN_TYPE); - JMXManagement jmxManagement = (JMXManagement) _jmxManagementFactory.createInstance(_id, _attributes, _broker); + JMXManagement jmxManagement = _jmxManagementFactory.createInstance( _attributes, _broker); assertNotNull(jmxManagement); - assertEquals("Unexpected plugin type", JMXManagement.PLUGIN_TYPE, jmxManagement.getAttribute(JMXManagementFactory.PLUGIN_TYPE)); + assertEquals("Unexpected plugin type", JMXManagement.PLUGIN_TYPE, jmxManagement.getType()); assertEquals("Unexpected default mbean platform", JMXManagement.DEFAULT_USE_PLATFORM_MBEAN_SERVER, jmxManagement.getAttribute(JMXManagement.USE_PLATFORM_MBEAN_SERVER)); assertEquals("Unexpected default name", JMXManagement.DEFAULT_NAME, jmxManagement.getAttribute(JMXManagement.NAME)); } - public void testCreateInstanceReturnsNullWhenPluginTypeMissing() - { - assertNull(_jmxManagementFactory.createInstance(_id, _attributes, _broker)); - } - public void testCreateInstanceReturnsNullWhenPluginTypeNotJmx() - { - _attributes.put(PluginFactory.PLUGIN_TYPE, "notJmx"); - assertNull(_jmxManagementFactory.createInstance(_id, _attributes, _broker)); - } } |
