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.api.user.User;
37 import fr.paris.lutece.api.user.UserRole;
38 import fr.paris.lutece.portal.business.rbac.RBACRole;
39 import fr.paris.lutece.portal.business.right.Right;
40 import fr.paris.lutece.portal.business.user.attribute.IAttribute;
41 import fr.paris.lutece.portal.business.user.authentication.AdminAuthentication;
42 import fr.paris.lutece.portal.business.user.parameter.EmailPatternRegularExpressionRemovalListener;
43 import fr.paris.lutece.portal.service.regularexpression.RegularExpressionRemovalListenerService;
44 import fr.paris.lutece.portal.service.workgroup.AdminWorkgroupResource;
45 import fr.paris.lutece.portal.web.l10n.LocaleService;
46
47 import org.apache.commons.lang3.StringUtils;
48
49 import java.io.Serializable;
50
51 import java.sql.Timestamp;
52 import java.util.ArrayList;
53 import java.util.HashMap;
54 import java.util.List;
55 import java.util.Locale;
56 import java.util.Map;
57
58 import javax.validation.constraints.NotNull;
59
60
61
62
63 public class AdminUser implements Serializable, AdminWorkgroupResource, User
64 {
65 public static final String RESOURCE_TYPE = "ADMIN_USER";
66
67 public static final String USER_REALM = "BACK_OFFICE_USER";
68 public static final int ACTIVE_CODE = 0;
69 public static final int NOT_ACTIVE_CODE = 1;
70 public static final int EXPIRED_CODE = 5;
71 public static final int ANONYMIZED_CODE = 10;
72 private static final Timestamp DEFAULT_DATE_LAST_LOGIN = Timestamp.valueOf( "1980-01-01 00:00:00" );
73 private static final long serialVersionUID = 7533831976351347197L;
74 private static EmailPatternRegularExpressionRemovalListener _listenerRegularExpression;
75 private int _nUserId;
76 private String _strAccessCode;
77 private String _strLastName;
78 private String _strFirstName;
79 private String _strEmail;
80 private int _nStatus;
81 private int _nUserLevel;
82 private boolean _bIsPasswordReset;
83 private boolean _bAccessibilityMode;
84 private Timestamp _passwordMaxValidDate;
85 private Timestamp _accountMaxValidDate;
86 private Timestamp _dateLastLogin;
87 private String _strWorkgroupKey;
88 private HashMap<String, Object> _userInfo = new HashMap<>( );
89
90 private List<String> _workgroups = new ArrayList<String>( );
91
92
93
94
95 private HashMap<String, Right> _rights = new HashMap<>( );
96
97
98
99
100 private HashMap<String, UserRole> _roles = new HashMap<>( );
101
102
103 private String _strAuthenticationService;
104
105
106 private String _strAuthenticationType;
107
108
109 private Locale _locale;
110
111
112
113
114 public AdminUser( )
115 {
116 }
117
118
119
120
121
122
123
124
125
126 public AdminUser( String stAccessCode, AdminAuthentication authenticationService )
127 {
128 _strAccessCode = stAccessCode;
129 _strAuthenticationService = authenticationService.getAuthServiceName( );
130 }
131
132
133
134
135 public static synchronized void init( )
136 {
137 if ( _listenerRegularExpression == null )
138 {
139 _listenerRegularExpression = new EmailPatternRegularExpressionRemovalListener( );
140 RegularExpressionRemovalListenerService.getService( ).registerListener( _listenerRegularExpression );
141 }
142 }
143
144
145
146
147
148
149 @NotNull
150 public Locale getLocale( )
151 {
152 return ( _locale == null ) ? LocaleService.getDefault( ) : _locale;
153 }
154
155
156
157
158
159
160
161 public void setLocale( Locale locale )
162 {
163 _locale = locale;
164 }
165
166
167
168
169
170
171 public int getUserId( )
172 {
173 return _nUserId;
174 }
175
176
177
178
179
180
181
182 public void setUserId( int nUserId )
183 {
184 _nUserId = nUserId;
185 }
186
187
188
189
190
191 public int getStatus( )
192 {
193 switch( _nStatus )
194 {
195 case ACTIVE_CODE:
196 case ANONYMIZED_CODE:
197 case NOT_ACTIVE_CODE:
198 return _nStatus;
199
200 case EXPIRED_CODE:
201 return ANONYMIZED_CODE;
202
203 default:
204 return ACTIVE_CODE;
205 }
206 }
207
208
209
210
211 public int getRealStatus( )
212 {
213 return _nStatus;
214 }
215
216
217
218
219
220 public void setStatus( int nStatus )
221 {
222 _nStatus = nStatus;
223 }
224
225
226
227
228
229
230 public boolean isStatusActive( )
231 {
232 return ( _nStatus == ACTIVE_CODE );
233 }
234
235
236
237
238
239
240 public boolean isStatusAnonymized( )
241 {
242 return ( _nStatus == ANONYMIZED_CODE );
243 }
244
245
246
247
248
249
250 @Override
251 public String getLastName( )
252 {
253 return _strLastName;
254 }
255
256
257
258
259
260
261
262 public void setLastName( String strLastName )
263 {
264 _strLastName = ( strLastName == null ) ? StringUtils.EMPTY : strLastName;
265 }
266
267
268
269
270
271
272 @Override
273 public String getFirstName( )
274 {
275 return _strFirstName;
276 }
277
278
279
280
281
282
283
284 public void setFirstName( String strFirstName )
285 {
286 _strFirstName = ( strFirstName == null ) ? StringUtils.EMPTY : strFirstName;
287 }
288
289
290
291
292
293
294 @Override
295 public String getEmail( )
296 {
297 return _strEmail;
298 }
299
300
301
302
303
304
305
306 public void setEmail( String strEmail )
307 {
308 _strEmail = ( strEmail == null ) ? StringUtils.EMPTY : strEmail;
309 }
310
311
312
313
314 @Override
315 public String getAccessCode( )
316 {
317 return _strAccessCode;
318 }
319
320
321
322
323
324 public void setAccessCode( String strAccessCode )
325 {
326 _strAccessCode = strAccessCode;
327 }
328
329
330
331
332
333
334 public Timestamp getPasswordMaxValidDate( )
335 {
336 return _passwordMaxValidDate;
337 }
338
339
340
341
342
343
344
345 public void setPasswordMaxValidDate( Timestamp passwordMaxValidDate )
346 {
347 _passwordMaxValidDate = passwordMaxValidDate;
348 }
349
350
351
352
353
354
355 public Timestamp getAccountMaxValidDate( )
356 {
357 return _accountMaxValidDate;
358 }
359
360
361
362
363
364
365
366 public void setAccountMaxValidDate( Timestamp accountMaxValidDate )
367 {
368 _accountMaxValidDate = accountMaxValidDate;
369 }
370
371
372
373
374
375
376
377 @Deprecated
378 public Map<String, UserRole> getRoles( )
379 {
380 return _roles;
381 }
382
383
384
385
386 @Override
387 public Map<String, UserRole> getUserRoles( )
388 {
389 return _roles;
390 }
391
392
393
394
395
396
397
398 public void addRoles( Map<String, RBACRole> roles )
399 {
400 _roles.putAll( roles );
401 }
402
403
404
405
406
407
408
409 public void setRoles( Map<String, RBACRole> roles )
410 {
411 _roles.clear( );
412 _roles.putAll( roles );
413 }
414
415
416
417
418
419
420 public Map<String, Right> getRights( )
421 {
422 return _rights;
423 }
424
425
426
427
428
429
430
431
432 public boolean checkRight( String strRightCode )
433 {
434 return _rights.containsKey( strRightCode );
435 }
436
437
438
439
440
441
442
443 public void setRights( Map<String, Right> rights )
444 {
445 _rights.clear( );
446 _rights.putAll( rights );
447 }
448
449
450
451
452
453
454
455 public void updateRight( Right rightToUpdate )
456 {
457 for ( Right right : _rights.values( ) )
458 {
459 if ( right.getId( ).equals( rightToUpdate.getId( ) ) )
460 {
461 _rights.put( right.getId( ), rightToUpdate );
462 }
463 }
464 }
465
466
467
468
469
470
471
472
473
474
475 public void setAuthenticationService( String strAuthenticationService )
476 {
477 _strAuthenticationService = strAuthenticationService;
478 }
479
480
481
482
483
484
485 public String getAuthenticationService( )
486 {
487 return _strAuthenticationService;
488 }
489
490
491
492
493
494
495
496 public void setAuthenticationType( String strAuthenticationType )
497 {
498 _strAuthenticationType = strAuthenticationType;
499 }
500
501
502
503
504
505
506 public String getAuthenticationType( )
507 {
508 return _strAuthenticationType;
509 }
510
511
512
513
514
515
516
517 public void setUserLevel( int nUserLevel )
518 {
519 _nUserLevel = nUserLevel;
520 }
521
522
523
524
525
526
527 public int getUserLevel( )
528 {
529 return _nUserLevel;
530 }
531
532
533
534
535
536
537
538
539 public boolean isParent( AdminUser user )
540 {
541 return _nUserLevel < user.getUserLevel( );
542 }
543
544
545
546
547
548
549
550
551 public boolean hasRights( int level )
552 {
553 return _nUserLevel < level;
554 }
555
556
557
558
559
560
561 public boolean isAdmin( )
562 {
563 return _nUserLevel == 0;
564 }
565
566
567
568
569
570
571
572
573 public boolean isInRole( String strRole )
574 {
575
576
577 Map<String, RBACRole> roles = AdminUserHome.getRolesListForUser( getUserId( ) );
578
579 return roles.containsKey( strRole );
580 }
581
582
583
584
585
586
587 public boolean isPasswordReset( )
588 {
589 return _bIsPasswordReset;
590 }
591
592
593
594
595
596
597
598 public void setPasswordReset( boolean bIsPasswordReset )
599 {
600 _bIsPasswordReset = bIsPasswordReset;
601 }
602
603
604
605
606
607
608
609 public void setAccessibilityMode( boolean bAccessibilityMode )
610 {
611 _bAccessibilityMode = bAccessibilityMode;
612 }
613
614
615
616
617
618
619 public boolean getAccessibilityMode( )
620 {
621 return _bAccessibilityMode;
622 }
623
624
625
626
627
628
629 public Timestamp getDateLastLogin( )
630 {
631 return _dateLastLogin;
632 }
633
634
635
636
637
638
639
640 public void setDateLastLogin( Timestamp dateLastLogin )
641 {
642 _dateLastLogin = dateLastLogin;
643 }
644
645
646
647
648 public String getWorkgroupKey( )
649 {
650 return _strWorkgroupKey;
651 }
652
653
654
655
656
657 public void setWorkgroupKey( String strWorkgroupKey )
658 {
659 this._strWorkgroupKey = strWorkgroupKey;
660 }
661
662 @Override
663 public String getWorkgroup( )
664 {
665 return getWorkgroupKey( );
666 }
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684 public <X extends Object> X setUserInfo( String strKey, X info )
685 {
686 return (X) _userInfo.put( strKey, info );
687 }
688
689
690
691
692
693
694
695
696
697
698
699
700 public <X extends Object> X getUserInfo( String strKey )
701 {
702 return (X) _userInfo.get( strKey );
703 }
704
705 public static Timestamp getDefaultDateLastLogin( )
706 {
707 return new Timestamp( DEFAULT_DATE_LAST_LOGIN.getTime( ) );
708 }
709
710
711
712
713 @Override
714 public List<String> getUserWorkgroups( )
715 {
716 return _workgroups;
717 }
718
719
720
721
722
723
724
725 public void setUserWorkgroups( List<String> workgroups )
726 {
727 this._workgroups = workgroups;
728 }
729
730
731
732
733 @Override
734 public String getRealm( )
735 {
736 return USER_REALM;
737 }
738
739 }