Return-Path: Delivered-To: apmail-geronimo-activemq-commits-archive@www.apache.org Received: (qmail 62429 invoked from network); 17 Nov 2006 10:24:38 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 17 Nov 2006 10:24:38 -0000 Received: (qmail 28907 invoked by uid 500); 17 Nov 2006 10:24:48 -0000 Delivered-To: apmail-geronimo-activemq-commits-archive@geronimo.apache.org Received: (qmail 28861 invoked by uid 500); 17 Nov 2006 10:24:48 -0000 Mailing-List: contact activemq-commits-help@geronimo.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: activemq-dev@geronimo.apache.org Delivered-To: mailing list activemq-commits@geronimo.apache.org Received: (qmail 28852 invoked by uid 99); 17 Nov 2006 10:24:48 -0000 Received: from herse.apache.org (HELO herse.apache.org) (140.211.11.133) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 17 Nov 2006 02:24:48 -0800 X-ASF-Spam-Status: No, hits=-8.6 required=10.0 tests=ALL_TRUSTED,INFO_TLD,NO_REAL_NAME X-Spam-Check-By: apache.org Received: from [140.211.11.3] (HELO eris.apache.org) (140.211.11.3) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 17 Nov 2006 02:24:37 -0800 Received: by eris.apache.org (Postfix, from userid 65534) id 894891A9846; Fri, 17 Nov 2006 02:24:05 -0800 (PST) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r476099 - in /incubator/activemq/trunk/activemq-core/src: main/java/org/apache/activemq/security/ test/java/org/apache/activemq/security/ test/resources/org/apache/activemq/security/ Date: Fri, 17 Nov 2006 10:24:05 -0000 To: activemq-commits@geronimo.apache.org From: jlim@apache.org X-Mailer: svnmailer-1.1.0 Message-Id: <20061117102405.894891A9846@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: jlim Date: Fri Nov 17 02:24:04 2006 New Revision: 476099 URL: http://svn.apache.org/viewvc?view=rev&rev=476099 Log: applied patch for http://issues.apache.org/activemq/browse/AMQ-1010 Added: incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/security/AuthenticationUser.java incubator/activemq/trunk/activemq-core/src/test/java/org/apache/activemq/security/SimpleAuthenticationPluginTest.java incubator/activemq/trunk/activemq-core/src/test/resources/org/apache/activemq/security/simple-auth-broker.xml Modified: incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/security/SimpleAuthenticationPlugin.java Added: incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/security/AuthenticationUser.java URL: http://svn.apache.org/viewvc/incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/security/AuthenticationUser.java?view=auto&rev=476099 ============================================================================== --- incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/security/AuthenticationUser.java (added) +++ incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/security/AuthenticationUser.java Fri Nov 17 02:24:04 2006 @@ -0,0 +1,64 @@ +/** + * + * 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.security; + + +/** + * A helper object used to configure simple authentiaction plugin + * + * @org.apache.xbean.XBean + * + * @version $Revision + */ +public class AuthenticationUser { + + String username; + String password; + String group; + + + + public AuthenticationUser(String username, String password, String group) { + this.username = username; + this.password = password; + this.group = group; + } + + + public String getGroup() { + return group; + } + public void setGroup(String group) { + this.group = group; + } + public String getPassword() { + return password; + } + public void setPassword(String password) { + this.password = password; + } + public String getUsername() { + return username; + } + public void setUsername(String username) { + this.username = username; + } + + + +} Modified: incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/security/SimpleAuthenticationPlugin.java URL: http://svn.apache.org/viewvc/incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/security/SimpleAuthenticationPlugin.java?view=diff&rev=476099&r1=476098&r2=476099 ============================================================================== --- incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/security/SimpleAuthenticationPlugin.java (original) +++ incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/security/SimpleAuthenticationPlugin.java Fri Nov 17 02:24:04 2006 @@ -17,6 +17,16 @@ */ package org.apache.activemq.security; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.StringTokenizer; + +import org.apache.activemq.jaas.GroupPrincipal; + import org.apache.activemq.broker.Broker; import org.apache.activemq.broker.BrokerPlugin; @@ -26,7 +36,7 @@ * A simple authentication plugin * * @org.apache.xbean.XBean element="simpleAuthenticationPlugin" description="Provides a simple authentication - * plugin configured with a map of user-passwords and a map of user-groups" + * plugin configured with a map of user-passwords and a map of user-groups or a list of authentication users" * * @version $Revision$ */ @@ -34,6 +44,12 @@ private Map userPasswords; private Map userGroups; + public SimpleAuthenticationPlugin() {} + + public SimpleAuthenticationPlugin(List users) { + setUsers(users); + } + public Broker installPlugin(Broker broker) { return new SimpleAuthenticationBroker(broker, userPasswords, userGroups); } @@ -41,6 +57,27 @@ public Map getUserGroups() { return userGroups; } + + /** + * Sets individual users for authentication + * + * @org.apache.xbean.ElementType class="org.apache.activemq.security.AuthenticationUser" + */ + public void setUsers(List users) { + userPasswords = new HashMap(); + userGroups = new HashMap(); + for (Iterator it = users.iterator(); it.hasNext();) { + AuthenticationUser user = (AuthenticationUser)it.next(); + userPasswords.put(user.getUsername(), user.getPassword()); + Set groups = new HashSet(); + StringTokenizer iter = new StringTokenizer(user.getGroup(), ","); + while (iter.hasMoreTokens()) { + String name = iter.nextToken().trim(); + groups.add(new GroupPrincipal(name)); + } + userGroups.put(user.getUsername(), groups); + } + } /** * Sets the groups a user is in. The key is the user name and the value is a Set of groups Added: incubator/activemq/trunk/activemq-core/src/test/java/org/apache/activemq/security/SimpleAuthenticationPluginTest.java URL: http://svn.apache.org/viewvc/incubator/activemq/trunk/activemq-core/src/test/java/org/apache/activemq/security/SimpleAuthenticationPluginTest.java?view=auto&rev=476099 ============================================================================== --- incubator/activemq/trunk/activemq-core/src/test/java/org/apache/activemq/security/SimpleAuthenticationPluginTest.java (added) +++ incubator/activemq/trunk/activemq-core/src/test/java/org/apache/activemq/security/SimpleAuthenticationPluginTest.java Fri Nov 17 02:24:04 2006 @@ -0,0 +1,52 @@ +/** + * + * 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.security; + +import java.net.URI; + +import junit.framework.Test; + +import org.apache.activemq.broker.BrokerFactory; +import org.apache.activemq.broker.BrokerService; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +public class SimpleAuthenticationPluginTest extends SecurityTestSupport { + + private static final Log log = LogFactory.getLog(XBeanSecurityTest.class); + + public static Test suite() { + return suite(XBeanSecurityTest.class); + } + + public static void main(String[] args) { + junit.textui.TestRunner.run(suite()); + } + + + protected BrokerService createBroker() throws Exception { + return createBroker("org/apache/activemq/security/simple-auth-broker.xml"); + } + + protected BrokerService createBroker(String uri) throws Exception { + log.info("Loading broker configuration from the classpath with URI: " + uri); + return BrokerFactory.createBroker(new URI("xbean:" + uri)); + } + + +} \ No newline at end of file Added: incubator/activemq/trunk/activemq-core/src/test/resources/org/apache/activemq/security/simple-auth-broker.xml URL: http://svn.apache.org/viewvc/incubator/activemq/trunk/activemq-core/src/test/resources/org/apache/activemq/security/simple-auth-broker.xml?view=auto&rev=476099 ============================================================================== --- incubator/activemq/trunk/activemq-core/src/test/resources/org/apache/activemq/security/simple-auth-broker.xml (added) +++ incubator/activemq/trunk/activemq-core/src/test/resources/org/apache/activemq/security/simple-auth-broker.xml Fri Nov 17 02:24:04 2006 @@ -0,0 +1,59 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file