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