View Javadoc
1   /*
2    * Copyright (c) 2002-2022, 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 the user access code from its email.
206      * 
207      * @param strEmail
208      *            The email
209      * @return The access code of the user with the given email, or null if no user has been found
210      */
211     String selectUserByEmail( String strEmail );
212 
213     /**
214      * Gets the collection of all AdminUsers
215      * 
216      * @return The user list
217      */
218     Collection<AdminUser> selectUserList( );
219 
220     /**
221      * Gets a collection of AdminUser that share a given role
222      * 
223      * @param strRoleKey
224      *            The role key
225      * @return The user List
226      */
227     Collection<AdminUser> selectUsersByRole( String strRoleKey );
228 
229     /**
230      * Update AdminUser data
231      * 
232      * @param user
233      *            The AdminUser
234      */
235     void store( AdminUser user );
236 
237     /**
238      * Update AdminUser data
239      * 
240      * @param user
241      *            The AdminUser
242      * @param passwordMode
243      *            Should the password be updated or not
244      */
245     void store( LuteceDefaultAdminUser user, PasswordUpdateMode passwordMode );
246 
247     /**
248      * Select all user that own a given level
249      * 
250      * @param nIdLevel
251      *            The level
252      * @return userList The user's list
253      */
254     Collection<AdminUser> selectUsersByLevel( int nIdLevel );
255 
256     /**
257      * Update role key if role key name has change
258      * 
259      * @param strOldRoleKey
260      *            The old role key name
261      * @param role
262      *            The new role
263      */
264     void storeUsersRole( String strOldRoleKey, RBACRole role );
265 
266     /**
267      * Check if the user has the role
268      * 
269      * @param nUserId
270      *            The ID of the user
271      * @param strRoleKey
272      *            The role Key
273      * @return true if the user has the role
274      */
275     boolean hasRole( int nUserId, String strRoleKey );
276 
277     /**
278      * Remove role for an user
279      * 
280      * @param nUserId
281      *            The ID of the user
282      * @param strRoleKey
283      *            The role key
284      */
285     void deleteRoleForUser( int nUserId, String strRoleKey );
286 
287     /**
288      * Select users by filter
289      * 
290      * @param auFilter
291      *            the filter
292      * @return a list of AdminUser
293      */
294     Collection<AdminUser> selectUsersByFilter( AdminUserFilter auFilter );
295 
296     /**
297      * Get all users having a given right
298      * 
299      * @param strIdRight
300      *            The ID right
301      * @return A collection of AdminUser
302      */
303     Collection<AdminUser> selectUsersByRight( String strIdRight );
304 
305     /**
306      * Check if the user has the given right
307      * 
308      * @param nUserId
309      *            The ID of the user
310      * @param strIdRight
311      *            The ID right
312      * @return true if the user has the right
313      */
314     boolean hasRight( int nUserId, String strIdRight );
315 
316     /**
317      * Remove a right for an user
318      * 
319      * @param nUserId
320      *            The user ID
321      * @param strIdRight
322      *            The right ID
323      */
324     void deleteRightForUser( int nUserId, String strIdRight );
325 
326     /**
327      * Gets the history of password of the given user
328      * 
329      * @param nUserID
330      *            Id of the user
331      * @return The collection of recent passwords used by the user.
332      */
333     List<IPassword> selectUserPasswordHistory( int nUserID );
334 
335     /**
336      * Get the number of password change done by a user since the given date.
337      * 
338      * @param minDate
339      *            Minimum date to consider.
340      * @param nUserId
341      *            Id of the user
342      * @return The number of password change done by the user since the given date.
343      */
344     int countUserPasswordHistoryFromDate( Timestamp minDate, int nUserId );
345 
346     /**
347      * Log a password change in the password history
348      * 
349      * @param password
350      *            New password of the user
351      * @param nUserId
352      *            Id of the user
353      */
354     void insertNewPasswordInHistory( IPassword password, int nUserId );
355 
356     /**
357      * Remove every password saved in the password history for a given user.
358      * 
359      * @param nUserId
360      *            Id of the user
361      */
362     void removeAllPasswordHistoryForUser( int nUserId );
363 
364     /**
365      * Get a map of anonymization status of a user field.
366      * 
367      * @return A map containing the associations of user field name and a boolean describing whether the field should be anonymized.
368      */
369     Map<String, Boolean> selectAnonymizationStatusUserStaticField( );
370 
371     /**
372      * Update the anonymization status of a user field.
373      * 
374      * @param strFieldName
375      *            Name of the field to update
376      * @param bAnonymizeFiled
377      *            True if the field should be anonymized, false otherwise
378      */
379     void updateAnonymizationStatusUserStaticField( String strFieldName, boolean bAnonymizeFiled );
380 
381     /**
382      * Get the list of id of user with the expired status.
383      * 
384      * @return The list of if of user with the expired status.
385      */
386     List<Integer> findAllExpiredUserId( );
387 
388     /**
389      * Get the list of id of users that have an expired time life but not the expired status
390      * 
391      * @param currentTimestamp
392      *            Timestamp describing the current time.
393      * @return the list of id of users with expired time life
394      */
395     List<Integer> getIdUsersWithExpiredLifeTimeList( Timestamp currentTimestamp );
396 
397     /**
398      * Get the list of id of users that need to receive their first alert
399      * 
400      * @param alertMaxDate
401      *            The maximum date to send alerts.
402      * @return the list of id of users that need to receive their first alert
403      */
404     List<Integer> getIdUsersToSendFirstAlert( Timestamp alertMaxDate );
405 
406     /**
407      * Get the list of id of users that need to receive their first alert
408      * 
409      * @param alertMaxDate
410      *            The maximum date to send alerts.
411      * @param timeBetweenAlerts
412      *            Timestamp describing the time between two alerts.
413      * @param maxNumberAlerts
414      *            Maximum number of alerts to send to a user
415      * @return the list of id of users that need to receive their first alert
416      */
417     List<Integer> getIdUsersToSendOtherAlert( Timestamp alertMaxDate, Timestamp timeBetweenAlerts, int maxNumberAlerts );
418 
419     /**
420      * Get the list of id of users that have an expired password but not the change password flag
421      * 
422      * @param currentTimestamp
423      *            Timestamp describing the current time.
424      * @return the list of id of users with expired passwords
425      */
426     List<Integer> getIdUsersWithExpiredPasswordsList( Timestamp currentTimestamp );
427 
428     /**
429      * Update status of a list of user accounts
430      * 
431      * @param listIdUser
432      *            List of user accounts to update
433      * @param nNewStatus
434      *            New status of the user
435      */
436     void updateUserStatus( List<Integer> listIdUser, int nNewStatus );
437 
438     /**
439      * Increment the number of alert send to users by 1
440      * 
441      * @param listIdUser
442      *            The list of users to update
443      */
444     void updateNbAlert( List<Integer> listIdUser );
445 
446     /**
447      * Set the "change password" flag of users to true
448      * 
449      * @param listIdUser
450      *            The list of users to update
451      */
452     void updateChangePassword( List<Integer> listIdUser );
453 
454     /**
455      * Update the admin user expiration date with the new values. Also update his alert account to 0
456      * 
457      * @param nIdUser
458      *            Id of the admin user to update
459      * @param newExpirationDate
460      *            New expiration date of the user
461      */
462     void updateUserExpirationDate( int nIdUser, Timestamp newExpirationDate );
463 
464     /**
465      * Update the admin user last login date.
466      * 
467      * @param nIdUser
468      *            Id of the admin user to update
469      * @param dateLastLogin
470      *            New last login date of the user
471      */
472     void updateDateLastLogin( int nIdUser, Timestamp dateLastLogin );
473 }