1 18 package org.apache.activemq.security; 19 20 import java.util.HashMap ; 21 import java.util.HashSet ; 22 import java.util.Iterator ; 23 import java.util.List ; 24 import java.util.Map ; 25 import java.util.Set ; 26 import java.util.StringTokenizer ; 27 28 import org.apache.activemq.jaas.GroupPrincipal; 29 30 import org.apache.activemq.broker.Broker; 31 import org.apache.activemq.broker.BrokerPlugin; 32 33 import java.util.Map ; 34 35 43 public class SimpleAuthenticationPlugin implements BrokerPlugin { 44 private Map userPasswords; 45 private Map userGroups; 46 47 public SimpleAuthenticationPlugin() {} 48 49 public SimpleAuthenticationPlugin(List users) { 50 setUsers(users); 51 } 52 53 public Broker installPlugin(Broker broker) { 54 return new SimpleAuthenticationBroker(broker, userPasswords, userGroups); 55 } 56 57 public Map getUserGroups() { 58 return userGroups; 59 } 60 61 66 public void setUsers(List users) { 67 userPasswords = new HashMap (); 68 userGroups = new HashMap (); 69 for (Iterator it = users.iterator(); it.hasNext();) { 70 AuthenticationUser user = (AuthenticationUser)it.next(); 71 userPasswords.put(user.getUsername(), user.getPassword()); 72 Set groups = new HashSet (); 73 StringTokenizer iter = new StringTokenizer (user.getGroups(), ","); 74 while (iter.hasMoreTokens()) { 75 String name = iter.nextToken().trim(); 76 groups.add(new GroupPrincipal(name)); 77 } 78 userGroups.put(user.getUsername(), groups); 79 } 80 } 81 82 85 public void setUserGroups(Map userGroups) { 86 this.userGroups = userGroups; 87 } 88 89 public Map getUserPasswords() { 90 return userPasswords; 91 } 92 93 96 public void setUserPasswords(Map userPasswords) { 97 this.userPasswords = userPasswords; 98 } 99 100 } 101 | Popular Tags |