(no commit message)
[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.Set;
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      * @param aGroup
34      *            Group.
35      * 
36      * @return User.
37      * 
38      * @throws UserMgtException
39      *             In case there is a conflict with an existing user.
40      */
41     User createUser(String aUser, String aPassword, Group aGroup)
42         throws UserMgtException;
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     Group createGroup(String aName) throws UserMgtException;
56
57     /**
58      * 
59      * @return Number of users.
60      */
61     int getUserCount();
62
63     /**
64      * 
65      * @return Number of groups.
66      */
67     int getGroupCount();
68
69     /**
70      * Must be called when the user is modified.
71      * 
72      * @param aUser
73      *            User.
74      * @return The modified user. The user passed in to this call should be considered invalid.
75      */
76     void userModified(User aUser);
77
78     /**
79      * Must be called when the group is modified.
80      * 
81      * @param aGroup
82      *            Group.
83      */
84     void groupModified(Group aGroup);
85
86     /**
87      * Gets the user for a given name.
88      * 
89      * @param aName
90      *            User name.
91      * 
92      * @return User or null if not found.
93      */
94     User getUser(String aName);
95
96     /**
97      * Gets the group for a given group name.
98      * 
99      * @param aName
100      *            Group name.
101      * 
102      * @return Group or null if not found.
103      */
104     Group getGroup(String aName);
105
106     /**
107      * Get the users.
108      * 
109      * @return All known users.
110      */
111     Set<User> getUsers();
112
113     /**
114      * Gets the users for a given group.
115      * 
116      * @param aGroup
117      *            Group.
118      * @return Set of users (always non-null).
119      */
120     Set<User> getUsers(Group aGroup);
121
122     /**
123      * Gets all known groups.
124      * 
125      * @return Groups.
126      */
127     Set<Group> getGroups();
128
129     /**
130      * Renames a user.
131      * 
132      * @param aUser
133      *            User object for which user name must be changed.
134      * @param aUserName
135      *            New user name.
136      * 
137      * @throws UserMgtException
138      *             In case the user is not known or the new user name is already
139      *             in use by another user.
140      */
141     void renameUser(User aUser, String aUserName) throws UserMgtException;
142
143     /**
144      * Renames a group.
145      * 
146      * @param aGroup
147      *            Group to rename.
148      * @param aGroupName
149      *            New name for the group.
150      * 
151      * @throws UserMgtException
152      *             In case the new group name is already used by another group
153      *             of if the existing group is unknown.
154      */
155     void renameGroup(Group aGroup, String aGroupName) throws UserMgtException;
156
157     /**
158      * Removes the user.
159      * 
160      * @param aUser
161      *            User to remove.
162      * 
163      * @throws UserMgtException
164      *             In case the user does not exist.
165      */
166     void removeUser(User aUser) throws UserMgtException;
167
168     /**
169      * Removes the group.
170      * 
171      * @param aGroup
172      *            Group to remove.
173      * 
174      * @throws UserMgtException
175      *             In case there are still users that are in the given group.
176      */
177     void removeGroup(Group aGroup) throws UserMgtException;
178
179     /**
180      * Adds a user to a group.
181      * 
182      * @param aUser
183      *            User.
184      * @param aGroup
185      *            Group.
186      * 
187      * @throws UserMgtException
188      *             In case the user or group or not known or if the user is
189      *             already part of the group.
190      */
191     void addUserToGroup(User aUser, Group aGroup) throws UserMgtException;
192
193     /**
194      * Removes a user from a group.
195      * 
196      * @param aUser
197      *            User
198      * @param aGroup
199      *            Group
200      * 
201      * @throws UserMgtException
202      *             In case the user or group are unknown or if the user is not
203      *             part of the group.
204      */
205     void removeUserFromGroup(User aUser, Group aGroup) throws UserMgtException;
206 }