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