1 17 18 19 package org.apache.catalina.users; 20 21 22 import java.util.ArrayList ; 23 import java.util.Iterator ; 24 25 import org.apache.catalina.Role; 26 import org.apache.catalina.UserDatabase; 27 28 29 37 38 public class MemoryGroup extends AbstractGroup { 39 40 41 43 44 52 MemoryGroup(MemoryUserDatabase database, 53 String groupname, String description) { 54 55 super(); 56 this.database = database; 57 setGroupname(groupname); 58 setDescription(description); 59 60 } 61 62 63 65 66 69 protected MemoryUserDatabase database = null; 70 71 72 75 protected ArrayList roles = new ArrayList (); 76 77 78 80 81 84 public Iterator getRoles() { 85 86 synchronized (roles) { 87 return (roles.iterator()); 88 } 89 90 } 91 92 93 96 public UserDatabase getUserDatabase() { 97 98 return (this.database); 99 100 } 101 102 103 106 public Iterator getUsers() { 107 108 ArrayList results = new ArrayList (); 109 Iterator users = database.getUsers(); 110 while (users.hasNext()) { 111 MemoryUser user = (MemoryUser) users.next(); 112 if (user.isInGroup(this)) { 113 results.add(user); 114 } 115 } 116 return (results.iterator()); 117 118 } 119 120 121 123 124 129 public void addRole(Role role) { 130 131 synchronized (roles) { 132 if (!roles.contains(role)) { 133 roles.add(role); 134 } 135 } 136 137 } 138 139 140 145 public boolean isInRole(Role role) { 146 147 synchronized (roles) { 148 return (roles.contains(role)); 149 } 150 151 } 152 153 154 159 public void removeRole(Role role) { 160 161 synchronized (roles) { 162 roles.remove(role); 163 } 164 165 } 166 167 168 171 public void removeRoles() { 172 173 synchronized (roles) { 174 roles.clear(); 175 } 176 177 } 178 179 180 183 public String toString() { 184 185 StringBuffer sb = new StringBuffer ("<group groupname=\""); 186 sb.append(groupname); 187 sb.append("\""); 188 if (description != null) { 189 sb.append(" description=\""); 190 sb.append(description); 191 sb.append("\""); 192 } 193 synchronized (roles) { 194 if (roles.size() > 0) { 195 sb.append(" roles=\""); 196 int n = 0; 197 Iterator values = roles.iterator(); 198 while (values.hasNext()) { 199 if (n > 0) { 200 sb.append(','); 201 } 202 n++; 203 sb.append((String ) ((Role) values.next()).getRolename()); 204 } 205 sb.append("\""); 206 } 207 } 208 sb.append("/>"); 209 return (sb.toString()); 210 211 } 212 213 214 } 215 | Popular Tags |