Return-Path: X-Original-To: apmail-activemq-commits-archive@www.apache.org Delivered-To: apmail-activemq-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 2BA6D10CF2 for ; Thu, 15 Jan 2015 17:19:05 +0000 (UTC) Received: (qmail 40133 invoked by uid 500); 15 Jan 2015 17:19:07 -0000 Delivered-To: apmail-activemq-commits-archive@activemq.apache.org Received: (qmail 40042 invoked by uid 500); 15 Jan 2015 17:19:06 -0000 Mailing-List: contact commits-help@activemq.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@activemq.apache.org Delivered-To: mailing list commits@activemq.apache.org Received: (qmail 40023 invoked by uid 99); 15 Jan 2015 17:19:06 -0000 Received: from tyr.zones.apache.org (HELO tyr.zones.apache.org) (140.211.11.114) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 15 Jan 2015 17:19:06 +0000 Received: by tyr.zones.apache.org (Postfix, from userid 65534) id 86EA4A44AC2; Thu, 15 Jan 2015 17:19:06 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: clebertsuconic@apache.org To: commits@activemq.apache.org Date: Thu, 15 Jan 2015 17:19:26 -0000 Message-Id: <860c1c65362a4ac393cc37799b6316b1@git.apache.org> In-Reply-To: <47e9dfd5faf44225b16f21fb526ed815@git.apache.org> References: <47e9dfd5faf44225b16f21fb526ed815@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [24/27] activemq-6 git commit: ACTIVEMQ6-67 - cleaned up configuration http://git-wip-us.apache.org/repos/asf/activemq-6/blob/4b63891a/activemq-server/src/main/java/org/apache/activemq/core/deployers/DeploymentManager.java ---------------------------------------------------------------------- diff --git a/activemq-server/src/main/java/org/apache/activemq/core/deployers/DeploymentManager.java b/activemq-server/src/main/java/org/apache/activemq/core/deployers/DeploymentManager.java deleted file mode 100644 index 6f0f882..0000000 --- a/activemq-server/src/main/java/org/apache/activemq/core/deployers/DeploymentManager.java +++ /dev/null @@ -1,41 +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.activemq.core.deployers; - -import org.apache.activemq.core.server.ActiveMQComponent; - -/** - * This class manages any configuration files available. It will notify any deployers registered with it on changes. - * - * @author Andy Taylor - */ -public interface DeploymentManager extends ActiveMQComponent -{ - /** - * registers a deployable object which will handle the deployment of URL's - * @param deployer The deployable object - * @throws Exception - */ - void registerDeployer(Deployer deployer) throws Exception; - - /** - * unregisters a deployable object which will handle the deployment of URL's - * @param deployer The deployable object - * @throws Exception - */ - void unregisterDeployer(Deployer deployer) throws Exception; -} http://git-wip-us.apache.org/repos/asf/activemq-6/blob/4b63891a/activemq-server/src/main/java/org/apache/activemq/core/deployers/impl/AddressSettingsDeployer.java ---------------------------------------------------------------------- diff --git a/activemq-server/src/main/java/org/apache/activemq/core/deployers/impl/AddressSettingsDeployer.java b/activemq-server/src/main/java/org/apache/activemq/core/deployers/impl/AddressSettingsDeployer.java deleted file mode 100644 index d3af73a..0000000 --- a/activemq-server/src/main/java/org/apache/activemq/core/deployers/impl/AddressSettingsDeployer.java +++ /dev/null @@ -1,106 +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.activemq.core.deployers.impl; - -import org.apache.activemq.api.core.Pair; -import org.apache.activemq.core.deployers.DeploymentManager; -import org.apache.activemq.core.settings.HierarchicalRepository; -import org.apache.activemq.core.settings.impl.AddressSettings; -import org.w3c.dom.Node; - -/** - * A deployer for creating a set of queue settings and adding them to a repository - * - * @author Andy Taylor - */ -public class AddressSettingsDeployer extends XmlDeployer -{ - private final HierarchicalRepository addressSettingsRepository; - - private final FileConfigurationParser parser = new FileConfigurationParser(); - - public AddressSettingsDeployer(final DeploymentManager deploymentManager, - final HierarchicalRepository addressSettingsRepository) - { - super(deploymentManager); - this.addressSettingsRepository = addressSettingsRepository; - } - - /** - * the names of the elements to deploy - * - * @return the names of the elements to deploy - */ - @Override - public String[] getElementTagName() - { - return new String[]{"address-setting"}; - } - - @Override - public void validate(final Node rootNode) throws Exception - { - org.apache.activemq.utils.XMLUtil.validate(rootNode, "schema/activemq-configuration.xsd"); - } - - /** - * deploy an element - * - * @param node the element to deploy - * @throws Exception - */ - @Override - public void deploy(final Node node) throws Exception - { - - Pair setting = parser.parseAddressSettings(node); - - addressSettingsRepository.addMatch(setting.getA(), setting.getB()); - } - - @Override - public String[] getDefaultConfigFileNames() - { - return new String[]{"activemq-configuration.xml", "activemq-queues.xml"}; - } - - /** - * Undeploys an element. - * - * @param node the element to undeploy - * @throws Exception - */ - @Override - public void undeploy(final Node node) throws Exception - { - String match = node.getAttributes().getNamedItem(getKeyAttribute()).getNodeValue(); - - addressSettingsRepository.removeMatch(match); - } - - /** - * the key attribute for the element, usually 'name' but can be overridden - * - * @return the key attribute - */ - @Override - public String getKeyAttribute() - { - return "match"; - } - -} http://git-wip-us.apache.org/repos/asf/activemq-6/blob/4b63891a/activemq-server/src/main/java/org/apache/activemq/core/deployers/impl/BasicUserCredentialsDeployer.java ---------------------------------------------------------------------- diff --git a/activemq-server/src/main/java/org/apache/activemq/core/deployers/impl/BasicUserCredentialsDeployer.java b/activemq-server/src/main/java/org/apache/activemq/core/deployers/impl/BasicUserCredentialsDeployer.java deleted file mode 100644 index 3f2d2b0..0000000 --- a/activemq-server/src/main/java/org/apache/activemq/core/deployers/impl/BasicUserCredentialsDeployer.java +++ /dev/null @@ -1,149 +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.activemq.core.deployers.impl; - -import org.apache.activemq.core.deployers.DeploymentManager; -import org.apache.activemq.spi.core.security.ActiveMQSecurityManager; -import org.apache.activemq.utils.PasswordMaskingUtil; -import org.apache.activemq.utils.SensitiveDataCodec; -import org.w3c.dom.Node; -import org.w3c.dom.NodeList; - -/** - * deployer for adding security loaded from the file "activemq-users.xml" - * - * @author Andy Taylor - */ -public class BasicUserCredentialsDeployer extends XmlDeployer -{ - private final ActiveMQSecurityManager activeMQSecurityManager; - - private static final String PASSWORD_ATTRIBUTE = "password"; - - private static final String ROLES_NODE = "role"; - - private static final String ROLE_ATTR_NAME = "name"; - - private static final String DEFAULT_USER = "defaultuser"; - - private static final String USER = "user"; - - private static final String MASK_PASSWORD = "mask-password"; - - private static final String PASSWORD_CODEC = "password-codec"; - - private boolean maskPassword = false; - - private SensitiveDataCodec passwordCodec; - - public BasicUserCredentialsDeployer(final DeploymentManager deploymentManager, - final ActiveMQSecurityManager activeMQSecurityManager) - { - super(deploymentManager); - - this.activeMQSecurityManager = activeMQSecurityManager; - } - - @Override - public String[] getElementTagName() - { - return new String[]{MASK_PASSWORD, PASSWORD_CODEC, DEFAULT_USER, USER}; - } - - @Override - public void validate(final Node rootNode) throws Exception - { - org.apache.activemq.utils.XMLUtil.validate(rootNode, "schema/activemq-users.xsd"); - } - - @Override - public void deploy(final Node node) throws Exception - { - String nodeName = node.getNodeName(); - - if (MASK_PASSWORD.equals(nodeName)) - { - String value = node.getTextContent().trim(); - - maskPassword = Boolean.parseBoolean(value); - - if (maskPassword) - { - passwordCodec = PasswordMaskingUtil.getDefaultCodec(); - } - return; - } - - if (PASSWORD_CODEC.equals(nodeName)) - { - if (maskPassword) - { - String codecDesc = node.getTextContent(); - - passwordCodec = PasswordMaskingUtil.getCodec(codecDesc); - } - return; - } - - String username = node.getAttributes().getNamedItem("name").getNodeValue(); - String password = node.getAttributes() - .getNamedItem(BasicUserCredentialsDeployer.PASSWORD_ATTRIBUTE) - .getNodeValue(); - - if (maskPassword) - { - if ((password != null) && (!"".equals(password.trim()))) - { - password = passwordCodec.decode(password); - } - } - - // add the user - activeMQSecurityManager.addUser(username, password); - - if (BasicUserCredentialsDeployer.DEFAULT_USER.equalsIgnoreCase(nodeName)) - { - activeMQSecurityManager.setDefaultUser(username); - } - NodeList children = node.getChildNodes(); - for (int i = 0; i < children.getLength(); i++) - { - Node child = children.item(i); - // and add any roles - if (BasicUserCredentialsDeployer.ROLES_NODE.equalsIgnoreCase(child.getNodeName())) - { - String role = child.getAttributes() - .getNamedItem(BasicUserCredentialsDeployer.ROLE_ATTR_NAME) - .getNodeValue(); - activeMQSecurityManager.addRole(username, role); - } - } - } - - @Override - public void undeploy(final Node node) throws Exception - { - String username = node.getAttributes().getNamedItem("name").getNodeValue(); - activeMQSecurityManager.removeUser(username); - } - - @Override - public String[] getDefaultConfigFileNames() - { - return new String[]{"activemq-users.xml"}; - } -} http://git-wip-us.apache.org/repos/asf/activemq-6/blob/4b63891a/activemq-server/src/main/java/org/apache/activemq/core/deployers/impl/FileConfigurationParser.java ---------------------------------------------------------------------- diff --git a/activemq-server/src/main/java/org/apache/activemq/core/deployers/impl/FileConfigurationParser.java b/activemq-server/src/main/java/org/apache/activemq/core/deployers/impl/FileConfigurationParser.java index f396da3..1bf0edb 100644 --- a/activemq-server/src/main/java/org/apache/activemq/core/deployers/impl/FileConfigurationParser.java +++ b/activemq-server/src/main/java/org/apache/activemq/core/deployers/impl/FileConfigurationParser.java @@ -51,7 +51,6 @@ import org.apache.activemq.core.config.ha.ReplicatedPolicyConfiguration; import org.apache.activemq.core.config.ha.SharedStoreMasterPolicyConfiguration; import org.apache.activemq.core.config.ha.SharedStoreSlavePolicyConfiguration; import org.apache.activemq.core.config.impl.ConfigurationImpl; -import org.apache.activemq.core.config.impl.FileConfiguration; import org.apache.activemq.core.config.impl.Validators; import org.apache.activemq.core.journal.impl.AIOSequentialFileFactory; import org.apache.activemq.core.journal.impl.JournalConstants; @@ -81,11 +80,6 @@ import org.w3c.dom.NodeList; */ public final class FileConfigurationParser extends XMLConfigurationUtil { - - // Constants ----------------------------------------------------- - - private static final String CONFIGURATION_SCHEMA_URL = "schema/activemq-configuration.xsd"; - // Security Parsing public static final String SECURITY_ELEMENT_NAME = "security-setting"; @@ -193,7 +187,6 @@ public final class FileConfigurationParser extends XMLConfigurationUtil public void parseMainConfig(final Element e, final Configuration config) throws Exception { - XMLUtil.validate(e, FileConfigurationParser.CONFIGURATION_SCHEMA_URL); config.setName(getString(e, "name", config.getName(), Validators.NO_CHECK)); @@ -457,9 +450,6 @@ public final class FileConfigurationParser extends XMLConfigurationUtil config.setResolveProtocols(getBoolean(e, "resolve-protocols", config.isResolveProtocols())); - // Defaults to true when using FileConfiguration - config.setFileDeploymentEnabled(getBoolean(e, "file-deployment-enabled", config instanceof FileConfiguration)); - config.setPersistenceEnabled(getBoolean(e, "persistence-enabled", config.isPersistenceEnabled())); http://git-wip-us.apache.org/repos/asf/activemq-6/blob/4b63891a/activemq-server/src/main/java/org/apache/activemq/core/deployers/impl/FileDeploymentManager.java ---------------------------------------------------------------------- diff --git a/activemq-server/src/main/java/org/apache/activemq/core/deployers/impl/FileDeploymentManager.java b/activemq-server/src/main/java/org/apache/activemq/core/deployers/impl/FileDeploymentManager.java deleted file mode 100644 index cb85425..0000000 --- a/activemq-server/src/main/java/org/apache/activemq/core/deployers/impl/FileDeploymentManager.java +++ /dev/null @@ -1,337 +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.activemq.core.deployers.impl; - -import java.io.File; -import java.io.IOException; -import java.io.UnsupportedEncodingException; -import java.net.MalformedURLException; -import java.net.URI; -import java.net.URISyntaxException; -import java.net.URL; -import java.net.URLDecoder; -import java.util.ArrayList; -import java.util.Enumeration; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.concurrent.Executors; -import java.util.concurrent.ScheduledExecutorService; -import java.util.concurrent.ScheduledFuture; -import java.util.concurrent.TimeUnit; - -import org.apache.activemq.api.core.Pair; -import org.apache.activemq.core.deployers.Deployer; -import org.apache.activemq.core.deployers.DeploymentManager; -import org.apache.activemq.core.server.ActiveMQServerLogger; - -/** - * @author Andy Taylor - * @author Tim Fox - */ -public class FileDeploymentManager implements Runnable, DeploymentManager -{ - private final List deployers = new ArrayList(); - - private final Map, DeployInfo> deployed = new HashMap, DeployInfo>(); - - private ScheduledExecutorService scheduler; - - private boolean started; - - private final long period; - - private ScheduledFuture future; - - public FileDeploymentManager(final long period) - { - this.period = period; - } - - public synchronized void start() throws Exception - { - if (started) - { - return; - } - - started = true; - - scheduler = Executors.newSingleThreadScheduledExecutor(); - - future = scheduler.scheduleWithFixedDelay(this, period, period, TimeUnit.MILLISECONDS); - } - - public synchronized void stop() - { - if (!started) - { - return; - } - - started = false; - - if (future != null) - { - future.cancel(false); - - future = null; - } - - scheduler.shutdown(); - - scheduler = null; - } - - public synchronized boolean isStarted() - { - return started; - } - - /** - * registers a Deployer object which will handle the deployment of URL's - * - * @param deployer The Deployer object - * @throws Exception - */ - public synchronized void registerDeployer(final Deployer deployer) throws Exception - { - if (!deployers.contains(deployer)) - { - deployers.add(deployer); - - String[] filenames = deployer.getConfigFileNames(); - - for (String filename : filenames) - { - ActiveMQServerLogger.LOGGER.debug("the filename is " + filename); - - Enumeration urls = Thread.currentThread().getContextClassLoader().getResources(filename); - - while (urls.hasMoreElements()) - { - URI uri = urls.nextElement().toURI(); - - ActiveMQServerLogger.LOGGER.debug("Got URI " + uri); - - try - { - ActiveMQServerLogger.LOGGER.debug("Deploying " + uri + " for " + deployer.getClass().getSimpleName()); - deployer.deploy(uri); - } - catch (Exception e) - { - ActiveMQServerLogger.LOGGER.errorDeployingURI(e, uri); - } - - Pair pair = new Pair(uri, deployer); - - deployed.put(pair, new DeployInfo(deployer, getFileFromURI(uri).lastModified())); - } - } - } - } - - @Override - public synchronized void unregisterDeployer(final Deployer deployer) throws Exception - { - if (deployers.remove(deployer)) - { - String[] filenames = deployer.getConfigFileNames(); - for (String filename : filenames) - { - Enumeration urls = Thread.currentThread().getContextClassLoader().getResources(filename); - while (urls.hasMoreElements()) - { - URI url = urls.nextElement().toURI(); - - Pair pair = new Pair(url, deployer); - - deployed.remove(pair); - } - } - } - } - - private File getFileFromURI(final URI uri) throws MalformedURLException, UnsupportedEncodingException - { - return new File(URLDecoder.decode(uri.toURL().getFile(), "UTF-8")); - } - - /** - * called by the ExecutorService every n seconds - */ - public synchronized void run() - { - if (!started) - { - return; - } - - try - { - for (Deployer deployer : deployers) - { - String[] filenames = deployer.getConfigFileNames(); - - for (String filename : filenames) - { - Enumeration urls = Thread.currentThread().getContextClassLoader().getResources(filename); - - while (urls.hasMoreElements()) - { - URL url = urls.nextElement(); - URI uri; - try - { - uri = url.toURI(); - } - catch (URISyntaxException e) - { - ActiveMQServerLogger.LOGGER.errorDeployingURI(e); - continue; - } - - Pair pair = new Pair(uri, deployer); - - DeployInfo info = deployed.get(pair); - - long newLastModified = getFileFromURI(uri).lastModified(); - - if (info == null) - { - try - { - deployer.deploy(uri); - - deployed.put(pair, new DeployInfo(deployer, getFileFromURI(uri).lastModified())); - } - catch (Exception e) - { - ActiveMQServerLogger.LOGGER.errorDeployingURI(e, uri); - } - } - else if (newLastModified > info.lastModified) - { - try - { - deployer.redeploy(uri); - - deployed.put(pair, new DeployInfo(deployer, getFileFromURI(uri).lastModified())); - } - catch (Exception e) - { - ActiveMQServerLogger.LOGGER.errorDeployingURI(e, uri); - } - } - } - } - } - List> toRemove = new ArrayList>(); - for (Map.Entry, DeployInfo> entry : deployed.entrySet()) - { - Pair pair = entry.getKey(); - try - { - if (!fileExists(pair.getA())) - { - Deployer deployer = entry.getValue().deployer; - ActiveMQServerLogger.LOGGER.debug("Undeploying " + deployer + " with url " + pair.getA()); - deployer.undeploy(pair.getA()); - toRemove.add(pair); - } - } - catch (URISyntaxException e) - { - ActiveMQServerLogger.LOGGER.errorUnDeployingURI(e, pair.getA()); - } - catch (Exception e) - { - ActiveMQServerLogger.LOGGER.errorUnDeployingURI(e, pair.getA()); - } - } - for (Pair pair : toRemove) - { - deployed.remove(pair); - } - } - catch (IOException e) - { - ActiveMQServerLogger.LOGGER.errorScanningURLs(e); - } - } - - public synchronized List getDeployers() - { - return deployers; - } - - public synchronized Map, DeployInfo> getDeployed() - { - return deployed; - } - - // Private ------------------------------------------------------- - - /** - * Checks if the URI is among the current thread context class loader's resources. - *

