1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
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 import fr.paris.lutece.util.password.IPasswordFactory;
41 import fr.paris.lutece.util.sql.DAOUtil;
42
43 import java.sql.Statement;
44 import java.sql.Timestamp;
45 import java.util.ArrayList;
46 import java.util.Collection;
47 import java.util.HashMap;
48 import java.util.List;
49 import java.util.Locale;
50 import java.util.Map;
51
52 import javax.inject.Inject;
53
54 import org.apache.commons.collections.CollectionUtils;
55
56
57
58
59 public class AdminUserDAO implements IAdminUserDAO
60 {
61
62 private static final String CONSTANT_AND_STATUS = " AND status = ?";
63 private static final String CONSTANT_AND_USER_LEVEL = " AND level_user = ?";
64 private static final String CONSTANT_ORDER_BY_LAST_NAME = " ORDER BY last_name ";
65 private static final String CONSTANT_PERCENT = "%";
66 private static final String SQL_QUERY_INSERT = "INSERT INTO core_admin_user ( access_code, last_name , first_name, email, status, locale, level_user, accessibility_mode, password_max_valid_date, account_max_valid_date ) VALUES ( ?, ?, ?, ?, ?, ?, ?, ?, ?, ? ) ";
67 private static final String SQL_QUERY_SELECTALL = "SELECT id_user , access_code, last_name , first_name, email, status, locale, level_user, accessibility_mode, reset_password, password_max_valid_date, account_max_valid_date, last_login, workgroup_key FROM core_admin_user ORDER BY last_name ";
68 private static final String SQL_QUERY_SELECT_USER_FROM_USER_ID = "SELECT id_user , access_code, last_name , first_name, email, status, password, locale, level_user, reset_password, accessibility_mode, password_max_valid_date, account_max_valid_date, workgroup_key FROM core_admin_user WHERE id_user = ? ";
69 private static final String SQL_QUERY_SELECT_USER_FROM_ACCESS_CODE = "SELECT id_user, access_code, last_name, first_name, email, status, locale, level_user, reset_password, accessibility_mode, password_max_valid_date, last_login FROM core_admin_user WHERE access_code = ? ";
70 private static final String SQL_QUERY_SELECT_USER_FROM_EMAIL = "SELECT access_code FROM core_admin_user WHERE email = ? ";
71 private static final String SQL_QUERY_SELECT_RIGHTS_FROM_USER_ID = " SELECT a.id_right , a.name, a.admin_url , a.description , a.plugin_name, a.id_feature_group, a.icon_url, a.level_right, a.documentation_url, a.id_order, a.is_external_feature "
72 + " FROM core_admin_right a , core_user_right b " + " WHERE a.id_right = b.id_right " + " AND b.id_user = ? "
73 + " ORDER BY a.id_order ASC, a.id_right ASC ";
74 private static final String SQL_QUERY_UPDATE = "UPDATE core_admin_user SET access_code = ? , last_name = ? , first_name = ?, email = ?, status = ?, locale = ?, reset_password = ?, accessibility_mode = ?, password_max_valid_date = ?, level_user = ? WHERE id_user = ? ";
75 private static final String SQL_QUERY_DELETE = "DELETE FROM core_admin_user WHERE id_user = ? ";
76 private static final String SQL_QUERY_INSERT_USER_RIGHT = "INSERT INTO core_user_right ( id_right, id_user ) VALUES ( ? , ? ) ";
77 private static final String SQL_QUERY_DELETE_ALL_USER_RIGHTS = "DELETE FROM core_user_right WHERE id_user = ? ";
78 private static final String SQL_QUERY_SELECT_ROLES_FROM_USER_ID = " SELECT a.role_key , a.role_description "
79 + " FROM core_admin_role a , core_user_role b WHERE a.role_key = b.role_key " + " AND b.id_user = ? ORDER BY a.role_key ";
80 private static final String SQL_QUERY_INSERT_USER_ROLE = " INSERT INTO core_user_role ( role_key, id_user ) VALUES ( ? , ? ) ";
81 private static final String SQL_QUERY_DELETE_ALL_USER_ROLES = " DELETE FROM core_user_role WHERE id_user = ? ";
82 private static final String SQL_CHECK_ROLE_ATTRIBUTED = " SELECT id_user FROM core_user_role WHERE role_key = ?";
83 private static final String SQL_CHECK_ACCESS_CODE_IN_USE = " SELECT id_user FROM core_admin_user WHERE access_code = ?";
84 private static final String SQL_CHECK_EMAIL_IN_USE = " SELECT id_user FROM core_admin_user WHERE email = ?";
85 private static final String SQL_QUERY_INSERT_DEFAULT_USER = " INSERT INTO core_admin_user ( access_code, last_name, first_name, email, status, password, locale, level_user, accessibility_mode, reset_password, password_max_valid_date, account_max_valid_date, last_login, workgroup_key ) VALUES ( ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ? ) ";
86 private static final String SQL_QUERY_UPDATE_DEFAULT_USER = " UPDATE core_admin_user SET access_code = ?, last_name = ?, first_name = ?, email = ?, status = ?, password = ?, locale = ?, reset_password = ?, accessibility_mode = ?, password_max_valid_date = ?, workgroup_key = ?, level_user = ? WHERE id_user = ? ";
87 private static final String SQL_QUERY_UPDATE_DEFAULT_USER_IGNORE_PASSWORD = " UPDATE core_admin_user SET access_code = ?, last_name = ?, first_name = ?, email = ?, status = ?, locale = ?, reset_password = ?, accessibility_mode = ?, password_max_valid_date = ?, workgroup_key = ?, level_user = ? WHERE id_user = ? ";
88 private static final String SQL_QUERY_SELECT_USERS_ID_BY_ROLES = " SELECT a.id_user , a.access_code, a.last_name , a.first_name, a.email, a.status, a.locale, a.accessibility_mode, a.password_max_valid_date "
89 + " FROM core_admin_user a, core_user_role b WHERE a.id_user = b.id_user AND b.role_key = ? ";
90 private static final String SQL_QUERY_SELECT_USER_RIGHTS_OWN = " SELECT DISTINCT b.id_right FROM core_admin_right a , core_user_right b WHERE b.id_user = ? and a.id_right = b.id_right and a.level_right >= ?";
91 private static final String SQL_QUERY_SELECT_USER_RIGHTS_DELEGATED = " SELECT DISTINCT b.id_right FROM core_admin_right a , core_user_right b WHERE b.id_user = ? and a.id_right = b.id_right and a.level_right < ?";
92 private static final String SQL_QUERY_DELETE_USER_RIGHTS = " DELETE FROM core_user_right WHERE id_user = ? and id_right = ?";
93 private static final String SQL_QUERY_SELECT_USERS_BY_LEVEL = " SELECT a.id_user, a.access_code, a.last_name, a.first_name, a.email, a.status, a.locale, a.accessibility_mode "
94 + " FROM core_admin_user a WHERE a.level_user = ? ";
95 private static final String SQL_QUERY_UPDATE_USERS_ROLE = "UPDATE core_user_role SET role_key = ? WHERE role_key = ?";
96 private static final String SQL_QUERY_SELECT_USER_ROLE = " SELECT id_user FROM core_user_role WHERE id_user = ? AND role_key = ? ";
97 private static final String SQL_QUERY_DELETE_ROLE_FOR_USER = " DELETE FROM core_user_role WHERE id_user = ? AND role_key = ? ";
98 private static final String SQL_QUERY_SELECT_USER_FROM_SEARCH = " SELECT id_user, access_code, last_name, first_name, email, status, locale, level_user, accessibility_mode "
99 + " FROM core_admin_user WHERE access_code LIKE ? AND last_name LIKE ? AND email LIKE ? AND first_name LIKE ? ";
100 private static final String SQL_QUERY_SELECT_USERS_BY_RIGHT = " SELECT u.id_user , u.access_code, u.last_name , u.first_name, u.email, u.status, u.locale, u.level_user, u.accessibility_mode "
101 + " FROM core_admin_user u INNER JOIN core_user_right r ON u.id_user = r.id_user WHERE r.id_right = ? ";
102 private static final String SQL_QUERY_SELECT_USER_RIGHT = " SELECT id_user FROM core_user_right WHERE id_user = ? AND id_right = ? ";
103 private static final String SQL_SELECT_USER_PASSWORD_HISTORY = "SELECT password FROM core_user_password_history WHERE id_user = ? ORDER BY date_password_change desc";
104 private static final String SQL_COUNT_USER_PASSWORD_HISTORY = "SELECT COUNT(*) FROM core_user_password_history WHERE id_user = ? AND date_password_change > ?";
105 private static final String SQL_INSERT_PASSWORD_HISTORY = "INSERT INTO core_user_password_history (id_user, password) VALUES ( ?, ? ) ";
106 private static final String SQL_DELETE_PASSWORD_HISTORY = "DELETE FROM core_user_password_history WHERE id_user = ?";
107 private static final String SQL_SELECT_ANONYMIZATION_STATUS_USER_FILED = "SELECT field_name, anonymize from core_admin_user_anonymize_field";
108 private static final String SQL_UPDATE_ANONYMIZATION_STATUS_USER_FILED = "UPDATE core_admin_user_anonymize_field SET anonymize = ? WHERE field_name = ? ";
109 private static final String SQL_QUERY_SELECT_EXPIRED_USER_ID = "SELECT id_user FROM core_admin_user WHERE status = ?";
110 private static final String SQL_QUERY_SELECT_EXPIRED_LIFE_TIME_USER_ID = "SELECT id_user FROM core_admin_user WHERE account_max_valid_date < ? and status < ? ";
111 private static final String SQL_QUERY_SELECT_USER_ID_FIRST_ALERT = "SELECT id_user FROM core_admin_user WHERE nb_alerts_sent = 0 and status < ? and account_max_valid_date < ? ";
112 private static final String SQL_QUERY_SELECT_USER_ID_OTHER_ALERT = "SELECT id_user FROM core_admin_user "
113 + "WHERE nb_alerts_sent > 0 and nb_alerts_sent <= ? and status < ? and (account_max_valid_date + nb_alerts_sent * ?) < ? ";
114 private static final String SQL_QUERY_SELECT_USER_ID_PASSWORD_EXPIRED = " SELECT id_user FROM core_admin_user WHERE password_max_valid_date < ? AND reset_password = 0 ";
115 private static final String SQL_QUERY_UPDATE_STATUS = " UPDATE core_admin_user SET status = ? WHERE id_user IN ( ";
116 private static final String SQL_QUERY_UPDATE_NB_ALERT = " UPDATE core_admin_user SET nb_alerts_sent = nb_alerts_sent + 1 WHERE id_user IN ( ";
117 private static final String SQL_QUERY_UPDATE_RESET_PASSWORD_LIST_ID = " UPDATE core_admin_user SET reset_password = 1 WHERE id_user IN ( ";
118 private static final String SQL_QUERY_UPDATE_REACTIVATE_ACCOUNT = " UPDATE core_admin_user SET nb_alerts_sent = 0, account_max_valid_date = ? WHERE id_user = ? ";
119 private static final String SQL_QUERY_UPDATE_DATE_LAST_LOGIN = " UPDATE core_admin_user SET last_login = ? WHERE id_user = ? ";
120 private static final String CONSTANT_CLOSE_PARENTHESIS = " ) ";
121 private static final String CONSTANT_COMMA = ", ";
122
123 @Inject
124 private IPasswordFactory _passwordFactory;
125
126
127
128
129 @Override
130 public AdminUser load( int nUserId )
131 {
132 AdminUser user = null;
133 try ( DAOUtil/DAOUtil.html#DAOUtil">DAOUtil daoUtil = new DAOUtil( SQL_QUERY_SELECT_USER_FROM_USER_ID ) )
134 {
135 daoUtil.setInt( 1, nUserId );
136 daoUtil.executeQuery( );
137
138 if ( daoUtil.next( ) )
139 {
140 user = new AdminUser( );
141 user.setUserId( daoUtil.getInt( 1 ) );
142 user.setAccessCode( daoUtil.getString( 2 ) );
143 user.setLastName( daoUtil.getString( 3 ) );
144 user.setFirstName( daoUtil.getString( 4 ) );
145 user.setEmail( daoUtil.getString( 5 ) );
146 user.setStatus( daoUtil.getInt( 6 ) );
147 user.setLocale( new Locale( daoUtil.getString( 8 ) ) );
148 user.setUserLevel( daoUtil.getInt( 9 ) );
149 user.setPasswordReset( daoUtil.getBoolean( 10 ) );
150 user.setAccessibilityMode( daoUtil.getBoolean( 11 ) );
151 user.setPasswordMaxValidDate( daoUtil.getTimestamp( 12 ) );
152
153 long accountTime = daoUtil.getLong( 13 );
154
155 if ( accountTime > 0 )
156 {
157 user.setAccountMaxValidDate( new Timestamp( accountTime ) );
158 }
159 }
160
161 }
162
163 return user;
164 }
165
166
167
168
169 @Override
170 public AdminUser selectUserByAccessCode( String strUserAccessCode )
171 {
172 AdminUser user = null;
173 try ( DAOUtil/DAOUtil.html#DAOUtil">DAOUtil daoUtil = new DAOUtil( SQL_QUERY_SELECT_USER_FROM_ACCESS_CODE ) )
174 {
175 daoUtil.setString( 1, strUserAccessCode );
176 daoUtil.executeQuery( );
177
178 if ( daoUtil.next( ) )
179 {
180 user = new AdminUser( );
181 user.setUserId( daoUtil.getInt( 1 ) );
182 user.setAccessCode( daoUtil.getString( 2 ) );
183 user.setLastName( daoUtil.getString( 3 ) );
184 user.setFirstName( daoUtil.getString( 4 ) );
185 user.setEmail( daoUtil.getString( 5 ) );
186 user.setStatus( daoUtil.getInt( 6 ) );
187 user.setLocale( new Locale( daoUtil.getString( 7 ) ) );
188 user.setUserLevel( daoUtil.getInt( 8 ) );
189 user.setPasswordReset( daoUtil.getBoolean( 9 ) );
190 user.setAccessibilityMode( daoUtil.getBoolean( 10 ) );
191 user.setPasswordMaxValidDate( daoUtil.getTimestamp( 11 ) );
192
193 Timestamp dateLastLogin = daoUtil.getTimestamp( 12 );
194
195 if ( ( dateLastLogin != null ) && !dateLastLogin.equals( AdminUser.getDefaultDateLastLogin( ) ) )
196 {
197 user.setDateLastLogin( dateLastLogin );
198 }
199 }
200
201 }
202
203 return user;
204 }
205
206
207
208
209 @Override
210 public String selectUserByEmail( String strEmail )
211 {
212 String strAccessCode = null;
213 try ( DAOUtil/DAOUtil.html#DAOUtil">DAOUtil daoUtil = new DAOUtil( SQL_QUERY_SELECT_USER_FROM_EMAIL ) )
214 {
215 daoUtil.setString( 1, strEmail );
216 daoUtil.executeQuery( );
217
218 if ( daoUtil.next( ) )
219 {
220 strAccessCode = daoUtil.getString( 1 );
221 }
222
223 }
224
225 return strAccessCode;
226 }
227
228
229
230
231 @Override
232 public Collection<AdminUser> selectUserList( )
233 {
234 Collection<AdminUser> userList = new ArrayList<>( );
235 try ( DAOUtil/DAOUtil.html#DAOUtil">DAOUtil daoUtil = new DAOUtil( SQL_QUERY_SELECTALL ) )
236 {
237 daoUtil.executeQuery( );
238
239 while ( daoUtil.next( ) )
240 {
241 AdminUserbusiness/user/AdminUser.html#AdminUser">AdminUser user = new AdminUser( );
242 user.setUserId( daoUtil.getInt( 1 ) );
243 user.setAccessCode( daoUtil.getString( 2 ) );
244 user.setLastName( daoUtil.getString( 3 ) );
245 user.setFirstName( daoUtil.getString( 4 ) );
246 user.setEmail( daoUtil.getString( 5 ) );
247 user.setStatus( daoUtil.getInt( 6 ) );
248 user.setLocale( new Locale( daoUtil.getString( 7 ) ) );
249 user.setUserLevel( daoUtil.getInt( 8 ) );
250 user.setAccessibilityMode( daoUtil.getBoolean( 9 ) );
251 user.setPasswordReset( daoUtil.getBoolean( 10 ) );
252 user.setPasswordMaxValidDate( daoUtil.getTimestamp( 11 ) );
253
254 long accountTime = daoUtil.getLong( 12 );
255
256 if ( accountTime > 0 )
257 {
258 user.setAccountMaxValidDate( new Timestamp( accountTime ) );
259 }
260
261 Timestamp dateLastLogin = daoUtil.getTimestamp( 13 );
262
263 if ( ( dateLastLogin != null ) && !dateLastLogin.equals( AdminUser.getDefaultDateLastLogin( ) ) )
264 {
265 user.setDateLastLogin( dateLastLogin );
266 }
267
268 user.setWorkgroupKey( daoUtil.getString( 14 ) );
269 userList.add( user );
270 }
271
272 }
273
274 return userList;
275 }
276
277
278
279
280 @Override
281 public void insert( AdminUser user )
282 {
283 try ( DAOUtil/DAOUtil.html#DAOUtil">DAOUtil daoUtil = new DAOUtil( SQL_QUERY_INSERT, Statement.RETURN_GENERATED_KEYS ) )
284 {
285 int nIndex = 1;
286 daoUtil.setString( nIndex++, user.getAccessCode( ) );
287 daoUtil.setString( nIndex++, user.getLastName( ) );
288 daoUtil.setString( nIndex++, user.getFirstName( ) );
289 daoUtil.setString( nIndex++, user.getEmail( ) );
290 daoUtil.setInt( nIndex++, user.getStatus( ) );
291 daoUtil.setString( nIndex++, user.getLocale( ).toString( ) );
292 daoUtil.setInt( nIndex++, user.getUserLevel( ) );
293 daoUtil.setBoolean( nIndex++, user.getAccessibilityMode( ) );
294 daoUtil.setTimestamp( nIndex++, user.getPasswordMaxValidDate( ) );
295
296 if ( user.getAccountMaxValidDate( ) == null )
297 {
298 daoUtil.setLongNull( nIndex );
299 }
300 else
301 {
302 daoUtil.setLong( nIndex, user.getAccountMaxValidDate( ).getTime( ) );
303 }
304
305 daoUtil.executeUpdate( );
306
307 if ( daoUtil.nextGeneratedKey( ) )
308 {
309 user.setUserId( daoUtil.getGeneratedKeyInt( 1 ) );
310 }
311 }
312 }
313
314
315
316
317 @Override
318 public void store( AdminUser user )
319 {
320 try ( DAOUtil/DAOUtil.html#DAOUtil">DAOUtil daoUtil = new DAOUtil( SQL_QUERY_UPDATE ) )
321 {
322
323 daoUtil.setString( 1, user.getAccessCode( ) );
324 daoUtil.setString( 2, user.getLastName( ) );
325 daoUtil.setString( 3, user.getFirstName( ) );
326 daoUtil.setString( 4, user.getEmail( ) );
327 daoUtil.setInt( 5, user.getStatus( ) );
328 daoUtil.setString( 6, user.getLocale( ).toString( ) );
329 daoUtil.setBoolean( 7, user.isPasswordReset( ) );
330 daoUtil.setBoolean( 8, user.getAccessibilityMode( ) );
331 daoUtil.setTimestamp( 9, user.getPasswordMaxValidDate( ) );
332 daoUtil.setInt( 10, user.getUserLevel( ) );
333
334 daoUtil.setInt( 11, user.getUserId( ) );
335
336 daoUtil.executeUpdate( );
337 }
338 }
339
340
341
342
343 @Override
344 public void delete( int nUserId )
345 {
346 try ( DAOUtil/DAOUtil.html#DAOUtil">DAOUtil daoUtil = new DAOUtil( SQL_QUERY_DELETE ) )
347 {
348 daoUtil.setInt( 1, nUserId );
349 daoUtil.executeUpdate( );
350 }
351 }
352
353
354
355
356 @Override
357 public Map<String, Right> selectRightsListForUser( int nUserId )
358 {
359 Map<String, Right> rightsMap = new HashMap<>( );
360
361 try ( DAOUtil/DAOUtil.html#DAOUtil">DAOUtil daoUtil = new DAOUtil( SQL_QUERY_SELECT_RIGHTS_FROM_USER_ID ) )
362 {
363 daoUtil.setInt( 1, nUserId );
364 daoUtil.executeQuery( );
365
366 while ( daoUtil.next( ) )
367 {
368 Rightal/business/right/Right.html#Right">Right right = new Right( );
369 right.setId( daoUtil.getString( 1 ) );
370 right.setNameKey( daoUtil.getString( 2 ) );
371 right.setUrl( daoUtil.getString( 3 ) );
372 right.setDescriptionKey( daoUtil.getString( 4 ) );
373 right.setPluginName( daoUtil.getString( 5 ) );
374 right.setFeatureGroup( daoUtil.getString( 6 ) );
375 right.setIconUrl( daoUtil.getString( 7 ) );
376 right.setLevel( daoUtil.getInt( 8 ) );
377 right.setDocumentationUrl( daoUtil.getString( 9 ) );
378 right.setOrder( daoUtil.getInt( 10 ) );
379 right.setExternalFeature( daoUtil.getBoolean( 11 ) );
380 rightsMap.put( right.getId( ), right );
381 }
382
383 }
384
385 return rightsMap;
386 }
387
388
389
390
391 @Override
392 public void insertRightsListForUser( int nUserId, String strRightId )
393 {
394 try ( DAOUtil/DAOUtil.html#DAOUtil">DAOUtil daoUtil = new DAOUtil( SQL_QUERY_INSERT_USER_RIGHT ) )
395 {
396 daoUtil.setString( 1, strRightId );
397 daoUtil.setInt( 2, nUserId );
398 daoUtil.executeUpdate( );
399 }
400 }
401
402
403
404
405 @Override
406 public void deleteAllRightsForUser( int nUserId )
407 {
408 try ( DAOUtil/DAOUtil.html#DAOUtil">DAOUtil daoUtil = new DAOUtil( SQL_QUERY_DELETE_ALL_USER_RIGHTS ) )
409 {
410 daoUtil.setInt( 1, nUserId );
411 daoUtil.executeUpdate( );
412 }
413 }
414
415
416
417
418 @Override
419 public Map<String, RBACRole> selectRolesListForUser( int nUserId )
420 {
421 Map<String, RBACRole> rolesMap = new HashMap<>( );
422
423 try ( DAOUtil/DAOUtil.html#DAOUtil">DAOUtil daoUtil = new DAOUtil( SQL_QUERY_SELECT_ROLES_FROM_USER_ID ) )
424 {
425 daoUtil.setInt( 1, nUserId );
426 daoUtil.executeQuery( );
427
428 while ( daoUtil.next( ) )
429 {
430 RBACRole/business/rbac/RBACRole.html#RBACRole">RBACRole role = new RBACRole( );
431 role.setKey( daoUtil.getString( 1 ) );
432 role.setDescription( daoUtil.getString( 2 ) );
433
434 rolesMap.put( role.getKey( ), role );
435 }
436
437 }
438
439 return rolesMap;
440 }
441
442
443
444
445 @Override
446 public void insertRolesListForUser( int nUserId, String strRoleKey )
447 {
448 try ( DAOUtil/DAOUtil.html#DAOUtil">DAOUtil daoUtil = new DAOUtil( SQL_QUERY_INSERT_USER_ROLE ) )
449 {
450 daoUtil.setString( 1, strRoleKey );
451 daoUtil.setInt( 2, nUserId );
452 daoUtil.executeUpdate( );
453 }
454 }
455
456
457
458
459 @Override
460 public void deleteAllRolesForUser( int nUserId )
461 {
462 try ( DAOUtil/DAOUtil.html#DAOUtil">DAOUtil daoUtil = new DAOUtil( SQL_QUERY_DELETE_ALL_USER_ROLES ) )
463 {
464 daoUtil.setInt( 1, nUserId );
465 daoUtil.executeUpdate( );
466 }
467 }
468
469
470
471
472 @Override
473 public boolean checkRoleAttributed( String strRoleKey )
474 {
475 boolean bInUse = false;
476
477 try ( DAOUtil/DAOUtil.html#DAOUtil">DAOUtil daoUtil = new DAOUtil( SQL_CHECK_ROLE_ATTRIBUTED ) )
478 {
479 daoUtil.setString( 1, strRoleKey );
480 daoUtil.executeQuery( );
481
482 if ( daoUtil.next( ) )
483 {
484 bInUse = true;
485 }
486
487 }
488
489 return bInUse;
490 }
491
492
493
494
495 @Override
496 public int checkAccessCodeAlreadyInUse( String strAccessCode )
497 {
498 int nIdUser = -1;
499 try ( DAOUtil/DAOUtil.html#DAOUtil">DAOUtil daoUtil = new DAOUtil( SQL_CHECK_ACCESS_CODE_IN_USE ) )
500 {
501 daoUtil.setString( 1, strAccessCode );
502 daoUtil.executeQuery( );
503
504 if ( daoUtil.next( ) )
505 {
506 nIdUser = daoUtil.getInt( 1 );
507 }
508
509 }
510
511 return nIdUser;
512 }
513
514
515
516
517 @Override
518 public int checkEmailAlreadyInUse( String strEmail )
519 {
520 int nIdUser = -1;
521 try ( DAOUtil/DAOUtil.html#DAOUtil">DAOUtil daoUtil = new DAOUtil( SQL_CHECK_EMAIL_IN_USE ) )
522 {
523 daoUtil.setString( 1, strEmail );
524 daoUtil.executeQuery( );
525
526 if ( daoUtil.next( ) )
527 {
528 nIdUser = daoUtil.getInt( 1 );
529 }
530
531 }
532
533 return nIdUser;
534 }
535
536
537
538
539
540
541 @Override
542 public void insert( LuteceDefaultAdminUser user )
543 {
544 try ( DAOUtil/DAOUtil.html#DAOUtil">DAOUtil daoUtil = new DAOUtil( SQL_QUERY_INSERT_DEFAULT_USER, Statement.RETURN_GENERATED_KEYS ) )
545 {
546 int nIndex = 1;
547 daoUtil.setString( nIndex++, user.getAccessCode( ) );
548 daoUtil.setString( nIndex++, user.getLastName( ) );
549 daoUtil.setString( nIndex++, user.getFirstName( ) );
550 daoUtil.setString( nIndex++, user.getEmail( ) );
551 daoUtil.setInt( nIndex++, user.getStatus( ) );
552 daoUtil.setString( nIndex++, user.getPassword( ).getStorableRepresentation( ) );
553 daoUtil.setString( nIndex++, user.getLocale( ).toString( ) );
554 daoUtil.setInt( nIndex++, user.getUserLevel( ) );
555 daoUtil.setBoolean( nIndex++, user.getAccessibilityMode( ) );
556 daoUtil.setBoolean( nIndex++, user.isPasswordReset( ) );
557 daoUtil.setTimestamp( nIndex++, user.getPasswordMaxValidDate( ) );
558
559 if ( user.getAccountMaxValidDate( ) == null )
560 {
561 daoUtil.setLongNull( nIndex++ );
562 }
563 else
564 {
565 daoUtil.setLong( nIndex++, user.getAccountMaxValidDate( ).getTime( ) );
566 }
567
568 daoUtil.setTimestamp( nIndex++, user.getDateLastLogin( ) );
569 daoUtil.setString( nIndex, user.getWorkgroupKey( ) );
570 daoUtil.executeUpdate( );
571
572 if ( daoUtil.nextGeneratedKey( ) )
573 {
574 user.setUserId( daoUtil.getGeneratedKeyInt( 1 ) );
575 }
576 }
577 }
578
579
580
581
582 @Override
583 public void store( LuteceDefaultAdminUser user, PasswordUpdateMode passwordMode )
584 {
585 String query = SQL_QUERY_UPDATE_DEFAULT_USER_IGNORE_PASSWORD;
586 if ( PasswordUpdateMode.UPDATE.equals( passwordMode ) )
587 {
588 query = SQL_QUERY_UPDATE_DEFAULT_USER;
589 }
590 try ( DAOUtil/DAOUtil.html#DAOUtil">DAOUtil daoUtil = new DAOUtil( query ) )
591 {
592
593 int nArgIndex = 1;
594 daoUtil.setString( nArgIndex++, user.getAccessCode( ) );
595 daoUtil.setString( nArgIndex++, user.getLastName( ) );
596 daoUtil.setString( nArgIndex++, user.getFirstName( ) );
597 daoUtil.setString( nArgIndex++, user.getEmail( ) );
598 daoUtil.setInt( nArgIndex++, user.getStatus( ) );
599 if ( PasswordUpdateMode.UPDATE.equals( passwordMode ) )
600 {
601 daoUtil.setString( nArgIndex++, user.getPassword( ).getStorableRepresentation( ) );
602 }
603 daoUtil.setString( nArgIndex++, user.getLocale( ).toString( ) );
604 daoUtil.setBoolean( nArgIndex++, user.isPasswordReset( ) );
605 daoUtil.setBoolean( nArgIndex++, user.getAccessibilityMode( ) );
606 daoUtil.setTimestamp( nArgIndex++, user.getPasswordMaxValidDate( ) );
607 daoUtil.setString( nArgIndex++, user.getWorkgroupKey( ) );
608 daoUtil.setInt( nArgIndex++, user.getUserLevel( ) );
609
610 daoUtil.setInt( nArgIndex++, user.getUserId( ) );
611
612 daoUtil.executeUpdate( );
613 }
614 }
615
616
617
618
619 @Override
620 public LuteceDefaultAdminUser loadDefaultAdminUser( int nUserId )
621 {
622 LuteceDefaultAdminUser/authentication/LuteceDefaultAdminUser.html#LuteceDefaultAdminUser">LuteceDefaultAdminUser user = new LuteceDefaultAdminUser( );
623 try ( DAOUtil/DAOUtil.html#DAOUtil">DAOUtil daoUtil = new DAOUtil( SQL_QUERY_SELECT_USER_FROM_USER_ID ) )
624 {
625 daoUtil.setInt( 1, nUserId );
626 daoUtil.executeQuery( );
627
628 if ( daoUtil.next( ) )
629 {
630 user.setUserId( daoUtil.getInt( 1 ) );
631 user.setAccessCode( daoUtil.getString( 2 ) );
632 user.setLastName( daoUtil.getString( 3 ) );
633 user.setFirstName( daoUtil.getString( 4 ) );
634 user.setEmail( daoUtil.getString( 5 ) );
635 user.setStatus( daoUtil.getInt( 6 ) );
636 user.setPassword( _passwordFactory.getPassword( daoUtil.getString( 7 ) ) );
637
638 Locale locale = new Locale( daoUtil.getString( 8 ) );
639 user.setLocale( locale );
640 user.setUserLevel( daoUtil.getInt( 9 ) );
641 user.setPasswordReset( daoUtil.getBoolean( 10 ) );
642 user.setAccessibilityMode( daoUtil.getBoolean( 11 ) );
643 user.setWorkgroupKey( daoUtil.getString( 14 ) );
644 }
645 }
646
647 return user;
648 }
649
650
651
652
653 @Override
654 public Collection<AdminUser> selectUsersByRole( String strRoleKey )
655 {
656 Collection<AdminUser> userList = new ArrayList<>( );
657 try ( DAOUtil/DAOUtil.html#DAOUtil">DAOUtil daoUtil = new DAOUtil( SQL_QUERY_SELECT_USERS_ID_BY_ROLES ) )
658 {
659 daoUtil.setString( 1, strRoleKey );
660 daoUtil.executeQuery( );
661
662 while ( daoUtil.next( ) )
663 {
664 AdminUserbusiness/user/AdminUser.html#AdminUser">AdminUser user = new AdminUser( );
665 user.setUserId( daoUtil.getInt( 1 ) );
666 user.setAccessCode( daoUtil.getString( 2 ) );
667 user.setLastName( daoUtil.getString( 3 ) );
668 user.setFirstName( daoUtil.getString( 4 ) );
669 user.setEmail( daoUtil.getString( 5 ) );
670 user.setStatus( daoUtil.getInt( 6 ) );
671 user.setLocale( new Locale( daoUtil.getString( 7 ) ) );
672 user.setAccessibilityMode( daoUtil.getBoolean( 8 ) );
673 user.setPasswordMaxValidDate( daoUtil.getTimestamp( 9 ) );
674 userList.add( user );
675 }
676
677 }
678
679 return userList;
680 }
681
682
683
684
685 @Override
686 public Collection<AdminUser> selectUsersByLevel( int nIdLevel )
687 {
688 Collection<AdminUser> userList = new ArrayList<>( );
689 try ( DAOUtil/DAOUtil.html#DAOUtil">DAOUtil daoUtil = new DAOUtil( SQL_QUERY_SELECT_USERS_BY_LEVEL ) )
690 {
691 daoUtil.setInt( 1, nIdLevel );
692 daoUtil.executeQuery( );
693
694 while ( daoUtil.next( ) )
695 {
696 AdminUserbusiness/user/AdminUser.html#AdminUser">AdminUser user = new AdminUser( );
697 user.setUserId( daoUtil.getInt( 1 ) );
698 user.setAccessCode( daoUtil.getString( 2 ) );
699 user.setLastName( daoUtil.getString( 3 ) );
700 user.setFirstName( daoUtil.getString( 4 ) );
701 user.setEmail( daoUtil.getString( 5 ) );
702 user.setStatus( daoUtil.getInt( 6 ) );
703 user.setLocale( new Locale( daoUtil.getString( 7 ) ) );
704 user.setAccessibilityMode( daoUtil.getBoolean( 8 ) );
705 userList.add( user );
706 }
707
708 }
709
710 return userList;
711 }
712
713
714
715
716
717
718
719
720
721
722
723
724 private Collection<String> selectIdRights( int nUserId, int nUserLevel, boolean bDelegated )
725 {
726 String strSqlQuery = bDelegated ? SQL_QUERY_SELECT_USER_RIGHTS_DELEGATED : SQL_QUERY_SELECT_USER_RIGHTS_OWN;
727 Collection<String> idRightList = new ArrayList<>( );
728 try ( DAOUtil/DAOUtil.html#DAOUtil">DAOUtil daoUtil = new DAOUtil( strSqlQuery ) )
729 {
730 daoUtil.setInt( 1, nUserId );
731 daoUtil.setInt( 2, nUserLevel );
732 daoUtil.executeQuery( );
733
734 while ( daoUtil.next( ) )
735 {
736 idRightList.add( daoUtil.getString( 1 ) );
737 }
738
739 }
740
741 return idRightList;
742 }
743
744
745
746
747
748
749
750
751
752 private void deleteRightsForUser( int nUserId, Collection<String> idRightList )
753 {
754 for ( String strIdRight : idRightList )
755 {
756 try ( DAOUtil/DAOUtil.html#DAOUtil">DAOUtil daoUtil = new DAOUtil( SQL_QUERY_DELETE_USER_RIGHTS ) )
757 {
758 daoUtil.setInt( 1, nUserId );
759 daoUtil.setString( 2, strIdRight );
760 daoUtil.executeUpdate( );
761 }
762 }
763 }
764
765
766
767
768 @Override
769 public void deleteAllOwnRightsForUser( int nUserId, int nUserLevel )
770 {
771 Collection<String> idRightList = selectIdRights( nUserId, nUserLevel, false );
772
773 deleteRightsForUser( nUserId, idRightList );
774 }
775
776
777
778
779 @Override
780 public void deleteAllDelegatedRightsForUser( int nUserId, int nUserLevel )
781 {
782 Collection<String> idRightList = selectIdRights( nUserId, nUserLevel, true );
783
784 deleteRightsForUser( nUserId, idRightList );
785 }
786
787
788
789
790 @Override
791 public void storeUsersRole( String strOldRoleKey, RBACRole role )
792 {
793 try ( DAOUtil/DAOUtil.html#DAOUtil">DAOUtil daoUtil = new DAOUtil( SQL_QUERY_UPDATE_USERS_ROLE ) )
794 {
795 daoUtil.setString( 1, role.getKey( ) );
796 daoUtil.setString( 2, strOldRoleKey );
797
798 daoUtil.executeUpdate( );
799 }
800 }
801
802
803
804
805 @Override
806 public boolean hasRole( int nUserId, String strRoleKey )
807 {
808 boolean bHasRole = false;
809 try ( DAOUtil/DAOUtil.html#DAOUtil">DAOUtil daoUtil = new DAOUtil( SQL_QUERY_SELECT_USER_ROLE ) )
810 {
811 daoUtil.setInt( 1, nUserId );
812 daoUtil.setString( 2, strRoleKey );
813 daoUtil.executeQuery( );
814
815 if ( daoUtil.next( ) )
816 {
817 bHasRole = true;
818 }
819
820 }
821
822 return bHasRole;
823 }
824
825
826
827
828 @Override
829 public void deleteRoleForUser( int nUserId, String strRoleKey )
830 {
831 try ( DAOUtil/DAOUtil.html#DAOUtil">DAOUtil daoUtil = new DAOUtil( SQL_QUERY_DELETE_ROLE_FOR_USER ) )
832 {
833 daoUtil.setInt( 1, nUserId );
834 daoUtil.setString( 2, strRoleKey );
835 daoUtil.executeUpdate( );
836 }
837 }
838
839
840
841
842 @Override
843 public Collection<AdminUser> selectUsersByFilter( AdminUserFilter auFilter )
844 {
845 Collection<AdminUser> userList = new ArrayList<>( );
846
847 String query = SQL_QUERY_SELECT_USER_FROM_SEARCH;
848
849 if ( auFilter.getStatus( ) != -1 )
850 {
851 query += CONSTANT_AND_STATUS;
852 }
853
854 if ( auFilter.getUserLevel( ) != -1 )
855 {
856 query += CONSTANT_AND_USER_LEVEL;
857 }
858
859 query += CONSTANT_ORDER_BY_LAST_NAME;
860
861 try ( DAOUtil/DAOUtil.html#DAOUtil">DAOUtil daoUtil = new DAOUtil( query ) )
862 {
863 int nIndex = 0;
864 daoUtil.setString( ++nIndex, CONSTANT_PERCENT + auFilter.getAccessCode( ) + CONSTANT_PERCENT );
865 daoUtil.setString( ++nIndex, CONSTANT_PERCENT + auFilter.getLastName( ) + CONSTANT_PERCENT );
866 daoUtil.setString( ++nIndex, CONSTANT_PERCENT + auFilter.getEmail( ) + CONSTANT_PERCENT );
867 daoUtil.setString( ++nIndex, CONSTANT_PERCENT + auFilter.getFirstName( ) + CONSTANT_PERCENT );
868
869 if ( auFilter.getStatus( ) != -1 )
870 {
871 daoUtil.setInt( ++nIndex, auFilter.getStatus( ) );
872 }
873
874 if ( auFilter.getUserLevel( ) != -1 )
875 {
876 daoUtil.setInt( ++nIndex, auFilter.getUserLevel( ) );
877 }
878
879 daoUtil.executeQuery( );
880
881 while ( daoUtil.next( ) )
882 {
883 AdminUserbusiness/user/AdminUser.html#AdminUser">AdminUser user = new AdminUser( );
884 user.setUserId( daoUtil.getInt( 1 ) );
885 user.setAccessCode( daoUtil.getString( 2 ) );
886 user.setLastName( daoUtil.getString( 3 ) );
887 user.setFirstName( daoUtil.getString( 4 ) );
888 user.setEmail( daoUtil.getString( 5 ) );
889 user.setStatus( daoUtil.getInt( 6 ) );
890 user.setLocale( new Locale( daoUtil.getString( 7 ) ) );
891 user.setUserLevel( daoUtil.getInt( 8 ) );
892 user.setAccessibilityMode( daoUtil.getBoolean( 9 ) );
893 userList.add( user );
894 }
895
896 }
897
898 return userList;
899 }
900
901
902
903
904 @Override
905 public Collection<AdminUser> selectUsersByRight( String strIdRight )
906 {
907 Collection<AdminUser> userList = new ArrayList<>( );
908 try ( DAOUtil/DAOUtil.html#DAOUtil">DAOUtil daoUtil = new DAOUtil( SQL_QUERY_SELECT_USERS_BY_RIGHT ) )
909 {
910 daoUtil.setString( 1, strIdRight );
911 daoUtil.executeQuery( );
912
913 while ( daoUtil.next( ) )
914 {
915 AdminUserbusiness/user/AdminUser.html#AdminUser">AdminUser user = new AdminUser( );
916 user.setUserId( daoUtil.getInt( 1 ) );
917 user.setAccessCode( daoUtil.getString( 2 ) );
918 user.setLastName( daoUtil.getString( 3 ) );
919 user.setFirstName( daoUtil.getString( 4 ) );
920 user.setEmail( daoUtil.getString( 5 ) );
921 user.setStatus( daoUtil.getInt( 6 ) );
922 user.setLocale( new Locale( daoUtil.getString( 7 ) ) );
923 user.setUserLevel( daoUtil.getInt( 8 ) );
924 user.setAccessibilityMode( daoUtil.getBoolean( 9 ) );
925 userList.add( user );
926 }
927
928 }
929
930 return userList;
931 }
932
933
934
935
936 @Override
937 public boolean hasRight( int nUserId, String strIdRight )
938 {
939 boolean bHasRight = false;
940 try ( DAOUtil/DAOUtil.html#DAOUtil">DAOUtil daoUtil = new DAOUtil( SQL_QUERY_SELECT_USER_RIGHT ) )
941 {
942 daoUtil.setInt( 1, nUserId );
943 daoUtil.setString( 2, strIdRight );
944 daoUtil.executeQuery( );
945
946 if ( daoUtil.next( ) )
947 {
948 bHasRight = true;
949 }
950
951 }
952
953 return bHasRight;
954 }
955
956
957
958
959 @Override
960 public void deleteRightForUser( int nUserId, String strIdRight )
961 {
962 try ( DAOUtil/DAOUtil.html#DAOUtil">DAOUtil daoUtil = new DAOUtil( SQL_QUERY_DELETE_USER_RIGHTS ) )
963 {
964 daoUtil.setInt( 1, nUserId );
965 daoUtil.setString( 2, strIdRight );
966 daoUtil.executeUpdate( );
967 }
968 }
969
970
971
972
973 @Override
974 public List<IPassword> selectUserPasswordHistory( int nUserID )
975 {
976 List<IPassword> listPasswordHistory = new ArrayList<>( );
977
978 try ( DAOUtil/DAOUtil.html#DAOUtil">DAOUtil daoUtil = new DAOUtil( SQL_SELECT_USER_PASSWORD_HISTORY ) )
979 {
980 daoUtil.setInt( 1, nUserID );
981 daoUtil.executeQuery( );
982
983 while ( daoUtil.next( ) )
984 {
985 listPasswordHistory.add( _passwordFactory.getPassword( daoUtil.getString( 1 ) ) );
986 }
987
988 }
989
990 return listPasswordHistory;
991 }
992
993
994
995
996 @Override
997 public int countUserPasswordHistoryFromDate( Timestamp minDate, int nUserId )
998 {
999 int nNbRes = 0;
1000
1001 try ( DAOUtil/DAOUtil.html#DAOUtil">DAOUtil daoUtil = new DAOUtil( SQL_COUNT_USER_PASSWORD_HISTORY ) )
1002 {
1003 daoUtil.setInt( 1, nUserId );
1004 daoUtil.setTimestamp( 2, minDate );
1005 daoUtil.executeQuery( );
1006
1007 if ( daoUtil.next( ) )
1008 {
1009 nNbRes = daoUtil.getInt( 1 );
1010 }
1011
1012 }
1013
1014 return nNbRes;
1015 }
1016
1017
1018
1019
1020 @Override
1021 public void insertNewPasswordInHistory( IPassword password, int nUserId )
1022 {
1023 try ( DAOUtil/DAOUtil.html#DAOUtil">DAOUtil daoUtil = new DAOUtil( SQL_INSERT_PASSWORD_HISTORY ) )
1024 {
1025 daoUtil.setInt( 1, nUserId );
1026 daoUtil.setString( 2, password.getStorableRepresentation( ) );
1027
1028 daoUtil.executeUpdate( );
1029 }
1030 }
1031
1032
1033
1034
1035 @Override
1036 public void removeAllPasswordHistoryForUser( int nUserId )
1037 {
1038 try ( DAOUtil/DAOUtil.html#DAOUtil">DAOUtil daoUtil = new DAOUtil( SQL_DELETE_PASSWORD_HISTORY ) )
1039 {
1040 daoUtil.setInt( 1, nUserId );
1041 daoUtil.executeUpdate( );
1042 }
1043 }
1044
1045
1046
1047
1048 @Override
1049 public Map<String, Boolean> selectAnonymizationStatusUserStaticField( )
1050 {
1051 Map<String, Boolean> resultMap = new HashMap<>( );
1052 try ( DAOUtil/DAOUtil.html#DAOUtil">DAOUtil daoUtil = new DAOUtil( SQL_SELECT_ANONYMIZATION_STATUS_USER_FILED ) )
1053 {
1054 daoUtil.executeQuery( );
1055
1056 while ( daoUtil.next( ) )
1057 {
1058 resultMap.put( daoUtil.getString( 1 ), daoUtil.getBoolean( 2 ) );
1059 }
1060
1061 }
1062
1063 return resultMap;
1064 }
1065
1066
1067
1068
1069 @Override
1070 public void updateAnonymizationStatusUserStaticField( String strFieldName, boolean bAnonymizeFiled )
1071 {
1072 try ( DAOUtil/DAOUtil.html#DAOUtil">DAOUtil daoUtil = new DAOUtil( SQL_UPDATE_ANONYMIZATION_STATUS_USER_FILED ) )
1073 {
1074 daoUtil.setBoolean( 1, bAnonymizeFiled );
1075 daoUtil.setString( 2, strFieldName );
1076 daoUtil.executeUpdate( );
1077 }
1078 }
1079
1080
1081
1082
1083 @Override
1084 public List<Integer> findAllExpiredUserId( )
1085 {
1086 List<Integer> listIdExpiredUser = new ArrayList<>( );
1087 try ( DAOUtil/DAOUtil.html#DAOUtil">DAOUtil daoUtil = new DAOUtil( SQL_QUERY_SELECT_EXPIRED_USER_ID ) )
1088 {
1089 daoUtil.setInt( 1, AdminUser.EXPIRED_CODE );
1090
1091 daoUtil.executeQuery( );
1092
1093 while ( daoUtil.next( ) )
1094 {
1095 listIdExpiredUser.add( daoUtil.getInt( 1 ) );
1096 }
1097
1098 }
1099
1100 return listIdExpiredUser;
1101 }
1102
1103
1104
1105
1106 @Override
1107 public List<Integer> getIdUsersWithExpiredLifeTimeList( Timestamp currentTimestamp )
1108 {
1109 List<Integer> listIdExpiredUser = new ArrayList<>( );
1110 try ( DAOUtil/DAOUtil.html#DAOUtil">DAOUtil daoUtil = new DAOUtil( SQL_QUERY_SELECT_EXPIRED_LIFE_TIME_USER_ID ) )
1111 {
1112 daoUtil.setLong( 1, currentTimestamp.getTime( ) );
1113 daoUtil.setInt( 2, AdminUser.EXPIRED_CODE );
1114
1115 daoUtil.executeQuery( );
1116
1117 while ( daoUtil.next( ) )
1118 {
1119 listIdExpiredUser.add( daoUtil.getInt( 1 ) );
1120 }
1121
1122 }
1123
1124 return listIdExpiredUser;
1125 }
1126
1127
1128
1129
1130 @Override
1131 public List<Integer> getIdUsersToSendFirstAlert( Timestamp alertMaxDate )
1132 {
1133 List<Integer> listIdUserFirstAlert = new ArrayList<>( );
1134 try ( DAOUtil/DAOUtil.html#DAOUtil">DAOUtil daoUtil = new DAOUtil( SQL_QUERY_SELECT_USER_ID_FIRST_ALERT ) )
1135 {
1136 daoUtil.setInt( 1, AdminUser.EXPIRED_CODE );
1137 daoUtil.setLong( 2, alertMaxDate.getTime( ) );
1138
1139 daoUtil.executeQuery( );
1140
1141 while ( daoUtil.next( ) )
1142 {
1143 listIdUserFirstAlert.add( daoUtil.getInt( 1 ) );
1144 }
1145
1146 }
1147
1148 return listIdUserFirstAlert;
1149 }
1150
1151
1152
1153
1154 @Override
1155 public List<Integer> getIdUsersToSendOtherAlert( Timestamp alertMaxDate, Timestamp timeBetweenAlerts, int maxNumberAlerts )
1156 {
1157 List<Integer> listIdUserFirstAlert = new ArrayList<>( );
1158 try ( DAOUtil/DAOUtil.html#DAOUtil">DAOUtil daoUtil = new DAOUtil( SQL_QUERY_SELECT_USER_ID_OTHER_ALERT ) )
1159 {
1160 daoUtil.setInt( 1, maxNumberAlerts );
1161 daoUtil.setInt( 2, AdminUser.EXPIRED_CODE );
1162 daoUtil.setLong( 3, timeBetweenAlerts.getTime( ) );
1163 daoUtil.setLong( 4, alertMaxDate.getTime( ) );
1164
1165 daoUtil.executeQuery( );
1166
1167 while ( daoUtil.next( ) )
1168 {
1169 listIdUserFirstAlert.add( daoUtil.getInt( 1 ) );
1170 }
1171
1172 }
1173
1174 return listIdUserFirstAlert;
1175 }
1176
1177
1178
1179
1180 @Override
1181 public List<Integer> getIdUsersWithExpiredPasswordsList( Timestamp currentTimestamp )
1182 {
1183 List<Integer> idUserPasswordExpiredlist = new ArrayList<>( );
1184 try ( DAOUtil/DAOUtil.html#DAOUtil">DAOUtil daoUtil = new DAOUtil( SQL_QUERY_SELECT_USER_ID_PASSWORD_EXPIRED ) )
1185 {
1186 daoUtil.setTimestamp( 1, currentTimestamp );
1187
1188 daoUtil.executeQuery( );
1189
1190 while ( daoUtil.next( ) )
1191 {
1192 idUserPasswordExpiredlist.add( daoUtil.getInt( 1 ) );
1193 }
1194
1195 }
1196
1197 return idUserPasswordExpiredlist;
1198 }
1199
1200
1201
1202
1203 @Override
1204 public void updateUserStatus( List<Integer> listIdUser, int nNewStatus )
1205 {
1206 if ( CollectionUtils.isNotEmpty( listIdUser ) )
1207 {
1208 StringBuilder sbSQL = new StringBuilder( );
1209 sbSQL.append( SQL_QUERY_UPDATE_STATUS );
1210
1211 for ( int i = 0; i < listIdUser.size( ); i++ )
1212 {
1213 if ( i > 0 )
1214 {
1215 sbSQL.append( CONSTANT_COMMA );
1216 }
1217
1218 sbSQL.append( listIdUser.get( i ) );
1219 }
1220
1221 sbSQL.append( CONSTANT_CLOSE_PARENTHESIS );
1222
1223 try ( DAOUtil/DAOUtil.html#DAOUtil">DAOUtil daoUtil = new DAOUtil( sbSQL.toString( ) ) )
1224 {
1225 daoUtil.setInt( 1, nNewStatus );
1226 daoUtil.executeUpdate( );
1227 }
1228 }
1229 }
1230
1231
1232
1233
1234 @Override
1235 public void updateNbAlert( List<Integer> listIdUser )
1236 {
1237 if ( CollectionUtils.isNotEmpty( listIdUser ) )
1238 {
1239 StringBuilder sbSQL = new StringBuilder( );
1240 sbSQL.append( SQL_QUERY_UPDATE_NB_ALERT );
1241
1242 for ( int i = 0; i < listIdUser.size( ); i++ )
1243 {
1244 if ( i > 0 )
1245 {
1246 sbSQL.append( CONSTANT_COMMA );
1247 }
1248
1249 sbSQL.append( listIdUser.get( i ) );
1250 }
1251
1252 sbSQL.append( CONSTANT_CLOSE_PARENTHESIS );
1253
1254 try ( DAOUtil/DAOUtil.html#DAOUtil">DAOUtil daoUtil = new DAOUtil( sbSQL.toString( ) ) )
1255 {
1256 daoUtil.executeUpdate( );
1257 }
1258 }
1259 }
1260
1261
1262
1263
1264 @Override
1265 public void updateChangePassword( List<Integer> listIdUser )
1266 {
1267 if ( CollectionUtils.isNotEmpty( listIdUser ) )
1268 {
1269 StringBuilder sbSQL = new StringBuilder( );
1270 sbSQL.append( SQL_QUERY_UPDATE_RESET_PASSWORD_LIST_ID );
1271
1272 for ( int i = 0; i < listIdUser.size( ); i++ )
1273 {
1274 if ( i > 0 )
1275 {
1276 sbSQL.append( CONSTANT_COMMA );
1277 }
1278
1279 sbSQL.append( listIdUser.get( i ) );
1280 }
1281
1282 sbSQL.append( CONSTANT_CLOSE_PARENTHESIS );
1283
1284 try ( DAOUtil/DAOUtil.html#DAOUtil">DAOUtil daoUtil = new DAOUtil( sbSQL.toString( ) ) )
1285 {
1286 daoUtil.executeUpdate( );
1287 }
1288 }
1289 }
1290
1291
1292
1293
1294 @Override
1295 public void updateUserExpirationDate( int nIdUser, Timestamp newExpirationDate )
1296 {
1297 try ( DAOUtil/DAOUtil.html#DAOUtil">DAOUtil daoUtil = new DAOUtil( SQL_QUERY_UPDATE_REACTIVATE_ACCOUNT ) )
1298 {
1299
1300 if ( newExpirationDate == null )
1301 {
1302 daoUtil.setLongNull( 1 );
1303 }
1304 else
1305 {
1306 daoUtil.setLong( 1, newExpirationDate.getTime( ) );
1307 }
1308
1309 daoUtil.setInt( 2, nIdUser );
1310
1311 daoUtil.executeUpdate( );
1312 }
1313 }
1314
1315
1316
1317
1318 @Override
1319 public void updateDateLastLogin( int nIdUser, Timestamp dateLastLogin )
1320 {
1321 try ( DAOUtil/DAOUtil.html#DAOUtil">DAOUtil daoUtil = new DAOUtil( SQL_QUERY_UPDATE_DATE_LAST_LOGIN ) )
1322 {
1323 daoUtil.setTimestamp( 1, dateLastLogin );
1324 daoUtil.setInt( 2, nIdUser );
1325 daoUtil.executeUpdate( );
1326 }
1327 }
1328 }