7e6f9721e69134bbd41003f6d91ece3e0f1a5ddf
[utils] / security / impl / 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)
42         throws UserMgtException;
43
44     /**
45      * Must be called whenever a user object has been modified to notify the
46      * user set.
47      * 
48      * @param aUser
49      *            Modified user.
50      */
51     void userModified(User aUser);
52
53     /**
54      * Finds user.
55      * 
56      * @param aName
57      *            Username.
58      * 
59      * @return User or null if not found.
60      */
61     User find(String aName);
62
63     /**
64      * Checks if a user exists.
65      * 
66      * @param aUser
67      *            User.
68      * 
69      * @return True iff the user exists.
70      */
71     boolean contains(User aUser);
72
73     /**
74      * Adds a user. If the user already exists, the user details are updated
75      * with that of the specified user object.
76      * 
77      * @param aUser
78      *            User to add.
79      * 
80      */
81     boolean add(User aUser);
82
83     /**
84      * Removes a user. 
85      *  
86      * @param aUser 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 }