ffff4abd8d3b87e095032175551075ce8c032141
[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 public interface UserSet {
27     
28     /**
29      * Creates a user. 
30      * @param aUsername User name. 
31      * @param aPassword Password. 
32      * @param aGroup Group.
33      * @return New user.  
34      * @throws UserMgtException In case the user cannot be created. 
35      */ 
36     User createUser(String aUsername, String aPassword, Group aGroup) throws UserMgtException; 
37     
38     /**
39      * Must be called whenever a user object has been modified to notify the
40      * user set.  
41      * @param aUser Modified user. 
42      */
43     void userModified(User aUser); 
44     
45     /**
46      * Finds  user. 
47      * @param aName Username. 
48      * @return User or null if not found. 
49      */
50     User find(String aName);
51     
52     /**
53      * Checks if a user exists. 
54      * @param aUser User. 
55      * @return True iff the user exists. 
56      */
57     boolean contains(User aUser); 
58     
59     /**
60      * Adds a user. If the user already exists, the user details are updated with that
61      * of the specified user object. 
62      * @param aUser User to add. 
63      */
64     boolean add(User aUser);
65     
66     /**
67      * Removes a user. If the user does not exist, nothing happens. 
68      * @param aUser
69      */
70     boolean remove(User aUser);
71     
72     /**
73      * Lists the current users. 
74      * @return Users. 
75      */
76     Set<User> list(); 
77     
78     /**
79      * Lists the users belonging to a particular group. 
80      * @param aGroup Group. 
81      * @return Groups. 
82      */
83     Set<User> list(Group aGroup);
84
85     /**
86      * 
87      * @return The number of users. 
88      */
89     int size(); 
90 }