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.Group; 26 import org.apache.catalina.Role; 27 import org.apache.catalina.UserDatabase; 28 import org.apache.catalina.util.RequestUtil; 29 30 38 39 public class MemoryUser extends AbstractUser { 40 41 42 44 45 54 MemoryUser(MemoryUserDatabase database, String username, 55 String password, String fullName) { 56 57 super(); 58 this.database = database; 59 setUsername(username); 60 setPassword(password); 61 setFullName(fullName); 62 63 } 64 65 66 68 69 72 protected MemoryUserDatabase database = null; 73 74 75 78 protected ArrayList groups = new ArrayList (); 79 80 81 84 protected ArrayList roles = new ArrayList (); 85 86 87 89 90 93 public Iterator getGroups() { 94 95 synchronized (groups) { 96 return (groups.iterator()); 97 } 98 99 } 100 101 102 105 public Iterator getRoles() { 106 107 synchronized (roles) { 108 return (roles.iterator()); 109 } 110 111 } 112 113 114 117 public UserDatabase getUserDatabase() { 118 119 return (this.database); 120 121 } 122 123 124 126 127 132 public void addGroup(Group group) { 133 134 synchronized (groups) { 135 if (!groups.contains(group)) { 136 groups.add(group); 137 } 138 } 139 140 } 141 142 143 148 public void addRole(Role role) { 149 150 synchronized (roles) { 151 if (!roles.contains(role)) { 152 roles.add(role); 153 } 154 } 155 156 } 157 158 159 164 public boolean isInGroup(Group group) { 165 166 synchronized (groups) { 167 return (groups.contains(group)); 168 } 169 170 } 171 172 173 180 public boolean isInRole(Role role) { 181 182 synchronized (roles) { 183 return (roles.contains(role)); 184 } 185 186 } 187 188 189 194 public void removeGroup(Group group) { 195 196 synchronized (groups) { 197 groups.remove(group); 198 } 199 200 } 201 202 203 206 public void removeGroups() { 207 208 synchronized (groups) { 209 groups.clear(); 210 } 211 212 } 213 214 215 220 public void removeRole(Role role) { 221 222 synchronized (roles) { 223 roles.remove(role); 224 } 225 226 } 227 228 229 232 public void removeRoles() { 233 234 synchronized (roles) { 235 roles.clear(); 236 } 237 238 } 239 240 241 249 public String toString() { 250 251 StringBuffer sb = new StringBuffer ("<user username=\""); 252 sb.append(RequestUtil.filter(username)); 253 sb.append("\" password=\""); 254 sb.append(RequestUtil.filter(password)); 255 sb.append("\""); 256 if (fullName != null) { 257 sb.append(" fullName=\""); 258 sb.append(RequestUtil.filter(fullName)); 259 sb.append("\""); 260 } 261 synchronized (groups) { 262 if (groups.size() > 0) { 263 sb.append(" groups=\""); 264 int n = 0; 265 Iterator values = groups.iterator(); 266 while (values.hasNext()) { 267 if (n > 0) { 268 sb.append(','); 269 } 270 n++; 271 sb.append(RequestUtil.filter(((Group) values.next()).getGroupname())); 272 } 273 sb.append("\""); 274 } 275 } 276 synchronized (roles) { 277 if (roles.size() > 0) { 278 sb.append(" roles=\""); 279 int n = 0; 280 Iterator values = roles.iterator(); 281 while (values.hasNext()) { 282 if (n > 0) { 283 sb.append(','); 284 } 285 n++; 286 sb.append(RequestUtil.filter(((Role) values.next()).getRolename())); 287 } 288 sb.append("\""); 289 } 290 } 291 sb.append("/>"); 292 return (sb.toString()); 293 294 } 295 296 297 } 298 | Popular Tags |