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 * @author Erik Brakkee
29 public class InMemoryUserSet extends AbstractUserSet {
32 * Users. All users in this set have their password validator and encoder set.
34 private Set<User> _users;
37 * Constructs an empty user set.
39 public InMemoryUserSet(NameValidator aPasswordValidator, MessageDigester aPasswordEncoder) {
40 super(aPasswordValidator, aPasswordEncoder);
41 _users = new TreeSet<User>();
47 * @see org.wamblee.usermgt.UserSet#userModified(org.wamblee.usermgt.User)
49 public void userModified(User aUser) {
51 setPasswordInfo(aUser);
58 * @see org.wamblee.usermgt.UserSet#find(java.lang.String)
60 public User find(String aName) {
61 for (User user : _users) {
62 if (user.getName().equals(aName)) {
63 return new User(user);
72 * @see org.wamblee.usermgt.UserSet#add(org.wamblee.usermgt.User)
74 public boolean add(User aUser) {
75 setPasswordInfo(aUser);
76 return _users.add(aUser);
82 * @see org.wamblee.usermgt.UserSet#contains(org.wamblee.usermgt.User)
84 public boolean contains(User aUser) {
85 return _users.contains(aUser);
91 * @see org.wamblee.usermgt.UserSet#remove(org.wamblee.usermgt.User)
93 public boolean remove(User aUser) {
94 return _users.remove(aUser);
100 * @see org.wamblee.usermgt.UserSet#list()
102 public Set<User> list() {
103 Set<User> list = new TreeSet<User>();
104 for (User user : _users) {
105 list.add(new User(user));
113 * @see org.wamblee.usermgt.UserSet#list(org.wamblee.usermgt.Group)
115 public Set<User> list(Group aGroup) {
116 Set<User> result = new TreeSet<User>();
117 for (User user : _users) {
118 if (user.getGroups().contains(aGroup)) {
119 result.add(new User(user));
126 * @see org.wamblee.usermgt.UserSet#size()
129 return _users.size();