1ce6fbfa7a0fdf9ea723e7a382edeaef377fe64f
[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
17 package org.wamblee.usermgt;
18
19 import java.util.Set;
20
21 /**
22  * Interface for user administration. Manages the users and groups. 
23  *
24  * @author Erik Brakkee
25  */
26 public interface UserAdministration {
27     
28     /**
29      * Creates a new user. 
30      * @param aUser Username. 
31      * @param aPassword Password. 
32      * @param aGroup Group. 
33      * @return User. 
34      * @throws UserMgtException In case there is a conflict with an existing user. 
35      */
36     User createUser(String aUser, String aPassword, Group aGroup) throws UserMgtException; 
37     
38     /**
39      * Creates a new group. 
40      * @param aName Group name. 
41      * @return Group
42      * @throws UserMgtException In case there is a conflict with an existing group. 
43      */
44     Group createGroup(String aName) throws UserMgtException;
45     
46     /** 
47      * @return Number of users. 
48      */
49     int getUserCount(); 
50     
51     /**
52      * @return Number of groups. 
53      */
54     int getGroupCount(); 
55     
56     /**
57      * Must be called when the user is modified. 
58      * @param aUser User.
59      */
60     void userModified(User aUser);
61     
62     /**
63      * Must be called when the group is modified. 
64      * @param aGroup Group. 
65      */
66     void groupModified(Group aGroup); 
67
68     /**
69      * Gets the user for a given name. 
70      * @param aName User name. 
71      * @return User or null if not found.   
72      */
73     User getUser(String aName); 
74     
75     /**
76      * Gets the group for a given group name. 
77      * @param aName Group name. 
78      * @return Group or null if not found. 
79      */
80     Group getGroup(String aName); 
81     
82     /**
83      * Get the users. 
84      * @return All known users. 
85      */
86     Set<User> getUsers(); 
87     
88     /**
89      * Gets the users for a given group. 
90      * @param aGroup Group. 
91      * @return Set of users (always non-null).
92      */
93     Set<User> getUsers(Group aGroup);
94     
95     /**
96      * Gets all known groups. 
97      * @return Groups. 
98      */
99     Set<Group> getGroups();
100     
101     /**
102      * Renames a user. 
103      * @param aUser User object for which user name must be changed. 
104      * @param aUserName New user name. 
105      * @throws UserMgtException In case the user is not known or the new user 
106      *    name is already in use by another user.  
107      */
108     void renameUser(User aUser, String aUserName) throws UserMgtException;
109     
110     /**
111      * Renames a group. 
112      * @param aGroup Group to rename. 
113      * @param aGroupName New name for the group. 
114      * @throws UserMgtException In case the new group name is already used by 
115      *    another group of if the existing group is unknown.  
116      */
117     void renameGroup(Group aGroup, String aGroupName) throws UserMgtException;
118     
119     /**
120      * Removes the user. 
121      * @param aUser User to remove. 
122      * @throws UserMgtException In case the user does not exist.  
123      */
124     void removeUser(User aUser) throws UserMgtException;
125     
126     /**
127      * Removes the group. 
128      * @param aGroup Group to remove. 
129      * @throws UserMgtException In case there are still users that are in the given group. 
130      */
131     void removeGroup(Group aGroup) throws UserMgtException;
132     
133     /**
134      * Adds a user to a group. 
135      * @param aUser User. 
136      * @param aGroup Group. 
137      * @throws UserMgtException In case the user or group or not known or if the user 
138      *   is already part of the group. 
139      */
140     void addUserToGroup(User aUser, Group aGroup) throws UserMgtException;
141     
142     /**
143      * Removes a user from a group. 
144      * @param aUser User
145      * @param aGroup Group
146      * @throws UserMgtException In case the user or group are unknown or if the user 
147      *    is not part of the group. 
148      */
149     void removeUserFromGroup(User aUser, Group aGroup) throws UserMgtException; 
150 }
151