1 7 8 package org.jboss.security; 9 10 import java.security.Principal ; 11 import java.security.acl.Group ; 12 import java.util.Collection ; 13 import java.util.Collections ; 14 import java.util.Enumeration ; 15 import java.util.Iterator ; 16 import java.util.HashMap ; 17 18 25 public class SimpleGroup extends SimplePrincipal implements Group 26 { 27 private HashMap members; 28 29 public SimpleGroup(String groupName) 30 { 31 super(groupName); 32 members = new HashMap (3); 33 } 34 35 40 public boolean addMember(Principal user) 41 { 42 boolean isMember = members.containsKey(user); 43 if( isMember == false ) 44 members.put(user, user); 45 return isMember == false; 46 } 47 58 public boolean isMember(Principal member) 59 { 60 boolean isMember = members.containsKey(member); 62 if( isMember == false ) 63 { isMember = (member instanceof org.jboss.security.AnybodyPrincipal); 65 if( isMember == false ) 66 { 67 if( member instanceof org.jboss.security.NobodyPrincipal ) 68 return false; 69 } 70 } 71 if( isMember == false ) 72 { Collection values = members.values(); 74 Iterator iter = values.iterator(); 75 while( isMember == false && iter.hasNext() ) 76 { 77 Object next = iter.next(); 78 if( next instanceof Group ) 79 { 80 Group group = (Group ) next; 81 isMember = group.isMember(member); 82 } 83 } 84 } 85 return isMember; 86 } 87 88 93 public Enumeration members() 94 { 95 return Collections.enumeration(members.values()); 96 } 97 98 103 public boolean removeMember(Principal user) 104 { 105 Object prev = members.remove(user); 106 return prev != null; 107 } 108 109 public String toString() 110 { 111 StringBuffer tmp = new StringBuffer (getName()); 112 tmp.append("(members:"); 113 Iterator iter = members.keySet().iterator(); 114 while( iter.hasNext() ) 115 { 116 tmp.append(iter.next()); 117 tmp.append(','); 118 } 119 tmp.setCharAt(tmp.length()-1, ')'); 120 return tmp.toString(); 121 } 122 } 123 | Popular Tags |