ac3f5a70b388024a82a05328fda9dd61a6f6187e
[utils] / security / src / main / java / org / wamblee / usermgt / UserSet.java
1 /*
2  * Copyright 2005 the original author or authors.
3  * 
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
7  * 
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  * 
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.
15  */ 
16
17 package org.wamblee.usermgt;
18
19 import java.util.Set;
20
21 /**
22  * Represents a set of users.
23  * Typical implementations would be an implementation based on a static configuration file or 
24  * an implementation backed by a database.  
25  *
26  * @author Erik Brakkee
27  */
28 public interface UserSet {
29     
30     /**
31      * Creates a user. 
32      * @param aUsername User name. 
33      * @param aPassword Password. 
34      * @param aGroup Group.
35      * @return New user.  
36      * @throws UserMgtException In case the user cannot be created. 
37      */ 
38     User createUser(String aUsername, String aPassword, Group aGroup) throws UserMgtException; 
39     
40     /**
41      * Must be called whenever a user object has been modified to notify the
42      * user set.  
43      * @param aUser Modified user. 
44      */
45     void userModified(User aUser); 
46     
47     /**
48      * Finds  user. 
49      * @param aName Username. 
50      * @return User or null if not found. 
51      */
52     User find(String aName);
53     
54     /**
55      * Checks if a user exists. 
56      * @param aUser User. 
57      * @return True iff the user exists. 
58      */
59     boolean contains(User aUser); 
60     
61     /**
62      * Adds a user. If the user already exists, the user details are updated with that
63      * of the specified user object. 
64      * @param aUser User to add. 
65      */
66     boolean add(User aUser);
67     
68     /**
69      * Removes a user. If the user does not exist, nothing happens. 
70      * @param aUser
71      */
72     boolean remove(User aUser);
73     
74     /**
75      * Lists the current users. 
76      * @return Users. 
77      */
78     Set<User> list(); 
79     
80     /**
81      * Lists the users belonging to a particular group. 
82      * @param aGroup Group. 
83      * @return Groups. 
84      */
85     Set<User> list(Group aGroup);
86
87     /**
88      * 
89      * @return The number of users. 
90      */
91     int size(); 
92 }