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