554590fde05aabc7ec00da0bdbd6d25bdd80ab05
[utils] / security / src / main / java / org / wamblee / usermgt / UserAdministration.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 package org.wamblee.usermgt;
17
18 import java.util.Set;
19
20
21 /**
22  * Interface for user administration. Manages the users and groups. 
23  *
24  * @author Erik Brakkee
25  */
26 public interface UserAdministration {
27     /**
28      * Creates a new user.
29      *
30      * @param aUser Username.
31      * @param aPassword Password.
32      * @param aGroup Group.
33      *
34      * @return User.
35      *
36      * @throws UserMgtException In case there is a conflict with an existing
37      *         user.
38      */
39     User createUser(String aUser, String aPassword, Group aGroup)
40         throws UserMgtException;
41
42     /**
43      * Creates a new group.
44      *
45      * @param aName Group name.
46      *
47      * @return Group
48      *
49      * @throws UserMgtException In case there is a conflict with an existing
50      *         group.
51      */
52     Group createGroup(String aName) throws UserMgtException;
53
54     /**
55      * DOCUMENT ME!
56      *
57      * @return Number of users.
58      */
59     int getUserCount();
60
61     /**
62      * DOCUMENT ME!
63      *
64      * @return Number of groups.
65      */
66     int getGroupCount();
67
68     /**
69      * Must be called when the user is modified.
70      *
71      * @param aUser User.
72      */
73     void userModified(User aUser);
74
75     /**
76      * Must be called when the group is modified.
77      *
78      * @param aGroup Group.
79      */
80     void groupModified(Group aGroup);
81
82     /**
83      * Gets the user for a given name.
84      *
85      * @param aName User name.
86      *
87      * @return User or null if not found.
88      */
89     User getUser(String aName);
90
91     /**
92      * Gets the group for a given group name.
93      *
94      * @param aName Group name.
95      *
96      * @return Group or null if not found.
97      */
98     Group getGroup(String aName);
99
100     /**
101      * DOCUMENT ME!
102      *
103      * @return DOCUMENT ME!
104      */
105 /**
106      * DOCUMENT ME!
107      *
108      * @return DOCUMENT ME!
109      */
110 /**
111      * Get the users. 
112      * @return All known users. 
113      */
114     Set<User> getUsers();
115
116     /**
117      * DOCUMENT ME!
118      *
119      * @param aGroup DOCUMENT ME!
120      *
121      * @return DOCUMENT ME!
122      */
123 /**
124      * DOCUMENT ME!
125      *
126      * @param aGroup DOCUMENT ME!
127      *
128      * @return DOCUMENT ME!
129      */
130 /**
131      * Gets the users for a given group. 
132      * @param aGroup Group. 
133      * @return Set of users (always non-null).
134      */
135     Set<User> getUsers(Group aGroup);
136
137     /**
138      * DOCUMENT ME!
139      *
140      * @return DOCUMENT ME!
141      */
142 /**
143      * DOCUMENT ME!
144      *
145      * @return DOCUMENT ME!
146      */
147 /**
148      * Gets all known groups. 
149      * @return Groups. 
150      */
151     Set<Group> getGroups();
152
153     /**
154      * Renames a user.
155      *
156      * @param aUser User object for which user name must be changed.
157      * @param aUserName New user name.
158      *
159      * @throws UserMgtException In case the user is not known or the new user
160      *         name is already in use by another user.
161      */
162     void renameUser(User aUser, String aUserName) throws UserMgtException;
163
164     /**
165      * Renames a group.
166      *
167      * @param aGroup Group to rename.
168      * @param aGroupName New name for the group.
169      *
170      * @throws UserMgtException In case the new group name is already used by
171      *         another group of if the existing group is unknown.
172      */
173     void renameGroup(Group aGroup, String aGroupName) throws UserMgtException;
174
175     /**
176      * Removes the user.
177      *
178      * @param aUser User to remove.
179      *
180      * @throws UserMgtException In case the user does not exist.
181      */
182     void removeUser(User aUser) throws UserMgtException;
183
184     /**
185      * Removes the group.
186      *
187      * @param aGroup Group to remove.
188      *
189      * @throws UserMgtException In case there are still users that are in the
190      *         given group.
191      */
192     void removeGroup(Group aGroup) throws UserMgtException;
193
194     /**
195      * Adds a user to a group.
196      *
197      * @param aUser User.
198      * @param aGroup Group.
199      *
200      * @throws UserMgtException In case the user or group or not known or if
201      *         the user  is already part of the group.
202      */
203     void addUserToGroup(User aUser, Group aGroup) throws UserMgtException;
204
205     /**
206      * Removes a user from a group.
207      *
208      * @param aUser User
209      * @param aGroup Group
210      *
211      * @throws UserMgtException In case the user or group are unknown or if the
212      *         user  is not part of the group.
213      */
214     void removeUserFromGroup(User aUser, Group aGroup)
215         throws UserMgtException;
216 }