- * We do not check that the corresponding file exists using File.exists() directly as it would - * fail in the case the resource is loaded from inside an EAR file (see - * https://jira.jboss.org/jira/browse/HORNETQ-122) - * - * @throws URISyntaxException - */ - private boolean fileExists(final URI resourceURI) throws URISyntaxException - { - try - { - File f = getFileFromURI(resourceURI); // this was the original line, which doesn't work for - // File-URLs with white spaces: File f = new - // File(resourceURL.getPath()); - Enumeration resources = Thread.currentThread().getContextClassLoader().getResources(f.getName()); - while (resources.hasMoreElements()) - { - URI url = resources.nextElement().toURI(); - if (url.equals(resourceURI)) - { - return true; - } - } - } - catch (IOException e) - { - return false; - } - return false; - } - - // Inner classes ------------------------------------------------------------------------------------------- - - public static class DeployInfo - { - public Deployer deployer; - - public long lastModified; - - DeployInfo(final Deployer deployer, final long lastModified) - { - this.deployer = deployer; - this.lastModified = lastModified; - } - } -} http://git-wip-us.apache.org/repos/asf/activemq-6/blob/4b63891a/activemq-server/src/main/java/org/apache/activemq/core/deployers/impl/QueueDeployer.java ---------------------------------------------------------------------- diff --git a/activemq-server/src/main/java/org/apache/activemq/core/deployers/impl/QueueDeployer.java b/activemq-server/src/main/java/org/apache/activemq/core/deployers/impl/QueueDeployer.java deleted file mode 100644 index c821b9a..0000000 --- a/activemq-server/src/main/java/org/apache/activemq/core/deployers/impl/QueueDeployer.java +++ /dev/null @@ -1,97 +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.activemq.core.deployers.impl; - -import org.apache.activemq.api.core.SimpleString; -import org.apache.activemq.core.config.CoreQueueConfiguration; -import org.apache.activemq.core.deployers.DeploymentManager; -import org.apache.activemq.core.server.ActiveMQServer; -import org.w3c.dom.Node; - -/** - * A QueueDeployer - * - * @author Andy Taylor - * @author Jeff Mesnil - * @author Tim Fox - */ -public class QueueDeployer extends XmlDeployer -{ - private final ActiveMQServer server; - - private final FileConfigurationParser parser = new FileConfigurationParser(); - - public QueueDeployer(final DeploymentManager deploymentManager, final ActiveMQServer server) - { - super(deploymentManager); - - this.server = server; - } - - /** - * the names of the elements to deploy - * - * @return the names of the elements todeploy - */ - @Override - public String[] getElementTagName() - { - return new String[]{"queue"}; - } - - @Override - public void validate(final Node rootNode) throws Exception - { - org.apache.activemq.utils.XMLUtil.validate(rootNode, "schema/activemq-configuration.xsd"); - } - - /** - * deploy an element - * - * @param node the element to deploy - * @throws Exception - */ - @Override - public void deploy(final Node node) throws Exception - { - CoreQueueConfiguration queueConfig = parser.parseQueueConfiguration(node); - - server.deployQueue(SimpleString.toSimpleString(queueConfig.getAddress()), - SimpleString.toSimpleString(queueConfig.getName()), - SimpleString.toSimpleString(queueConfig.getFilterString()), - queueConfig.isDurable(), - false); - } - - @Override - public void undeploy(final Node node) throws Exception - { - // Undeploy means nothing for core queues - } - - /** - * The name of the configuration file name to look for for deployment - * - * @return The name of the config file - */ - @Override - public String[] getDefaultConfigFileNames() - { - return new String[]{"activemq-configuration.xml", "activemq-queues.xml"}; - } - -} http://git-wip-us.apache.org/repos/asf/activemq-6/blob/4b63891a/activemq-server/src/main/java/org/apache/activemq/core/deployers/impl/SecurityDeployer.java ---------------------------------------------------------------------- diff --git a/activemq-server/src/main/java/org/apache/activemq/core/deployers/impl/SecurityDeployer.java b/activemq-server/src/main/java/org/apache/activemq/core/deployers/impl/SecurityDeployer.java deleted file mode 100644 index 3f26196..0000000 --- a/activemq-server/src/main/java/org/apache/activemq/core/deployers/impl/SecurityDeployer.java +++ /dev/null @@ -1,117 +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.activemq.core.deployers.impl; - -import java.util.Set; - -import org.apache.activemq.api.core.Pair; -import org.apache.activemq.core.deployers.DeploymentManager; -import org.apache.activemq.core.security.Role; -import org.apache.activemq.core.settings.HierarchicalRepository; -import org.w3c.dom.Node; - -/** - * Deploys the security settings into a security repository and adds them to the security store. - * - * @author Andy Taylor - */ -public class SecurityDeployer extends XmlDeployer -{ - private static final String QUEUES_XML = "activemq-queues.xml"; - - private static final String MATCH = "match"; - - private final FileConfigurationParser parser = new FileConfigurationParser(); - - /** - * The repository to add to - */ - private final HierarchicalRepository> securityRepository; - - public SecurityDeployer(final DeploymentManager deploymentManager, - final HierarchicalRepository> securityRepository) - { - super(deploymentManager); - - this.securityRepository = securityRepository; - } - - /** - * the names of the elements to deploy - * - * @return the names of the elements todeploy - */ - @Override - public String[] getElementTagName() - { - return new String[]{FileConfigurationParser.SECURITY_ELEMENT_NAME}; - } - - @Override - public void validate(final Node rootNode) throws Exception - { - org.apache.activemq.utils.XMLUtil.validate(rootNode, "schema/activemq-configuration.xsd"); - } - - /** - * the key attribute for the element, usually 'name' but can be overridden - * - * @return the key attribute - */ - @Override - public String getKeyAttribute() - { - return SecurityDeployer.MATCH; - } - - /** - * deploy an element - * - * @param node the element to deploy - * @throws Exception - */ - @Override - public void deploy(final Node node) throws Exception - { - Pair> securityMatch = parser.parseSecurityRoles(node); - securityRepository.addMatch(securityMatch.getA(), securityMatch.getB()); - } - - /** - * undeploys an element - * - * @param node the element to undeploy - * @throws Exception - */ - @Override - public void undeploy(final Node node) throws Exception - { - String match = node.getAttributes().getNamedItem(getKeyAttribute()).getNodeValue(); - securityRepository.removeMatch(match); - } - - /** - * The name of the configuration file name to look for for deployment - * - * @return The name of the config file - */ - @Override - public String[] getDefaultConfigFileNames() - { - return new String[]{"activemq-configuration.xml", SecurityDeployer.QUEUES_XML}; - } -} http://git-wip-us.apache.org/repos/asf/activemq-6/blob/4b63891a/activemq-server/src/main/java/org/apache/activemq/core/deployers/impl/XmlDeployer.java ---------------------------------------------------------------------- diff --git a/activemq-server/src/main/java/org/apache/activemq/core/deployers/impl/XmlDeployer.java b/activemq-server/src/main/java/org/apache/activemq/core/deployers/impl/XmlDeployer.java deleted file mode 100644 index 9804563..0000000 --- a/activemq-server/src/main/java/org/apache/activemq/core/deployers/impl/XmlDeployer.java +++ /dev/null @@ -1,334 +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.activemq.core.deployers.impl; - -import java.io.InputStreamReader; -import java.io.Reader; -import java.net.URI; -import java.util.ArrayList; -import java.util.Collection; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Set; - -import org.apache.activemq.api.core.ActiveMQException; -import org.apache.activemq.core.deployers.Deployer; -import org.apache.activemq.core.deployers.DeploymentManager; -import org.apache.activemq.core.server.ActiveMQServerLogger; -import org.apache.activemq.utils.XMLUtil; -import org.w3c.dom.Element; -import org.w3c.dom.Node; -import org.w3c.dom.NodeList; - -/** - * @author Andy Taylor - */ -public abstract class XmlDeployer implements Deployer -{ - protected static final String NAME_ATTR = "name"; - - private final Map> configuration = new HashMap>(); - - private final DeploymentManager deploymentManager; - - private boolean started; - - private String[] configFileNames; - - public XmlDeployer(final DeploymentManager deploymentManager) - { - this.deploymentManager = deploymentManager; - configFileNames = getDefaultConfigFileNames(); - } - - /** - * adds a URL to the already configured set of url's this deployer is handling - * @param url The URL to add - * @param name the name of the element - * @param e . - */ - public synchronized void addToConfiguration(final URI url, final String name, final Node e) - { - Map map = configuration.get(url); - if (map == null) - { - map = new HashMap(); - configuration.put(url, map); - } - map.put(name, e); - } - - /** - * Redeploys a URL if changed - * @param url The resource to redeploy - * @throws Exception - */ - @Override - public synchronized void redeploy(final URI url) throws Exception - { - Element e = getRootElement(url); - - validate(e); - - List added = new ArrayList(); - // pull out the elements that need deploying - String[] elements = getElementTagName(); - for (String element : elements) - { - NodeList children = e.getElementsByTagName(element); - for (int i = 0; i < children.getLength(); i++) - { - Node node = children.item(i); - - String name = getName(node); - - added.add(name); - // if this has never been deployed deploy - Map map = configuration.get(url); - if (map == null || map.get(name) == null) - { - deploy(node); - } - // or if it has changed redeploy - else if (hasNodeChanged(url, node, name)) - { - undeploy(node); - deploy(node); - addToConfiguration(url, name, node); - } - } - } - // now check for anything that has been removed and undeploy - if (configuration.get(url) != null) - { - Set keys = configuration.get(url).keySet(); - List removed = new ArrayList(); - - for (String key : keys) - { - if (!added.contains(key)) - { - undeploy(configuration.get(url).get(key)); - removed.add(key); - } - } - for (String s : removed) - { - configuration.get(url).remove(s); - } - } - } - - /** - * Undeploys a resource that has been removed - * @param uri The Resource that was deleted - * @throws Exception - */ - @Override - public synchronized void undeploy(final URI uri) throws Exception - { - Set keys = configuration.get(uri).keySet(); - for (String key : keys) - { - undeploy(configuration.get(uri).get(key)); - } - configuration.remove(uri); - } - - /** - * Deploy the URL for the first time - * @param url The resource to deploy - * @throws Exception - */ - @Override - public synchronized void deploy(final URI url) throws Exception - { - Element e = getRootElement(url); - - validate(e); - - Map map = configuration.get(url); - if (map == null) - { - map = new HashMap(); - configuration.put(url, map); - } - - // find all thenodes to deploy - String[] elements = getElementTagName(); - for (String element : elements) - { - NodeList children = e.getElementsByTagName(element); - for (int i = 0; i < children.getLength(); i++) - { - Node node = children.item(i); - - String name = getName(node); - - try - { - deploy(node); - } - catch (Exception e1) - { - ActiveMQServerLogger.LOGGER.unableToDeployNode(e1, node); - continue; - } - - addToConfiguration(url, name, node); - } - } - } - - /** - * The key attribute for the element, usually 'name' but can be overridden - * @return the key attribute - */ - public String getKeyAttribute() - { - return XmlDeployer.NAME_ATTR; - } - - // register with the deploymenmt manager - public synchronized void start() throws Exception - { - if (started) - { - return; - } - - deploymentManager.registerDeployer(this); - - started = true; - } - - // undeploy everything - public synchronized void stop() throws Exception - { - if (!started) - { - return; - } - - Collection> urls = configuration.values(); - for (Map hashMap : urls) - { - for (Node node : hashMap.values()) - { - try - { - undeploy(node); - } - catch (Exception e) - { - ActiveMQServerLogger.LOGGER.problemUndeployingNode(e, node); - } - } - } - deploymentManager.unregisterDeployer(this); - - started = false; - } - - public synchronized boolean isStarted() - { - return started; - } - - public String[] getConfigFileNames() - { - return configFileNames; - } - - public void setConfigFileNames(final String[] configFileNames) - { - this.configFileNames = configFileNames; - } - - /** - * the names of the elements to deploy - * @return the names of the elements todeploy - */ - public abstract String[] getElementTagName(); - - public abstract String[] getDefaultConfigFileNames(); - - /** - * deploy an element - * @param node the element to deploy - * @throws Exception - */ - public abstract void deploy(final Node node) throws Exception; - - /** - * Validate the DOM - */ - public abstract void validate(final Node rootNode) throws Exception; - - /** - * undeploys an element - * @param node the element to undeploy - * @throws Exception - */ - public abstract void undeploy(final Node node) throws Exception; - - protected Element getRootElement(final URI url) throws Exception - { - Reader reader = new InputStreamReader(url.toURL().openStream()); - String xml = org.apache.activemq.utils.XMLUtil.readerToString(reader); - xml = org.apache.activemq.utils.XMLUtil.replaceSystemProps(xml); - return org.apache.activemq.utils.XMLUtil.stringToElement(xml); - } - - private boolean hasNodeChanged(final URI url, final Node child, final String name) - { - String newTextContent = child.getTextContent(); - String origTextContent = configuration.get(url).get(name).getTextContent(); - return !newTextContent.equals(origTextContent); - } - - private String getName(Node node) throws ActiveMQException - { - - String name; - - if (node.hasAttributes()) - { - - try - { - Node keyNode = node.getAttributes().getNamedItem( - getKeyAttribute()); - - name = keyNode.getNodeValue(); - } - catch (NullPointerException e) - { - throw new ActiveMQException("Could not find " + getKeyAttribute() + " in " + XMLUtil.elementToString(node)); - } - } - else - { - - name = node.getLocalName(); - } - - return name; - } - -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/activemq-6/blob/4b63891a/activemq-server/src/main/java/org/apache/activemq/core/security/User.java ---------------------------------------------------------------------- diff --git a/activemq-server/src/main/java/org/apache/activemq/core/security/User.java b/activemq-server/src/main/java/org/apache/activemq/core/security/User.java new file mode 100644 index 0000000..528530d --- /dev/null +++ b/activemq-server/src/main/java/org/apache/activemq/core/security/User.java @@ -0,0 +1,80 @@ +/** + * 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.activemq.core.security; + +/** +* @author Andy Taylor +*/ +public class User +{ + final String user; + + final String password; + + public User(final String user, final String password) + { + this.user = user; + this.password = password; + } + + @Override + public boolean equals(final Object o) + { + if (this == o) + { + return true; + } + if (o == null || getClass() != o.getClass()) + { + return false; + } + + User user1 = (User)o; + + if (!user.equals(user1.user)) + { + return false; + } + + return true; + } + + @Override + public int hashCode() + { + return user.hashCode(); + } + + public boolean isValid(final String user, final String password) + { + if (user == null) + { + return false; + } + return this.user.equals(user) && this.password.equals(password); + } + + public String getUser() + { + return user; + } + + public String getPassword() + { + return password; + } +} http://git-wip-us.apache.org/repos/asf/activemq-6/blob/4b63891a/activemq-server/src/main/java/org/apache/activemq/core/server/ActiveMQServers.java ---------------------------------------------------------------------- diff --git a/activemq-server/src/main/java/org/apache/activemq/core/server/ActiveMQServers.java b/activemq-server/src/main/java/org/apache/activemq/core/server/ActiveMQServers.java index 5ab885c..730a2c8 100644 --- a/activemq-server/src/main/java/org/apache/activemq/core/server/ActiveMQServers.java +++ b/activemq-server/src/main/java/org/apache/activemq/core/server/ActiveMQServers.java @@ -97,9 +97,9 @@ public final class ActiveMQServers public static ActiveMQServer newActiveMQServer(Configuration config, String defUser, String defPass) { - ActiveMQSecurityManager securityManager = new ActiveMQSecurityManagerImpl(); + ActiveMQSecurityManagerImpl securityManager = new ActiveMQSecurityManagerImpl(); - securityManager.addUser(defUser, defPass); + securityManager.getConfiguration().addUser(defUser, defPass); ActiveMQServer server = ActiveMQServers.newActiveMQServer(config, ManagementFactory.getPlatformMBeanServer(), @@ -115,9 +115,9 @@ public final class ActiveMQServers String user, String password) { - ActiveMQSecurityManager securityManager = new ActiveMQSecurityManagerImpl(); + ActiveMQSecurityManagerImpl securityManager = new ActiveMQSecurityManagerImpl(); - securityManager.addUser(user, password); + securityManager.getConfiguration().addUser(user, password); ActiveMQServer server = ActiveMQServers.newActiveMQServer(config, mbeanServer, securityManager, enablePersistence); http://git-wip-us.apache.org/repos/asf/activemq-6/blob/4b63891a/activemq-server/src/main/java/org/apache/activemq/core/server/embedded/EmbeddedActiveMQ.java ---------------------------------------------------------------------- diff --git a/activemq-server/src/main/java/org/apache/activemq/core/server/embedded/EmbeddedActiveMQ.java b/activemq-server/src/main/java/org/apache/activemq/core/server/embedded/EmbeddedActiveMQ.java index 139c6ed..45deccc 100644 --- a/activemq-server/src/main/java/org/apache/activemq/core/server/embedded/EmbeddedActiveMQ.java +++ b/activemq-server/src/main/java/org/apache/activemq/core/server/embedded/EmbeddedActiveMQ.java @@ -19,6 +19,7 @@ package org.apache.activemq.core.server.embedded; import javax.management.MBeanServer; import org.apache.activemq.core.config.Configuration; +import org.apache.activemq.core.config.FileDeploymentManager; import org.apache.activemq.core.config.impl.FileConfiguration; import org.apache.activemq.core.server.ActiveMQServer; import org.apache.activemq.core.server.impl.ActiveMQServerImpl; @@ -97,8 +98,10 @@ public class EmbeddedActiveMQ if (configuration == null) { if (configResourcePath == null) configResourcePath = "activemq-configuration.xml"; - FileConfiguration config = new FileConfiguration(configResourcePath); - config.start(); + FileDeploymentManager deploymentManager = new FileDeploymentManager(configResourcePath); + FileConfiguration config = new FileConfiguration(); + deploymentManager.addDeployable(config); + deploymentManager.readConfiguration(); configuration = config; } if (securityManager == null) http://git-wip-us.apache.org/repos/asf/activemq-6/blob/4b63891a/activemq-server/src/main/java/org/apache/activemq/core/server/impl/ActiveMQServerImpl.java ---------------------------------------------------------------------- diff --git a/activemq-server/src/main/java/org/apache/activemq/core/server/impl/ActiveMQServerImpl.java b/activemq-server/src/main/java/org/apache/activemq/core/server/impl/ActiveMQServerImpl.java index fd412d9..b1f237d 100644 --- a/activemq-server/src/main/java/org/apache/activemq/core/server/impl/ActiveMQServerImpl.java +++ b/activemq-server/src/main/java/org/apache/activemq/core/server/impl/ActiveMQServerImpl.java @@ -52,13 +52,6 @@ import org.apache.activemq.core.config.ConfigurationUtils; import org.apache.activemq.core.config.CoreQueueConfiguration; import org.apache.activemq.core.config.DivertConfiguration; import org.apache.activemq.core.config.impl.ConfigurationImpl; -import org.apache.activemq.core.deployers.Deployer; -import org.apache.activemq.core.deployers.DeploymentManager; -import org.apache.activemq.core.deployers.impl.AddressSettingsDeployer; -import org.apache.activemq.core.deployers.impl.BasicUserCredentialsDeployer; -import org.apache.activemq.core.deployers.impl.FileDeploymentManager; -import org.apache.activemq.core.deployers.impl.QueueDeployer; -import org.apache.activemq.core.deployers.impl.SecurityDeployer; import org.apache.activemq.core.filter.Filter; import org.apache.activemq.core.filter.impl.FilterImpl; import org.apache.activemq.core.journal.IOCriticalErrorListener; @@ -233,13 +226,6 @@ public class ActiveMQServerImpl implements ActiveMQServer private MemoryManager memoryManager; - private volatile DeploymentManager deploymentManager; - - private Deployer basicUserCredentialsDeployer; - private Deployer addressSettingsDeployer; - private Deployer queueDeployer; - private Deployer securityDeployer; - private final Map sessions = new ConcurrentHashMap(); /** @@ -661,16 +647,6 @@ public class ActiveMQServerImpl implements ActiveMQServer //before we stop any components deactivate any callbacks callDeActiveCallbacks(); - // Stop the deployers - if (configuration.isFileDeploymentEnabled()) - { - stopComponent(basicUserCredentialsDeployer); - stopComponent(addressSettingsDeployer); - stopComponent(queueDeployer); - stopComponent(securityDeployer); - stopComponent(deploymentManager); - } - stopComponent(backupManager); activation.preStorageClose(); stopComponent(pagingManager); @@ -688,7 +664,6 @@ public class ActiveMQServerImpl implements ActiveMQServer managementService.unregisterServer(); stopComponent(managementService); - stopComponent(securityManager); stopComponent(resourceManager); stopComponent(postOffice); @@ -993,11 +968,6 @@ public class ActiveMQServerImpl implements ActiveMQServer return addressSettingsRepository; } - public DeploymentManager getDeploymentManager() - { - return deploymentManager; - } - public ResourceManager getResourceManager() { return resourceManager; @@ -1633,11 +1603,6 @@ public class ActiveMQServerImpl implements ActiveMQServer // Create the hard-wired components - if (configuration.isFileDeploymentEnabled()) - { - deploymentManager = new FileDeploymentManager(configuration.getFileDeployerScanPeriod()); - } - callPreActiveCallbacks(); // startReplication(); @@ -1711,24 +1676,11 @@ public class ActiveMQServerImpl implements ActiveMQServer if (!scalingDown) { - if (configuration.isFileDeploymentEnabled()) - { - addressSettingsDeployer = new AddressSettingsDeployer(deploymentManager, addressSettingsRepository); - - addressSettingsDeployer.start(); - } - deployAddressSettingsFromConfiguration(); } storageManager.start(); - - if (securityManager != null) - { - securityManager.start(); - } - postOffice.start(); pagingManager.start(); @@ -1737,21 +1689,6 @@ public class ActiveMQServerImpl implements ActiveMQServer resourceManager.start(); - // Deploy all security related config - if (configuration.isFileDeploymentEnabled()) - { - basicUserCredentialsDeployer = new BasicUserCredentialsDeployer(deploymentManager, securityManager); - - basicUserCredentialsDeployer.start(); - - if (securityManager != null) - { - securityDeployer = new SecurityDeployer(deploymentManager, securityRepository); - - securityDeployer.start(); - } - } - deploySecurityFromConfiguration(); deployGroupingHandlerConfiguration(configuration.getGroupingHandlerConfiguration()); @@ -1794,16 +1731,7 @@ public class ActiveMQServerImpl implements ActiveMQServer // Deploy the rest of the stuff // Deploy any predefined queues - if (configuration.isFileDeploymentEnabled()) - { - queueDeployer = new QueueDeployer(deploymentManager, this); - - queueDeployer.start(); - } - else - { - deployQueuesFromConfiguration(); - } + deployQueuesFromConfiguration(); // We need to call this here, this gives any dependent server a chance to deploy its own addresses http://git-wip-us.apache.org/repos/asf/activemq-6/blob/4b63891a/activemq-server/src/main/java/org/apache/activemq/spi/core/security/ActiveMQSecurityManager.java ---------------------------------------------------------------------- diff --git a/activemq-server/src/main/java/org/apache/activemq/spi/core/security/ActiveMQSecurityManager.java b/activemq-server/src/main/java/org/apache/activemq/spi/core/security/ActiveMQSecurityManager.java index ab8853f..e1b2b1a 100644 --- a/activemq-server/src/main/java/org/apache/activemq/spi/core/security/ActiveMQSecurityManager.java +++ b/activemq-server/src/main/java/org/apache/activemq/spi/core/security/ActiveMQSecurityManager.java @@ -20,14 +20,13 @@ import java.util.Set; import org.apache.activemq.core.security.CheckType; import org.apache.activemq.core.security.Role; -import org.apache.activemq.core.server.ActiveMQComponent; /** * Use to validate whether a user has is valid to connect to the server and perform certain * functions * @author Andy Taylor */ -public interface ActiveMQSecurityManager extends ActiveMQComponent +public interface ActiveMQSecurityManager { /** * is this a valid user. @@ -47,36 +46,4 @@ public interface ActiveMQSecurityManager extends ActiveMQComponent * @return true if the user is valid and they have the correct roles */ boolean validateUserAndRole(String user, String password, Set roles, CheckType checkType); - - /** - * adds a new user - * @param user the user to add - * @param password theusers password - */ - void addUser(String user, String password); - - /** - * removes a user and any roles they may have. - * @param user the user to remove - */ - void removeUser(String user); - - /** - * adds a new role for a user. - * @param user the user - * @param role the role to add - */ - void addRole(String user, String role); - - /** - * removes a role from a user - * @param user the user - * @param role the role to remove - */ - void removeRole(String user, String role); - - /* - * set the default user for null users - */ - void setDefaultUser(String username); } http://git-wip-us.apache.org/repos/asf/activemq-6/blob/4b63891a/activemq-server/src/main/java/org/apache/activemq/spi/core/security/ActiveMQSecurityManagerImpl.java ---------------------------------------------------------------------- diff --git a/activemq-server/src/main/java/org/apache/activemq/spi/core/security/ActiveMQSecurityManagerImpl.java b/activemq-server/src/main/java/org/apache/activemq/spi/core/security/ActiveMQSecurityManagerImpl.java index e5dc4b4..b63e775 100644 --- a/activemq-server/src/main/java/org/apache/activemq/spi/core/security/ActiveMQSecurityManagerImpl.java +++ b/activemq-server/src/main/java/org/apache/activemq/spi/core/security/ActiveMQSecurityManagerImpl.java @@ -16,15 +16,13 @@ */ package org.apache.activemq.spi.core.security; -import java.util.ArrayList; -import java.util.HashMap; import java.util.List; -import java.util.Map; import java.util.Set; +import org.apache.activemq.core.config.impl.SecurityConfiguration; import org.apache.activemq.core.security.CheckType; import org.apache.activemq.core.security.Role; -import org.apache.activemq.core.server.ActiveMQMessageBundle; +import org.apache.activemq.core.security.User; /** * A basic implementation of the ActiveMQSecurityManager. This can be used within an appserver and be deployed by @@ -34,53 +32,29 @@ import org.apache.activemq.core.server.ActiveMQMessageBundle; */ public class ActiveMQSecurityManagerImpl implements ActiveMQSecurityManager { + private final SecurityConfiguration configuration; - // Static -------------------------------------------------------- - - // Attributes ---------------------------------------------------- - - /** - * the current valid users - */ - private final Map users = new HashMap(); - - private String defaultUser = null; - - /** - * the roles for the users - */ - private final Map> roles = new HashMap>(); - - // ActiveMQComponent implementation ------------------------------------------ - - public void start() - { - } - - public void stop() + public ActiveMQSecurityManagerImpl() { - users.clear(); - - roles.clear(); - - defaultUser = null; + configuration = new SecurityConfiguration(); } - public boolean isStarted() + public ActiveMQSecurityManagerImpl(SecurityConfiguration configuration) { - return true; + this.configuration = configuration; } // Public --------------------------------------------------------------------- public boolean validateUser(final String user, final String password) { - if (user == null && defaultUser == null) + if (user == null && configuration.getDefaultUser() == null) { return false; } - User theUser = users.get(user == null ? defaultUser : user); + String defaultUser = configuration.getDefaultUser(); + User theUser = configuration.getUser(user == null ? defaultUser : user); boolean ok = theUser != null && theUser.isValid(user == null ? defaultUser : user, password == null ? defaultUser : password); @@ -94,7 +68,8 @@ public class ActiveMQSecurityManagerImpl implements ActiveMQSecurityManager { if (validateUser(user, password)) { - List availableRoles = this.roles.get(user == null ? defaultUser : user); + String defaultUser = configuration.getDefaultUser(); + List availableRoles = configuration.getRole(user == null ? defaultUser : user); if (availableRoles == null) { @@ -119,98 +94,8 @@ public class ActiveMQSecurityManagerImpl implements ActiveMQSecurityManager return false; } - public void addUser(final String user, final String password) - { - if (user == null) - { - throw ActiveMQMessageBundle.BUNDLE.nullUser(); - } - if (password == null) - { - throw ActiveMQMessageBundle.BUNDLE.nullPassword(); - } - users.put(user, new User(user, password)); - } - - public void removeUser(final String user) - { - users.remove(user); - roles.remove(user); - } - - public void addRole(final String user, final String role) - { - if (roles.get(user) == null) - { - roles.put(user, new ArrayList()); - } - roles.get(user).add(role); - } - - public void removeRole(final String user, final String role) - { - if (roles.get(user) == null) - { - return; - } - roles.get(user).remove(role); - } - - /* - * set the default user for null users - */ - public void setDefaultUser(final String username) + public SecurityConfiguration getConfiguration() { - defaultUser = username; - } - - static class User - { - final String user; - - final String password; - - User(final String user, final String password) - { - this.user = user; - this.password = password; - } - - @Override - public boolean equals(final Object o) - { - if (this == o) - { - return true; - } - if (o == null || getClass() != o.getClass()) - { - return false; - } - - User user1 = (User)o; - - if (!user.equals(user1.user)) - { - return false; - } - - return true; - } - - @Override - public int hashCode() - { - return user.hashCode(); - } - - public boolean isValid(final String user, final String password) - { - if (user == null) - { - return false; - } - return this.user.equals(user) && this.password.equals(password); - } + return configuration; } } http://git-wip-us.apache.org/repos/asf/activemq-6/blob/4b63891a/activemq-server/src/main/java/org/apache/activemq/spi/core/security/JAASSecurityManager.java ---------------------------------------------------------------------- diff --git a/activemq-server/src/main/java/org/apache/activemq/spi/core/security/JAASSecurityManager.java b/activemq-server/src/main/java/org/apache/activemq/spi/core/security/JAASSecurityManager.java index 74f6925..81d73df 100644 --- a/activemq-server/src/main/java/org/apache/activemq/spi/core/security/JAASSecurityManager.java +++ b/activemq-server/src/main/java/org/apache/activemq/spi/core/security/JAASSecurityManager.java @@ -30,7 +30,6 @@ import javax.security.auth.login.LoginException; import org.apache.activemq.core.security.CheckType; import org.apache.activemq.core.security.Role; -import org.apache.activemq.core.server.ActiveMQComponent; import org.apache.activemq.core.server.ActiveMQServerLogger; /** @@ -43,7 +42,7 @@ import org.apache.activemq.core.server.ActiveMQServerLogger; * @author Tim Fox * @author Jeff Mesnil */ -public class JAASSecurityManager implements ActiveMQSecurityManager, ActiveMQComponent +public class JAASSecurityManager implements ActiveMQSecurityManager { // Static -------------------------------------------------------- @@ -53,8 +52,6 @@ public class JAASSecurityManager implements ActiveMQSecurityManager, ActiveMQCom private String configurationName; - private boolean started; - private CallbackHandler callbackHandler; private Configuration config; @@ -122,62 +119,6 @@ public class JAASSecurityManager implements ActiveMQSecurityManager, ActiveMQCom return authenticated; } - public void addRole(final String user, final String role) - { - // NO-OP - } - - public void addUser(final String user, final String password) - { - // NO-OP - } - - public void removeRole(final String user, final String role) - { - // NO-OP - } - - public void removeUser(final String user) - { - // NO-OP - } - - public void setDefaultUser(final String username) - { - // NO-OP - } - - // ActiveMQComponent implementation ----------------------------- - - /** - * lifecycle method, needs to be called - * - * @throws Exception - */ - public synchronized void start() throws Exception - { - if (started) - { - return; - } - - started = true; - } - - public synchronized void stop() - { - if (!started) - { - return; - } - started = false; - } - - public synchronized boolean isStarted() - { - return started; - } - private Subject getAuthenticatedSubject(final String user, final String password) throws LoginException { SimplePrincipal principal = user == null ? null : new SimplePrincipal(user); http://git-wip-us.apache.org/repos/asf/activemq-6/blob/4b63891a/activemq-server/src/main/resources/META-INF/services/org/apache/activemq/security/basic-security ---------------------------------------------------------------------- diff --git a/activemq-server/src/main/resources/META-INF/services/org/apache/activemq/security/basic-security b/activemq-server/src/main/resources/META-INF/services/org/apache/activemq/security/basic-security deleted file mode 100644 index b5b8419..0000000 --- a/activemq-server/src/main/resources/META-INF/services/org/apache/activemq/security/basic-security +++ /dev/null @@ -1,17 +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. -## --------------------------------------------------------------------------- -class=org.apache.activemq.spi.core.security.ActiveMQSecurityManagerImpl