(no commit message)
[utils] / security / usermgt / src / main / java / org / wamblee / security / authentication / UserSet.java
1 /*
2  * Copyright 2005-2010 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 package org.wamblee.security.authentication;
17
18 import java.util.Set;
19
20 /**
21  * Represents a set of users. Typical implementations would be an implementation
22  * based on a static configuration file or an implementation backed by a
23  * database.
24  * 
25  * @author Erik Brakkee
26  */
27 public interface UserSet {
28     /**
29      * Creates a user.
30      * 
31      * @param aUsername
32      *            User name.
33      * @param aPassword
34      *            Password.
35      * 
36      * @return New user.
37      * 
38      * @throws UserMgtException
39      *             In case the user cannot be created.
40      */
41     User createUser(String aUsername, String aPassword) throws UserMgtException;
42
43     /**
44      * Must be called whenever a user object has been modified to notify the
45      * user set.
46      * 
47      * @param aUser
48      *            Modified user.
49      */
50     void userModified(User aUser);
51
52     /**
53      * Finds user.
54      * 
55      * @param aName
56      *            Username.
57      * 
58      * @return User or null if not found.
59      */
60     User find(String aName);
61
62     /**
63      * Checks if a user exists.
64      * 
65      * @param aUser
66      *            User.
67      * 
68      * @return True iff the user exists.
69      */
70     boolean contains(User aUser);
71
72     /**
73      * Adds a user. If the user already exists, the user details are updated
74      * with that of the specified user object.
75      * 
76      * @param aUser
77      *            User to add.
78      * 
79      */
80     boolean add(User aUser);
81
82     /**
83      * Removes a user.
84      * 
85      * @param aUser
86      *            User to remove
87      * @return True iff user was removed.
88      * 
89      */
90     boolean remove(User aUser);
91
92     /**
93      * Lists the current users.
94      * 
95      * @return Users.
96      */
97     Set<User> list();
98
99     /**
100      * Lists the users belonging to a particular group.
101      * 
102      * @param aGroup
103      *            Group.
104      * @return Groups.
105      */
106     Set<User> list(Group aGroup);
107
108     /**
109      * 
110      * @return The number of users.
111      */
112     int size();
113
114     /**
115      * Clears the user cache.
116      */
117     void clearCache();
118 }