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.portal.service.spring.SpringContextService;
40 import fr.paris.lutece.portal.service.util.CryptoService;
41 import fr.paris.lutece.util.password.IPassword;
42
43 import java.sql.Timestamp;
44
45 import java.util.Collection;
46 import java.util.Date;
47 import java.util.List;
48 import java.util.Map;
49
50
51
52
53 public final class AdminUserHome
54 {
55
56 private static IAdminUserDAO _dao = SpringContextService.getBean( "adminUserDAO" );
57
58
59
60
61 private AdminUserHome( )
62 {
63 }
64
65
66
67
68
69
70
71
72 public static AdminUser findUserByLogin( String strUserLogin )
73 {
74 return _dao.selectUserByAccessCode( strUserLogin );
75 }
76
77
78
79
80
81
82
83
84
85 public static <T extends AdminUser> T findUserByLogin( String strUserLogin,T user )
86 {
87 return _dao.selectUserByAccessCode( strUserLogin ,user);
88 }
89
90
91
92
93
94
95
96
97
98 public static String findUserByEmail( String strEmail )
99 {
100 return _dao.selectUserByEmail( strEmail );
101 }
102
103
104
105
106
107
108
109
110 public static AdminUser findByPrimaryKey( int nUserId )
111 {
112 return _dao.load( nUserId );
113 }
114
115
116
117
118 public static Collection<AdminUser> findUserList( )
119 {
120 return _dao.selectUserList( );
121 }
122
123
124
125
126
127 public static void create( AdminUser user )
128 {
129 _dao.insert( user );
130 }
131
132
133
134
135
136 public static void update( AdminUser user )
137 {
138 _dao.store( user );
139 }
140
141
142
143
144
145 public static void remove( int nUserId )
146 {
147 _dao.delete( nUserId );
148 }
149
150
151
152
153
154
155
156
157 public static Map<String, Right> getRightsListForUser( int nUserId )
158 {
159 return _dao.selectRightsListForUser( nUserId );
160 }
161
162
163
164
165
166
167
168 public static void createRightForUser( int nUserId, String strRightId )
169 {
170 _dao.insertRightsListForUser( nUserId, strRightId );
171 }
172
173
174
175
176
177 public static void removeAllRightsForUser( int nUserId )
178 {
179 _dao.deleteAllRightsForUser( nUserId );
180 }
181
182
183
184
185
186 public static void removeAllDelegatedRightsForUser( AdminUser user )
187 {
188 _dao.deleteAllDelegatedRightsForUser( user.getUserId( ), user.getUserLevel( ) );
189 }
190
191
192
193
194
195 public static void removeAllOwnRightsForUser( AdminUser user )
196 {
197 _dao.deleteAllOwnRightsForUser( user.getUserId( ), user.getUserLevel( ) );
198 }
199
200
201
202
203
204
205
206
207 public static Map<String, RBACRole> getRolesListForUser( int nUserId )
208 {
209 return _dao.selectRolesListForUser( nUserId );
210 }
211
212
213
214
215
216
217
218 public static void createRoleForUser( int nUserId, String strRightId )
219 {
220 _dao.insertRolesListForUser( nUserId, strRightId );
221 }
222
223
224
225
226
227 public static void removeAllRolesForUser( int nUserId )
228 {
229 _dao.deleteAllRolesForUser( nUserId );
230 }
231
232
233
234
235
236
237
238
239 public static boolean checkRoleAttributed( String strRoleKey )
240 {
241 return _dao.checkRoleAttributed( strRoleKey );
242 }
243
244
245
246
247
248
249
250
251 public static int checkAccessCodeAlreadyInUse( String strAccessCode )
252 {
253 return _dao.checkAccessCodeAlreadyInUse( strAccessCode );
254 }
255
256
257
258
259
260
261
262
263 public static int checkEmailAlreadyInUse( String strEmail )
264 {
265 return _dao.checkEmailAlreadyInUse( strEmail );
266 }
267
268
269
270
271
272
273
274
275
276
277 public static boolean hasRole( AdminUser user, String strRoleKey )
278 {
279 return _dao.hasRole( user.getUserId( ), strRoleKey );
280 }
281
282
283
284
285
286
287
288
289
290 public static void removeRoleForUser( int nUserId, String strRoleKey )
291 {
292 _dao.deleteRoleForUser( nUserId, strRoleKey );
293 }
294
295
296
297
298
299
300
301
302 public static void create( LuteceDefaultAdminUser user )
303 {
304 _dao.insert( user );
305 }
306
307
308
309
310
311 public static void update( LuteceDefaultAdminUser user )
312 {
313 update( user, PasswordUpdateMode.UPDATE );
314 }
315
316
317
318
319
320
321
322 public static void update( LuteceDefaultAdminUser user, PasswordUpdateMode passwordMode )
323 {
324 _dao.store( user, passwordMode );
325 }
326
327
328
329
330
331
332
333
334 public static LuteceDefaultAdminUser findLuteceDefaultAdminUserByPrimaryKey( int nUserId )
335 {
336 return _dao.loadDefaultAdminUser( nUserId );
337 }
338
339
340
341
342
343
344
345
346 public static Collection<AdminUser> findByRole( String strRoleKey )
347 {
348 return _dao.selectUsersByRole( strRoleKey );
349 }
350
351
352
353
354
355
356
357
358 public static Collection<AdminUser> findByLevel( int nIdLevel )
359 {
360 return _dao.selectUsersByLevel( nIdLevel );
361 }
362
363
364
365
366
367
368
369
370
371 public static void updateUsersRole( String strOldRoleKey, RBACRole role )
372 {
373 _dao.storeUsersRole( strOldRoleKey, role );
374 }
375
376
377
378
379
380
381
382
383 public static Collection<AdminUser> findUserByFilter( AdminUserFilter auFilter )
384 {
385 return _dao.selectUsersByFilter( auFilter );
386 }
387
388
389
390
391
392
393
394
395 public static Collection<AdminUser> findByRight( String strIdRight )
396 {
397 return _dao.selectUsersByRight( strIdRight );
398 }
399
400
401
402
403
404
405
406
407
408
409 public static boolean hasRight( AdminUser user, String strIdRight )
410 {
411 return _dao.hasRight( user.getUserId( ), strIdRight );
412 }
413
414
415
416
417
418
419
420
421
422 public static void removeRightForUser( int nUserId, String strIdRight )
423 {
424 _dao.deleteRightForUser( nUserId, strIdRight );
425 }
426
427
428
429
430
431
432
433
434 public static List<IPassword> selectUserPasswordHistory( int nUserID )
435 {
436 return _dao.selectUserPasswordHistory( nUserID );
437 }
438
439
440
441
442
443
444
445
446
447
448 public static int countUserPasswordHistoryFromDate( Timestamp minDate, int nUserId )
449 {
450 return _dao.countUserPasswordHistoryFromDate( minDate, nUserId );
451 }
452
453
454
455
456
457
458
459
460
461 public static void insertNewPasswordInHistory( IPassword password, int nUserId )
462 {
463 _dao.insertNewPasswordInHistory( password, nUserId );
464 }
465
466
467
468
469
470
471
472 public static void removeAllPasswordHistoryForUser( int nUserId )
473 {
474 _dao.removeAllPasswordHistoryForUser( nUserId );
475 }
476
477
478
479
480
481
482 public static Map<String, Boolean> getAnonymizationStatusUserStaticField( )
483 {
484 return _dao.selectAnonymizationStatusUserStaticField( );
485 }
486
487
488
489
490
491
492
493
494
495 public static void updateAnonymizationStatusUserStaticField( String strFieldName, boolean bAnonymizeFiled )
496 {
497 _dao.updateAnonymizationStatusUserStaticField( strFieldName, bAnonymizeFiled );
498 }
499
500
501
502
503
504
505 public static List<Integer> findAllExpiredUserId( )
506 {
507 return _dao.findAllExpiredUserId( );
508 }
509
510
511
512
513
514
515
516
517 public static List<Integer> getIdUsersWithExpiredLifeTimeList( Timestamp currentTimestamp )
518 {
519 return _dao.getIdUsersWithExpiredLifeTimeList( currentTimestamp );
520 }
521
522
523
524
525
526
527
528
529 public static List<Integer> getIdUsersToSendFirstAlert( Timestamp firstAlertMaxDate )
530 {
531 return _dao.getIdUsersToSendFirstAlert( firstAlertMaxDate );
532 }
533
534
535
536
537
538
539
540
541
542
543
544
545 public static List<Integer> getIdUsersToSendOtherAlert( Timestamp alertMaxDate, Timestamp timeBetweenAlerts, int maxNumberAlerts )
546 {
547 return _dao.getIdUsersToSendOtherAlert( alertMaxDate, timeBetweenAlerts, maxNumberAlerts );
548 }
549
550
551
552
553
554
555
556
557 public static List<Integer> getIdUsersWithExpiredPasswordsList( Timestamp currentTimestamp )
558 {
559 return _dao.getIdUsersWithExpiredPasswordsList( currentTimestamp );
560 }
561
562
563
564
565
566
567
568
569
570 public static void updateUserStatus( List<Integer> listIdUser, int nNewStatus )
571 {
572 _dao.updateUserStatus( listIdUser, nNewStatus );
573 }
574
575
576
577
578
579
580
581 public static void updateNbAlert( List<Integer> listIdUser )
582 {
583 _dao.updateNbAlert( listIdUser );
584 }
585
586
587
588
589
590
591
592 public static void updateChangePassword( List<Integer> listIdUser )
593 {
594 _dao.updateChangePassword( listIdUser );
595 }
596
597
598
599
600
601
602
603
604
605 public static void updateUserExpirationDate( int nIdUser, Timestamp newExpirationDate )
606 {
607 _dao.updateUserExpirationDate( nIdUser, newExpirationDate );
608 }
609
610
611
612
613
614
615
616
617
618 public static void updateDateLastLogin( int nIdUser, Timestamp dateLastLogin )
619 {
620 _dao.updateDateLastLogin( nIdUser, dateLastLogin );
621 }
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636 public static String getUserPasswordResetToken( int nIdUser, Date timestamp, String strSessionId )
637 {
638 LuteceDefaultAdminUser user = _dao.loadDefaultAdminUser( nIdUser );
639 StringBuilder builder = new StringBuilder( );
640 builder.append( "userId:" ).append( nIdUser );
641 IPassword password = user.getPassword( );
642 if ( password != null )
643 {
644 builder.append( ":password:" );
645 if ( password.isLegacy( ) )
646 {
647 builder.append( "legacy" );
648 }
649 else
650 {
651 builder.append( password.getStorableRepresentation( ) );
652 }
653 }
654 builder.append( ":timestamp:" ).append( timestamp.getTime( ) );
655 if ( strSessionId != null )
656 {
657 builder.append( ":sessionId:" ).append( strSessionId );
658 }
659 return CryptoService.hmacSHA256( builder.toString( ) );
660 }
661 }