2 * Copyright 2005 the original author or authors.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 package org.wamblee.usermgt;
20 import java.util.TreeSet;
22 import org.wamblee.security.encryption.MessageDigester;
27 public class InMemoryUserSet extends AbstractUserSet {
30 * Users. All users in this set have their password validator and encoder set.
32 private Set<User> _users;
35 * Constructs an empty user set.
37 public InMemoryUserSet(NameValidator aPasswordValidator, MessageDigester aPasswordEncoder) {
38 super(aPasswordValidator, aPasswordEncoder);
39 _users = new TreeSet<User>();
45 * @see org.wamblee.usermgt.UserSet#userModified(org.wamblee.usermgt.User)
47 public void userModified(User aUser) {
49 setPasswordInfo(aUser);
56 * @see org.wamblee.usermgt.UserSet#find(java.lang.String)
58 public User find(String aName) {
59 for (User user : _users) {
60 if (user.getName().equals(aName)) {
61 return new User(user);
70 * @see org.wamblee.usermgt.UserSet#add(org.wamblee.usermgt.User)
72 public boolean add(User aUser) {
73 setPasswordInfo(aUser);
74 return _users.add(aUser);
80 * @see org.wamblee.usermgt.UserSet#contains(org.wamblee.usermgt.User)
82 public boolean contains(User aUser) {
83 return _users.contains(aUser);
89 * @see org.wamblee.usermgt.UserSet#remove(org.wamblee.usermgt.User)
91 public boolean remove(User aUser) {
92 return _users.remove(aUser);
98 * @see org.wamblee.usermgt.UserSet#list()
100 public Set<User> list() {
101 Set<User> list = new TreeSet<User>();
102 for (User user : _users) {
103 list.add(new User(user));
111 * @see org.wamblee.usermgt.UserSet#list(org.wamblee.usermgt.Group)
113 public Set<User> list(Group aGroup) {
114 Set<User> result = new TreeSet<User>();
115 for (User user : _users) {
116 if (user.getGroups().contains(aGroup)) {
117 result.add(new User(user));
124 * @see org.wamblee.usermgt.UserSet#size()
127 return _users.size();