2 * Copyright 2005-2010 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.
16 package org.wamblee.usermgt;
18 import org.wamblee.security.encryption.MessageDigester;
21 import java.util.TreeSet;
26 * @author Erik Brakkee
28 public class InMemoryUserSet extends AbstractUserSet {
30 * Users. All users in this set have their password validator and encoder
33 private Set<User> users;
36 * Constructs an empty user set.
38 public InMemoryUserSet(NameValidator aPasswordValidator,
39 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);
73 * @see org.wamblee.usermgt.UserSet#add(org.wamblee.usermgt.User)
75 public boolean add(User aUser) {
76 setPasswordInfo(aUser);
78 return users.add(aUser);
84 * @see org.wamblee.usermgt.UserSet#contains(org.wamblee.usermgt.User)
86 public boolean contains(User aUser) {
87 return users.contains(aUser);
93 * @see org.wamblee.usermgt.UserSet#remove(org.wamblee.usermgt.User)
95 public boolean remove(User aUser) {
96 return users.remove(aUser);
102 * @see org.wamblee.usermgt.UserSet#list()
104 public Set<User> list() {
105 Set<User> list = new TreeSet<User>();
107 for (User user : users) {
108 list.add(new User(user));
117 * @see org.wamblee.usermgt.UserSet#list(org.wamblee.usermgt.Group)
119 public Set<User> list(Group aGroup) {
120 Set<User> result = new TreeSet<User>();
122 for (User user : users) {
123 if (user.getGroups().contains(aGroup)) {
124 result.add(new User(user));
134 * @see org.wamblee.usermgt.UserSet#size()