View Javadoc
1   /*
2    * Copyright (c) 2002-2014, Mairie de 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.AdminRole;
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  /**
49   * AdminUserDAO Interface
50   */
51  public interface IAdminUserDAO
52  {
53      /**
54       * Checks the availibility of an access code
55       * @param strAccessCode The access code
56       * @return user ID if the access code is already used by another user, -1 otherwise
57       */
58      int checkAccessCodeAlreadyInUse( String strAccessCode );
59  
60      /**
61       * Checks the availibility of an email
62       * @param strEmail The email
63       * @return True if the email is already used by another user
64       */
65      int checkEmailAlreadyInUse( String strEmail );
66  
67      /**
68       * Checks wether the role is in use or not
69       * @param strRoleKey the role key to check
70       * @return user ID if the emaile is already used by another user, -1 otherwise
71       */
72      boolean checkRoleAttributed( String strRoleKey );
73  
74      /**
75       * Delete an user
76       * @param nUserId the user id
77       */
78      void delete( int nUserId );
79  
80      /**
81       * Deletes rights delegated by user ie rights with level < userlevel
82       * @param nUserId the user id
83       * @param nUserLevel the user level
84       */
85      void deleteAllDelegatedRightsForUser( int nUserId, int nUserLevel );
86  
87      /**
88       * Deletes all rights owned by user ie rights with level >= userlevel
89       * @param nUserId the user id
90       * @param nUserLevel the user level
91       */
92      void deleteAllOwnRightsForUser( int nUserId, int nUserLevel );
93  
94      /**
95       * Delete all rights owned by an user
96       * @param nUserId the user id
97       */
98      void deleteAllRightsForUser( int nUserId );
99  
100     /**
101      * Remove all rights from an user
102      * @param nUserId the user id
103      */
104     void deleteAllRolesForUser( int nUserId );
105 
106     /**
107      * Insert a new record in the table.
108      * @param user The AdminUser
109      */
110     void insert( AdminUser user );
111 
112     /**
113      * Insert a new record in the table.
114      * @param user The AdminUser
115      */
116     void insert( LuteceDefaultAdminUser user );
117 
118     /**
119      * Add a right to an user
120      * @param nUserId the user id
121      * @param strRightId the right id
122      */
123     void insertRightsListForUser( int nUserId, String strRightId );
124 
125     /**
126      * Gives a role to an user
127      * @param nUserId the user id
128      * @param strRoleKey the key role
129      */
130     void insertRolesListForUser( int nUserId, String strRoleKey );
131 
132     /**
133      * Load an AdminUser
134      * @param nUserId the user id
135      * @return user
136      */
137     AdminUser load( int nUserId );
138 
139     /**
140      * Load a default AdminUser
141      * @param nUserId the user id
142      * @return user
143      */
144     LuteceDefaultAdminUser loadDefaultAdminUser( int nUserId );
145 
146     /**
147      * Generates a new primary key
148      * @return nKey
149      */
150     int newPrimaryKey(  );
151 
152     /**
153      * Get the right list associated to a given user id
154      * @param nUserId the id of the user to retrieve rights
155      * @return the right list as a collection of strings
156      */
157     Map<String, Right> selectRightsListForUser( int nUserId );
158 
159     /**
160      * Get the role list associated to a given user id
161      * @param nUserId the id of the user to retrieve roles
162      * @return the role list
163      */
164     Map<String, AdminRole> selectRolesListForUser( int nUserId );
165 
166     /**
167      * Get an user by its access code (login)
168      * @param strUserAccessCode the login
169      * @return The user found, otherwise null
170      */
171     AdminUser selectUserByAccessCode( String strUserAccessCode );
172 
173     /**
174      * Get the user access code from its email.
175      * @param strEmail The email
176      * @return The access code of the user with the given email, or null if no user has been found
177      */
178     String selectUserByEmail( String strEmail );
179 
180     /**
181      * Gets the collection of all AdminUsers
182      * @return The user list
183      */
184     Collection<AdminUser> selectUserList(  );
185 
186     /**
187      * Gets a collection of AdminUser that share a given role
188      * @param strRoleKey The role key
189      * @return The user List
190      */
191     Collection<AdminUser> selectUsersByRole( String strRoleKey );
192 
193     /**
194      * Update AdminUser data
195      * @param user The AdminUser
196      */
197     void store( AdminUser user );
198 
199     /**
200      * Update AdminUser data
201      * @param user The AdminUser
202      */
203     void store( LuteceDefaultAdminUser user );
204 
205     /**
206      * Select all user that own a given level
207      * @param nIdLevel The level
208      * @return userList The user's list
209      */
210     Collection<AdminUser> selectUsersByLevel( int nIdLevel );
211 
212     /**
213      * Update role key if role key name has change
214      * @param strOldRoleKey The old role key name
215      * @param role The new role
216      */
217     void storeUsersRole( String strOldRoleKey, AdminRole role );
218 
219     /**
220      * Check if the user has the role
221      * @param nUserId The ID of the user
222      * @param strRoleKey The role Key
223      * @return true if the user has the role
224      */
225     boolean hasRole( int nUserId, String strRoleKey );
226 
227     /**
228      * Remove role for an user
229      * @param nUserId The ID of the user
230      * @param strRoleKey The role key
231      */
232     void deleteRoleForUser( int nUserId, String strRoleKey );
233 
234     /**
235      * Select users by filter
236      * @param auFilter the filter
237      * @return a list of AdminUser
238      */
239     Collection<AdminUser> selectUsersByFilter( AdminUserFilter auFilter );
240 
241     /**
242      * Get all users having a given right
243      * @param strIdRight The ID right
244      * @return A collection of AdminUser
245      */
246     Collection<AdminUser> selectUsersByRight( String strIdRight );
247 
248     /**
249      * Check if the user has the given right
250      * @param nUserId The ID of the user
251      * @param strIdRight The ID right
252      * @return true if the user has the right
253      */
254     boolean hasRight( int nUserId, String strIdRight );
255 
256     /**
257      * Remove a right for an user
258      * @param nUserId The user ID
259      * @param strIdRight The right ID
260      */
261     void deleteRightForUser( int nUserId, String strIdRight );
262 
263     /**
264      * Gets the history of password of the given user
265      * @param nUserID Id of the user
266      * @return The collection of recent passwords used by the user.
267      */
268     List<IPassword> selectUserPasswordHistory( int nUserID );
269 
270     /**
271      * Get the number of password change done by a user since the given date.
272      * @param minDate Minimum date to consider.
273      * @param nUserId Id of the user
274      * @return The number of password change done by the user since the given date.
275      */
276     int countUserPasswordHistoryFromDate( Timestamp minDate, int nUserId );
277 
278     /**
279      * Log a password change in the password history
280      * @param password New password of the user
281      * @param nUserId Id of the user
282      */
283     void insertNewPasswordInHistory( IPassword password, int nUserId );
284 
285     /**
286      * Remove every password saved in the password history for a given user.
287      * @param nUserId Id of the user
288      */
289     void removeAllPasswordHistoryForUser( int nUserId );
290 
291     /**
292      * Get a map of anonymization status of a user field.
293      * @return A map containing the associations of user field name and a boolean describing whether the field should be anonymized.
294      */
295     Map<String, Boolean> selectAnonymizationStatusUserStaticField(  );
296 
297     /**
298      * Update the anonymization status of a user field.
299      * @param strFieldName Name of the field to update
300      * @param bAnonymizeFiled True if the field should be anonymized, false otherwise
301      */
302     void updateAnonymizationStatusUserStaticField( String strFieldName, boolean bAnonymizeFiled );
303 
304     /**
305      * Get the list of id of user with the expired status.
306      * @return The list of if of user with the expired status.
307      */
308     List<Integer> findAllExpiredUserId(  );
309 
310     /**
311      * Get the list of id of users that have an expired time life but not the expired status
312      * @param currentTimestamp Timestamp describing the current time.
313      * @return the list of id of users with expired time life
314      */
315     List<Integer> getIdUsersWithExpiredLifeTimeList( Timestamp currentTimestamp );
316 
317     /**
318      * Get the list of id of users that need to receive their first alert
319      * @param alertMaxDate The maximum date to send alerts.
320      * @return the list of id of users that need to receive their first alert
321      */
322     List<Integer> getIdUsersToSendFirstAlert( Timestamp alertMaxDate );
323 
324     /**
325      * Get the list of id of users that need to receive their first alert
326      * @param alertMaxDate The maximum date to send alerts.
327      * @param timeBetweenAlerts Timestamp describing the time between two alerts.
328      * @param maxNumberAlerts Maximum number of alerts to send to a user
329      * @return the list of id of users that need to receive their first alert
330      */
331     List<Integer> getIdUsersToSendOtherAlert( Timestamp alertMaxDate, Timestamp timeBetweenAlerts, int maxNumberAlerts );
332 
333     /**
334      * Get the list of id of users that have an expired password but not the change password flag
335      * @param currentTimestamp Timestamp describing the current time.
336      * @return the list of id of users with expired passwords
337      */
338     List<Integer> getIdUsersWithExpiredPasswordsList( Timestamp currentTimestamp );
339 
340     /**
341      * Update status of a list of user accounts
342      * @param listIdUser List of user accounts to update
343      * @param nNewStatus New status of the user
344      */
345     void updateUserStatus( List<Integer> listIdUser, int nNewStatus );
346 
347     /**
348      * Increment the number of alert send to users by 1
349      * @param listIdUser The list of users to update
350      */
351     void updateNbAlert( List<Integer> listIdUser );
352 
353     /**
354      * Set the "change password" flag of users to true
355      * @param listIdUser The list of users to update
356      */
357     void updateChangePassword( List<Integer> listIdUser );
358 
359     /**
360      * Update the admin user expiration date with the new values. Also update his alert account to 0
361      * @param nIdUser Id of the admin user to update
362      * @param newExpirationDate New expiration date of the user
363      */
364     void updateUserExpirationDate( int nIdUser, Timestamp newExpirationDate );
365 
366     /**
367      * Update the admin user last login date.
368      * @param nIdUser Id of the admin user to update
369      * @param dateLastLogin New last login date of the user
370      */
371     void updateDateLastLogin( int nIdUser, Timestamp dateLastLogin );
372 }