(no commit message)
[utils] / security / usermgt / src / main / java / org / wamblee / security / authentication / UserAdministration.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.List;
19
20 /**
21  * Interface for user administration. Manages the users and groups.
22  * 
23  * @author Erik Brakkee
24  */
25 public interface UserAdministration {
26     /**
27      * Creates a new user.
28      * 
29      * @param aUser
30      *            Username.
31      * @param aPassword
32      *            Password.
33      * 
34      * @return User.
35      * 
36      * @throws UserMgtException
37      *             In case there is a conflict with an existing user.
38      */
39     void createUser(String aUser, String aPassword);
40
41     /**
42      * Creates a new group.
43      * 
44      * @param aName
45      *            Group name.
46      * 
47      * @return Group
48      * 
49      * @throws UserMgtException
50      *             In case there is a conflict with an existing group.
51      */
52     void createGroup(String aName);
53
54     /**
55      * Checks if a user exists.
56      * 
57      * @param aUser
58      *            User to check.
59      * @return True iff user exists.
60      */
61     boolean checkUser(String aUser);
62
63     /**
64      * Check if a group exists.
65      * 
66      * @param aGroup
67      *            Group.
68      * @return True iff group exists.
69      */
70     boolean checkGroup(String aGroup);
71
72     /**
73      * Checks the password.
74      * 
75      * @param aUser
76      *            User to check password for.
77      * @param aPassword
78      *            Password to check.
79      * @throws UserMgtException
80      *             In case user does not exist.
81      * @return True iff password is ok.
82      */
83     boolean checkPassword(String aUser, String aPassword);
84
85     /**
86      * Changes the password.
87      * 
88      * @param aUser
89      *            User.
90      * @param aOldPassword
91      *            Old password.
92      * @param aNewPassword
93      *            New password.
94      * 
95      * @throws UserMgtException
96      *             Inc ase the user does not exist.
97      * @return True if the password was changed.
98      */
99     boolean changePassword(String aUser, String aOldPassword,
100         String aNewPassword);
101
102     /**
103      * 
104      * @param aUser
105      *            User.
106      * @param aPassword
107      *            The password to set.
108      * 
109      * @throws UserMgtException
110      *             Inc ase the user does not exist.
111      */
112     void setPassword(String aUser, String aPassword);
113
114     /**
115      * Checks if the user belongs to the given group.
116      * 
117      * @param aUser
118      *            User
119      * @param aGroup
120      *            Group.
121      * @return True iff user is in group
122      * @throws UserMgtException
123      *             In case the user or group do not exist.
124      */
125     boolean isInGroup(String aUser, String aGroup);
126
127     /**
128      * 
129      * @return Number of users.
130      */
131     int getUserCount();
132
133     /**
134      * 
135      * @return Number of groups.
136      */
137     int getGroupCount();
138
139     /**
140      * Get the users.
141      * 
142      * @return All known users.
143      */
144     List<String> getUsers();
145
146     /**
147      * Gets the users for a given group.
148      * 
149      * @param aGroup
150      *            Group.
151      * @return Set of users (always non-null).
152      */
153     List<String> getUsers(String aGroup);
154
155     /**
156      * Gets all groups.
157      * 
158      * @return Groups.
159      */
160     List<String> getGroups();
161
162     /**
163      * Gets all groups for a given user.
164      * 
165      * @param aUser
166      *            user.
167      * @return Groups.
168      */
169     List<String> getGroups(String aUser);
170
171     /**
172      * Renames a user.
173      * 
174      * @param aOldUserName
175      *            Current user name.
176      * @param aUserName
177      *            New user name.
178      * 
179      * @throws UserMgtException
180      *             In case the user is not known or the new user name is already
181      *             in use by another user.
182      */
183     void renameUser(String aOldUserName, String aUserName);
184
185     /**
186      * Renames a group.
187      * 
188      * @param aGroup
189      *            Group to rename.
190      * @param aGroupName
191      *            New name for the group.
192      * 
193      * @throws UserMgtException
194      *             In case the new group name is already used by another group
195      *             of if the existing group is unknown.
196      */
197     void renameGroup(String aOldGroup, String aGroupName);
198
199     /**
200      * Removes the user.
201      * 
202      * @param aUser
203      *            User to remove.
204      * 
205      * @throws UserMgtException
206      *             In case the user does not exist.
207      */
208     void removeUser(String aUser);
209
210     /**
211      * Removes the group.
212      * 
213      * @param aGroup
214      *            Group to remove.
215      * 
216      * @throws UserMgtException
217      *             In case there are still users that are in the given group.
218      */
219     void removeGroup(String aGroup);
220
221     /**
222      * Adds a user to a group.
223      * 
224      * @param aUser
225      *            User.
226      * @param aGroup
227      *            Group.
228      * 
229      * @throws UserMgtException
230      *             In case the user or group or not known or if the user is
231      *             already part of the group.
232      */
233     void addUserToGroup(String aUser, String aGroup);
234
235     /**
236      * Removes a user from a group.
237      * 
238      * @param aUser
239      *            User
240      * @param aGroup
241      *            Group
242      * 
243      * @throws UserMgtException
244      *             In case the user or group are unknown or if the user is not
245      *             part of the group.
246      */
247     void removeUserFromGroup(String aUser, String aGroup);
248 }