1 /*
2 * Copyright (c) 2002-2025, City of Paris
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * 1. Redistributions of source code must retain the above copyright notice
10 * and the following disclaimer.
11 *
12 * 2. Redistributions in binary form must reproduce the above copyright notice
13 * and the following disclaimer in the documentation and/or other materials
14 * provided with the distribution.
15 *
16 * 3. Neither the name of 'Mairie de Paris' nor 'Lutece' nor the names of its
17 * contributors may be used to endorse or promote products derived from
18 * this software without specific prior written permission.
19 *
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
24 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30 * POSSIBILITY OF SUCH DAMAGE.
31 *
32 * License 1.0
33 */
34 package fr.paris.lutece.portal.business.user;
35
36 import fr.paris.lutece.portal.business.rbac.RBACRole;
37 import fr.paris.lutece.portal.business.right.Right;
38 import fr.paris.lutece.portal.business.user.authentication.LuteceDefaultAdminUser;
39 import fr.paris.lutece.util.password.IPassword;
40
41 import java.sql.Timestamp;
42
43 import java.util.Collection;
44 import java.util.List;
45 import java.util.Map;
46
47 /**
48 * AdminUserDAO Interface
49 */
50 public interface IAdminUserDAO
51 {
52 /**
53 * Checks the availibility of an access code
54 *
55 * @param strAccessCode
56 * The access code
57 * @return user ID if the access code is already used by another user, -1 otherwise
58 */
59 int checkAccessCodeAlreadyInUse( String strAccessCode );
60
61 /**
62 * Checks the availibility of an email
63 *
64 * @param strEmail
65 * The email
66 * @return True if the email is already used by another user
67 */
68 int checkEmailAlreadyInUse( String strEmail );
69
70 /**
71 * Checks wether the role is in use or not
72 *
73 * @param strRoleKey
74 * the role key to check
75 * @return user ID if the emaile is already used by another user, -1 otherwise
76 */
77 boolean checkRoleAttributed( String strRoleKey );
78
79 /**
80 * Delete an user
81 *
82 * @param nUserId
83 * the user id
84 */
85 void delete( int nUserId );
86
87 /**
88 * Deletes rights delegated by user ie rights with level < userlevel
89 *
90 * @param nUserId
91 * the user id
92 * @param nUserLevel
93 * the user level
94 */
95 void deleteAllDelegatedRightsForUser( int nUserId, int nUserLevel );
96
97 /**
98 * Deletes all rights owned by user ie rights with level >= userlevel
99 *
100 * @param nUserId
101 * the user id
102 * @param nUserLevel
103 * the user level
104 */
105 void deleteAllOwnRightsForUser( int nUserId, int nUserLevel );
106
107 /**
108 * Delete all rights owned by an user
109 *
110 * @param nUserId
111 * the user id
112 */
113 void deleteAllRightsForUser( int nUserId );
114
115 /**
116 * Remove all rights from an user
117 *
118 * @param nUserId
119 * the user id
120 */
121 void deleteAllRolesForUser( int nUserId );
122
123 /**
124 * Insert a new record in the table.
125 *
126 * @param user
127 * The AdminUser
128 */
129 void insert( AdminUser user );
130
131 /**
132 * Insert a new record in the table.
133 *
134 * @param user
135 * The AdminUser
136 */
137 void insert( LuteceDefaultAdminUser user );
138
139 /**
140 * Add a right to an user
141 *
142 * @param nUserId
143 * the user id
144 * @param strRightId
145 * the right id
146 */
147 void insertRightsListForUser( int nUserId, String strRightId );
148
149 /**
150 * Gives a role to an user
151 *
152 * @param nUserId
153 * the user id
154 * @param strRoleKey
155 * the key role
156 */
157 void insertRolesListForUser( int nUserId, String strRoleKey );
158
159 /**
160 * Load an AdminUser
161 *
162 * @param nUserId
163 * the user id
164 * @return user
165 */
166 AdminUser load( int nUserId );
167
168 /**
169 * Load a default AdminUser
170 *
171 * @param nUserId
172 * the user id
173 * @return user
174 */
175 LuteceDefaultAdminUser loadDefaultAdminUser( int nUserId );
176
177 /**
178 * Get the right list associated to a given user id
179 *
180 * @param nUserId
181 * the id of the user to retrieve rights
182 * @return the right list as a collection of strings
183 */
184 Map<String, Right> selectRightsListForUser( int nUserId );
185
186 /**
187 * Get the role list associated to a given user id
188 *
189 * @param nUserId
190 * the id of the user to retrieve roles
191 * @return the role list
192 */
193 Map<String, RBACRole> selectRolesListForUser( int nUserId );
194
195 /**
196 * Get an user by its access code (login)
197 *
198 * @param strUserAccessCode
199 * the login
200 * @return The user found, otherwise null
201 */
202 AdminUser selectUserByAccessCode( String strUserAccessCode );
203
204 /**
205 * Get an user by its access code (login)
206 *
207 * @param strUserAccessCode
208 * the login
209 * @param user the user to load
210 * @return The user found, otherwise null
211 */
212 <T extends AdminUser> T selectUserByAccessCode( String strUserAccessCode,T user );
213
214 /**
215 * Get the user access code from its email.
216 *
217 * @param strEmail
218 * The email
219 * @return The access code of the user with the given email, or null if no user has been found
220 */
221 String selectUserByEmail( String strEmail );
222
223 /**
224 * Gets the collection of all AdminUsers
225 *
226 * @return The user list
227 */
228 Collection<AdminUser> selectUserList( );
229
230 /**
231 * Gets a collection of AdminUser that share a given role
232 *
233 * @param strRoleKey
234 * The role key
235 * @return The user List
236 */
237 Collection<AdminUser> selectUsersByRole( String strRoleKey );
238
239 /**
240 * Update AdminUser data
241 *
242 * @param user
243 * The AdminUser
244 */
245 void store( AdminUser user );
246
247 /**
248 * Update AdminUser data
249 *
250 * @param user
251 * The AdminUser
252 * @param passwordMode
253 * Should the password be updated or not
254 */
255 void store( LuteceDefaultAdminUser user, PasswordUpdateMode passwordMode );
256
257 /**
258 * Select all user that own a given level
259 *
260 * @param nIdLevel
261 * The level
262 * @return userList The user's list
263 */
264 Collection<AdminUser> selectUsersByLevel( int nIdLevel );
265
266 /**
267 * Update role key if role key name has change
268 *
269 * @param strOldRoleKey
270 * The old role key name
271 * @param role
272 * The new role
273 */
274 void storeUsersRole( String strOldRoleKey, RBACRole role );
275
276 /**
277 * Check if the user has the role
278 *
279 * @param nUserId
280 * The ID of the user
281 * @param strRoleKey
282 * The role Key
283 * @return true if the user has the role
284 */
285 boolean hasRole( int nUserId, String strRoleKey );
286
287 /**
288 * Remove role for an user
289 *
290 * @param nUserId
291 * The ID of the user
292 * @param strRoleKey
293 * The role key
294 */
295 void deleteRoleForUser( int nUserId, String strRoleKey );
296
297 /**
298 * Select users by filter
299 *
300 * @param auFilter
301 * the filter
302 * @return a list of AdminUser
303 */
304 Collection<AdminUser> selectUsersByFilter( AdminUserFilter auFilter );
305
306 /**
307 * Get all users having a given right
308 *
309 * @param strIdRight
310 * The ID right
311 * @return A collection of AdminUser
312 */
313 Collection<AdminUser> selectUsersByRight( String strIdRight );
314
315 /**
316 * Check if the user has the given right
317 *
318 * @param nUserId
319 * The ID of the user
320 * @param strIdRight
321 * The ID right
322 * @return true if the user has the right
323 */
324 boolean hasRight( int nUserId, String strIdRight );
325
326 /**
327 * Remove a right for an user
328 *
329 * @param nUserId
330 * The user ID
331 * @param strIdRight
332 * The right ID
333 */
334 void deleteRightForUser( int nUserId, String strIdRight );
335
336 /**
337 * Gets the history of password of the given user
338 *
339 * @param nUserID
340 * Id of the user
341 * @return The collection of recent passwords used by the user.
342 */
343 List<IPassword> selectUserPasswordHistory( int nUserID );
344
345 /**
346 * Get the number of password change done by a user since the given date.
347 *
348 * @param minDate
349 * Minimum date to consider.
350 * @param nUserId
351 * Id of the user
352 * @return The number of password change done by the user since the given date.
353 */
354 int countUserPasswordHistoryFromDate( Timestamp minDate, int nUserId );
355
356 /**
357 * Log a password change in the password history
358 *
359 * @param password
360 * New password of the user
361 * @param nUserId
362 * Id of the user
363 */
364 void insertNewPasswordInHistory( IPassword password, int nUserId );
365
366 /**
367 * Remove every password saved in the password history for a given user.
368 *
369 * @param nUserId
370 * Id of the user
371 */
372 void removeAllPasswordHistoryForUser( int nUserId );
373
374 /**
375 * Get a map of anonymization status of a user field.
376 *
377 * @return A map containing the associations of user field name and a boolean describing whether the field should be anonymized.
378 */
379 Map<String, Boolean> selectAnonymizationStatusUserStaticField( );
380
381 /**
382 * Update the anonymization status of a user field.
383 *
384 * @param strFieldName
385 * Name of the field to update
386 * @param bAnonymizeFiled
387 * True if the field should be anonymized, false otherwise
388 */
389 void updateAnonymizationStatusUserStaticField( String strFieldName, boolean bAnonymizeFiled );
390
391 /**
392 * Get the list of id of user with the expired status.
393 *
394 * @return The list of if of user with the expired status.
395 */
396 List<Integer> findAllExpiredUserId( );
397
398 /**
399 * Get the list of id of users that have an expired time life but not the expired status
400 *
401 * @param currentTimestamp
402 * Timestamp describing the current time.
403 * @return the list of id of users with expired time life
404 */
405 List<Integer> getIdUsersWithExpiredLifeTimeList( Timestamp currentTimestamp );
406
407 /**
408 * Get the list of id of users that need to receive their first alert
409 *
410 * @param alertMaxDate
411 * The maximum date to send alerts.
412 * @return the list of id of users that need to receive their first alert
413 */
414 List<Integer> getIdUsersToSendFirstAlert( Timestamp alertMaxDate );
415
416 /**
417 * Get the list of id of users that need to receive their first alert
418 *
419 * @param alertMaxDate
420 * The maximum date to send alerts.
421 * @param timeBetweenAlerts
422 * Timestamp describing the time between two alerts.
423 * @param maxNumberAlerts
424 * Maximum number of alerts to send to a user
425 * @return the list of id of users that need to receive their first alert
426 */
427 List<Integer> getIdUsersToSendOtherAlert( Timestamp alertMaxDate, Timestamp timeBetweenAlerts, int maxNumberAlerts );
428
429 /**
430 * Get the list of id of users that have an expired password but not the change password flag
431 *
432 * @param currentTimestamp
433 * Timestamp describing the current time.
434 * @return the list of id of users with expired passwords
435 */
436 List<Integer> getIdUsersWithExpiredPasswordsList( Timestamp currentTimestamp );
437
438 /**
439 * Update status of a list of user accounts
440 *
441 * @param listIdUser
442 * List of user accounts to update
443 * @param nNewStatus
444 * New status of the user
445 */
446 void updateUserStatus( List<Integer> listIdUser, int nNewStatus );
447
448 /**
449 * Increment the number of alert send to users by 1
450 *
451 * @param listIdUser
452 * The list of users to update
453 */
454 void updateNbAlert( List<Integer> listIdUser );
455
456 /**
457 * Set the "change password" flag of users to true
458 *
459 * @param listIdUser
460 * The list of users to update
461 */
462 void updateChangePassword( List<Integer> listIdUser );
463
464 /**
465 * Update the admin user expiration date with the new values. Also update his alert account to 0
466 *
467 * @param nIdUser
468 * Id of the admin user to update
469 * @param newExpirationDate
470 * New expiration date of the user
471 */
472 void updateUserExpirationDate( int nIdUser, Timestamp newExpirationDate );
473
474 /**
475 * Update the admin user last login date.
476 *
477 * @param nIdUser
478 * Id of the admin user to update
479 * @param dateLastLogin
480 * New last login date of the user
481 */
482 void updateDateLastLogin( int nIdUser, Timestamp dateLastLogin );
483 }