1 package org.apache.archiva.redback.users;
2
3 /*
4 * Licensed to the Apache Software Foundation (ASF) under one
5 * or more contributor license agreements. See the NOTICE file
6 * distributed with this work for additional information
7 * regarding copyright ownership. The ASF licenses this file
8 * to you under the Apache License, Version 2.0 (the
9 * "License"); you may not use this file except in compliance
10 * with the License. You may obtain a copy of the License at
11 *
12 * http://www.apache.org/licenses/LICENSE-2.0
13 *
14 * Unless required by applicable law or agreed to in writing,
15 * software distributed under the License is distributed on an
16 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17 * KIND, either express or implied. See the License for the
18 * specific language governing permissions and limitations
19 * under the License.
20 */
21
22 import java.util.List;
23
24 /**
25 * User Manager Interface
26 *
27 * @author Jason van Zyl
28 * @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
29 */
30 public interface UserManager
31 {
32
33 static final String GUEST_USERNAME = "guest";
34
35 /**
36 * Is the UserManager read only? if so then create and modify actions are to be disabled
37 *
38 * @return boolean true if user manager is disabled
39 */
40 boolean isReadOnly();
41
42 /**
43 * An Identifier for the UserManager.
44 *
45 * @return the user manager identifier.
46 */
47 String getId();
48
49 /**
50 * Add a {@link UserManagerListener} to track major events in the
51 * UserManager.
52 *
53 * @param listener the listener to add.
54 */
55 void addUserManagerListener( UserManagerListener listener );
56
57 /**
58 * Remove a {@link UserManagerListener} from the collection of listeners.
59 *
60 * @param listener the listener to remove.
61 */
62 void removeUserManagerListener( UserManagerListener listener );
63
64 /**
65 * Factory method to create new User Objects based on provider specific
66 * implementation.
67 * <p/>
68 * User objects created this way do not exist in the provider's underlying
69 * data store until a call to {@link #addUser(User)} is made.
70 *
71 * @param username the username for this user.
72 * @param fullName the full name for this user.
73 * @param emailAddress the email address for this user.
74 * @return the new user object ready to use.
75 * @throws UserManagerException
76 */
77 User createUser( String username, String fullName, String emailAddress )
78 throws UserManagerException;
79
80 /**
81 * Factory method to create the guest user.
82 *
83 * @return The guest user
84 * @throws UserManagerException
85 */
86 User createGuestUser()
87 throws UserManagerException;
88
89 /**
90 * Factory method to create {@link UserQuery}s based on provider specific
91 * implementations.
92 *
93 * @return the provider implementation of UserQuery
94 */
95 UserQuery createUserQuery();
96
97 /**
98 * Get the List of {@link User} objects.
99 *
100 * @return the List of {@link User} Objects.
101 * @throws UserManagerException
102 */
103 List<User> getUsers()
104 throws UserManagerException;
105
106 List<User> getUsers( boolean orderAscending )
107 throws UserManagerException;
108
109 /**
110 * Add a User.
111 *
112 * @param user the user to add.
113 * @return the user that was just added.
114 * @throws UserManagerException
115 */
116 User addUser( User user )
117 throws UserManagerException;
118
119 /**
120 * Update a User.
121 *
122 * @param user the user to update.
123 * @return the user that was just updated.
124 * @throws UserNotFoundException if the user was not found to update.
125 */
126 User updateUser( User user )
127 throws UserNotFoundException, UserManagerException;
128
129 /**
130 * Find a User using a User name.
131 *
132 * @param username the username to find.
133 * @return the user.
134 * @throws UserNotFoundException if the user was not found.
135 */
136 User findUser( String username )
137 throws UserNotFoundException, UserManagerException;
138
139 /**
140 * Get the guest user.
141 *
142 * @return the guest user.
143 */
144 User getGuestUser()
145 throws UserNotFoundException, UserManagerException;
146
147 List<User> findUsersByUsernameKey( String usernameKey, boolean orderAscending )
148 throws UserManagerException;
149
150 List<User> findUsersByFullNameKey( String fullNameKey, boolean orderAscending )
151 throws UserManagerException;
152
153 List<User> findUsersByEmailKey( String emailKey, boolean orderAscending )
154 throws UserManagerException;
155
156 /**
157 * Find users matching properties, ordering and range as specified by the
158 * {@link UserQuery}.
159 *
160 * @param query the query.
161 * @return a List of {@link User} objects.
162 */
163 List<User> findUsersByQuery( UserQuery query )
164 throws UserManagerException;
165
166 /**
167 * true if the user exists, false if it doesn't
168 *
169 * @param principal
170 * @return true, if user exists
171 */
172 boolean userExists( String principal )
173 throws UserManagerException;
174
175 /**
176 * Delete a user using the username.
177 *
178 * @param username the username to look for.
179 * @throws UserNotFoundException the user was not found.
180 */
181 void deleteUser( String username )
182 throws UserNotFoundException, UserManagerException;
183
184 /**
185 * Add a user to the database without checking for consistency or adjusting the password. Should only be used for
186 * re-importing known-good data.
187 *
188 * @param user the user to add
189 */
190 void addUserUnchecked( User user )
191 throws UserManagerException;
192
193 void eraseDatabase();
194
195 User updateUser( User user, boolean passwordChangeRequired )
196 throws UserNotFoundException, UserManagerException;
197
198
199 /**
200 * consumer of user manager can use it to reload various configuration
201 * with the configurable implementation is possible to change dynamically the real implementation used.
202 *
203 * @since 2.1
204 */
205 void initialize();
206
207 /**
208 * @return true if this implementation is a final one and not a wrapper (configurable, cached)
209 * @since 2.1
210 */
211 boolean isFinalImplementation();
212
213 /**
214 * @return a key to be able to customize label in UI
215 * @since 2.1
216 */
217 String getDescriptionKey();
218
219 }