View Javadoc
1   /*
2    * Copyright (c) 2002-2021, 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.plugins.mylutece.modules.database.authentication.business;
35  
36  import fr.paris.lutece.portal.service.plugin.Plugin;
37  import fr.paris.lutece.util.password.IPassword;
38  
39  import java.sql.Timestamp;
40  
41  import java.util.Collection;
42  import java.util.List;
43  
44  /**
45   *
46   * @author Etienne
47   */
48  public interface IDatabaseUserDAO
49  {
50      /**
51       * Generates a new primary key
52       * 
53       * @param plugin
54       *            The Plugin using this data access service
55       * @return The new primary key
56       */
57      int newPrimaryKey( Plugin plugin );
58  
59      /**
60       * Insert a new record in the table.
61       *
62       * @param databaseUser
63       *            The databaseUser object
64       * @param password
65       *            The user password
66       * @param plugin
67       *            The Plugin using this data access service
68       */
69      void insert( DatabaseUser databaseUser, IPassword password, Plugin plugin );
70  
71      /**
72       * Load the data of DatabaseUser from the table
73       *
74       * @param nDatabaseUserId
75       *            The identifier of databaseUser
76       * @param plugin
77       *            The Plugin using this data access service
78       * @return the instance of the DatabaseUser
79       */
80      DatabaseUser load( int nDatabaseUserId, Plugin plugin );
81  
82      /**
83       * Delete a record from the table
84       * 
85       * @param databaseUser
86       *            The databaseUser object
87       * @param plugin
88       *            The Plugin using this data access service
89       */
90      void delete( DatabaseUser databaseUser, Plugin plugin );
91  
92      /**
93       * Update the record in the table
94       * 
95       * @param databaseUser
96       *            The reference of databaseUser
97       * @param plugin
98       *            The Plugin using this data access service
99       */
100     void store( DatabaseUser databaseUser, Plugin plugin );
101 
102     /**
103      * Update the record in the table
104      * 
105      * @param databaseUser
106      *            The reference of databaseUser
107      * @param newPassword
108      *            The new password to store
109      * @param plugin
110      *            The Plugin using this data access service
111      */
112     void updatePassword( DatabaseUser databaseUser, IPassword newPassword, Plugin plugin );
113 
114     /**
115      * Update the record in the table
116      * 
117      * @param databaseUser
118      *            The reference of databaseUser
119      * @param bNewValue
120      *            The new value of the resetPassword attribute
121      * @param plugin
122      *            The Plugin using this data access service
123      */
124     void updateResetPassword( DatabaseUser databaseUser, boolean bNewValue, Plugin plugin );
125 
126     /**
127      * Load the list of databaseUsers
128      * 
129      * @param plugin
130      *            The Plugin using this data access service
131      * @return The Collection of the databaseUsers
132      */
133     Collection<DatabaseUser> selectDatabaseUserList( Plugin plugin );
134 
135     /**
136      * Load the list of DatabaseUsers for a login
137      * 
138      * @param strLogin
139      *            The login of DatabaseUser
140      * @param plugin
141      *            The Plugin using this data access service
142      * @return The Collection of the DatabaseUsers
143      */
144     Collection<DatabaseUser> selectDatabaseUserListForLogin( String strLogin, Plugin plugin );
145 
146     /**
147      * Load the list of DatabaseUsers for a email
148      * 
149      * @param strEmail
150      *            The email of DatabaseUser
151      * @param plugin
152      *            The Plugin using this data access service
153      * @return The Collection of the DatabaseUsers
154      */
155     Collection<DatabaseUser> selectDatabaseUserListForEmail( String strEmail, Plugin plugin );
156 
157     /**
158      * load the password for a DatabaseUser
159      *
160      * @param strLogin
161      *            The user login of DatabaseUser
162      * @param plugin
163      *            The Plugin using this data access service
164      * @return the stored password of the user
165      */
166     IPassword loadPassword( String strLogin, Plugin plugin );
167 
168     /**
169      * Load the list of DatabaseUsers by a filter
170      * 
171      * @param duFilter
172      *            filter
173      * @param plugin
174      *            Plugin
175      * @return a list of DatabaseUser
176      */
177     List<DatabaseUser> selectDatabaseUsersListByFilter( DatabaseUserFilter duFilter, Plugin plugin );
178 
179     /**
180      * Get a user id from his login
181      * 
182      * @param strLogin
183      *            The login of the user
184      * @param plugin
185      *            The plugin
186      * @return The user id, or 0 if no user has this login.
187      */
188     int findDatabaseUserIdFromLogin( String strLogin, Plugin plugin );
189 
190     /**
191      * Gets the history of password of the given user
192      * 
193      * @param nUserID
194      *            Id of the user
195      * @param plugin
196      *            The plugin
197      * @return The collection of recent passwords used by the user.
198      */
199     List<IPassword> selectUserPasswordHistory( int nUserID, Plugin plugin );
200 
201     /**
202      * Get the number of password change done by a user since the given date.
203      * 
204      * @param minDate
205      *            Minimum date to consider.
206      * @param nUserId
207      *            Id of the user
208      * @param plugin
209      *            The plugin
210      * @return The number of password change done by the user since the given date.
211      */
212     int countUserPasswordHistoryFromDate( Timestamp minDate, int nUserId, Plugin plugin );
213 
214     /**
215      * Log a password change in the password history
216      * 
217      * @param password
218      *            New password of the user
219      * @param nUserId
220      *            Id of the user
221      * @param plugin
222      *            The plugin
223      */
224     void insertNewPasswordInHistory( IPassword password, int nUserId, Plugin plugin );
225 
226     /**
227      * Remove every password saved in the password history for a user.
228      * 
229      * @param nUserId
230      *            Id of the user
231      * @param plugin
232      *            The plugin
233      */
234     void removeAllPasswordHistoryForUser( int nUserId, Plugin plugin );
235 
236     /**
237      * Get the list of id of user with the expired status.
238      * 
239      * @param plugin
240      *            The plugin
241      * @return The list of if of user with the expired status.
242      */
243     List<Integer> findAllExpiredUserId( Plugin plugin );
244 
245     /**
246      * Get the list of id of users that have an expired time life but not the expired status
247      * 
248      * @param currentTimestamp
249      *            Timestamp describing the current time.
250      * @param plugin
251      *            The plugin
252      * @return the list of id of users with expired time life
253      */
254     List<Integer> getIdUsersWithExpiredLifeTimeList( Timestamp currentTimestamp, Plugin plugin );
255 
256     /**
257      * Get the list of id of users that need to receive their first alert
258      * 
259      * @param alertMaxDate
260      *            The maximum date to send alerts.
261      * @param plugin
262      *            The plugin
263      * @return the list of id of users that need to receive their first alert
264      */
265     List<Integer> getIdUsersToSendFirstAlert( Timestamp alertMaxDate, Plugin plugin );
266 
267     /**
268      * Get the list of id of users that need to receive their first alert
269      * 
270      * @param alertMaxDate
271      *            The maximum date to send alerts.
272      * @param timeBetweenAlerts
273      *            Timestamp describing the time between two alerts.
274      * @param maxNumberAlerts
275      *            Maximum number of alerts to send to a user
276      * @param plugin
277      *            The plugin
278      * @return the list of id of users that need to receive their first alert
279      */
280     List<Integer> getIdUsersToSendOtherAlert( Timestamp alertMaxDate, Timestamp timeBetweenAlerts, int maxNumberAlerts, Plugin plugin );
281 
282     /**
283      * Get the list of id of users that have an expired password but not the change password flag
284      * 
285      * @param currentTimestamp
286      *            Timestamp describing the current time.
287      * @param plugin
288      *            The plugin
289      * @return the list of id of users with expired passwords
290      */
291     List<Integer> getIdUsersWithExpiredPasswordsList( Timestamp currentTimestamp, Plugin plugin );
292 
293     /**
294      * Update status of a list of user accounts
295      * 
296      * @param listIdUser
297      *            List of user accounts to update
298      * @param nNewStatus
299      *            New status of the user
300      * @param plugin
301      *            The plugin
302      */
303     void updateUserStatus( List<Integer> listIdUser, int nNewStatus, Plugin plugin );
304 
305     /**
306      * Increment the number of alert send to users by 1
307      * 
308      * @param listIdUser
309      *            The list of users to update
310      * @param plugin
311      *            The plugin
312      */
313     void updateNbAlert( List<Integer> listIdUser, Plugin plugin );
314 
315     /**
316      * Set the "change password" flag of users to true
317      * 
318      * @param listIdUser
319      *            The list of users to update
320      * @param plugin
321      *            The plugin
322      */
323     void updateChangePassword( List<Integer> listIdUser, Plugin plugin );
324 
325     /**
326      * Update the user expiration date with the new values. Also update his alert account to 0
327      * 
328      * @param nIdUser
329      *            Id of the user to update
330      * @param newExpirationDate
331      *            Id of the user to update
332      * @param plugin
333      *            The plugin
334      */
335     void updateUserExpirationDate( int nIdUser, Timestamp newExpirationDate, Plugin plugin );
336 
337     /**
338      * Get the number of notification send to a user to warn him about the expiration of his account
339      * 
340      * @param nIdUser
341      *            Id of the user
342      * @param plugin
343      *            The plugin
344      * @return The number of notification send to the user
345      */
346     int getNbAccountLifeTimeNotification( int nIdUser, Plugin plugin );
347 
348     /**
349      * Update a user last login date
350      * 
351      * @param strLogin
352      *            Login of the user to update
353      * @param dateLastLogin
354      *            date of the last login of the user
355      * @param plugin
356      *            The plugin
357      */
358     void updateUserLastLoginDate( String strLogin, Timestamp dateLastLogin, Plugin plugin );
359 }