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.AdminRole;
37 import fr.paris.lutece.portal.business.right.Right;
38 import fr.paris.lutece.portal.business.user.authentication.AdminAuthentication;
39 import fr.paris.lutece.portal.business.user.parameter.EmailPatternRegularExpressionRemovalListener;
40 import fr.paris.lutece.portal.service.regularexpression.RegularExpressionRemovalListenerService;
41 import fr.paris.lutece.portal.service.workgroup.AdminWorkgroupResource;
42 import fr.paris.lutece.portal.web.l10n.LocaleService;
43
44 import org.apache.commons.lang.StringUtils;
45
46 import java.io.Serializable;
47
48 import java.sql.Timestamp;
49
50 import java.util.HashMap;
51 import java.util.Locale;
52 import java.util.Map;
53
54
55
56
57
58 public class AdminUser implements Serializable, AdminWorkgroupResource
59 {
60 public static final String RESOURCE_TYPE = "ADMIN_USER";
61 public static final int ACTIVE_CODE = 0;
62 public static final int NOT_ACTIVE_CODE = 1;
63 public static final int EXPIRED_CODE = 5;
64 public static final int ANONYMIZED_CODE = 10;
65 public static final Timestamp DEFAULT_DATE_LAST_LOGIN = Timestamp.valueOf( "1980-01-01 00:00:00" );
66 private static final long serialVersionUID = 7533831976351347197L;
67 private static EmailPatternRegularExpressionRemovalListener _listenerRegularExpression;
68 private int _nUserId;
69 private String _strAccessCode;
70 private String _strLastName;
71 private String _strFirstName;
72 private String _strEmail;
73 private int _nStatus;
74 private int _nUserLevel;
75 private boolean _bIsPasswordReset;
76 private boolean _bAccessibilityMode;
77 private Timestamp _passwordMaxValidDate;
78 private Timestamp _accountMaxValidDate;
79 private Timestamp _dateLastLogin;
80 private String _strWorkgroupKey;
81
82
83
84
85
86 private HashMap<String, Right> _rights = new HashMap<String, Right>( );
87
88
89
90
91
92 private HashMap<String, AdminRole> _roles = new HashMap<String, AdminRole>( );
93
94
95 private String _strAuthenticationService;
96
97
98 private String _strAuthenticationType;
99
100
101 private Locale _locale;
102
103
104
105
106 public AdminUser( )
107 {
108 }
109
110
111
112
113
114
115 public AdminUser( String stAccessCode, AdminAuthentication authenticationService )
116 {
117 _strAccessCode = stAccessCode;
118 _strAuthenticationService = authenticationService.getAuthServiceName( );
119 }
120
121
122
123
124 public static synchronized void init( )
125 {
126 if ( _listenerRegularExpression == null )
127 {
128 _listenerRegularExpression = new EmailPatternRegularExpressionRemovalListener( );
129 RegularExpressionRemovalListenerService.getService( ).registerListener( _listenerRegularExpression );
130 }
131 }
132
133
134
135
136
137 public Locale getLocale( )
138 {
139 return ( _locale == null ) ? LocaleService.getDefault( ) : _locale;
140 }
141
142
143
144
145
146 public void setLocale( Locale locale )
147 {
148 _locale = locale;
149 }
150
151
152
153
154
155 public int getUserId( )
156 {
157 return _nUserId;
158 }
159
160
161
162
163
164 public void setUserId( int nUserId )
165 {
166 _nUserId = nUserId;
167 }
168
169
170
171
172
173
174 public int getStatus( )
175 {
176 switch ( _nStatus )
177 {
178 case ACTIVE_CODE:
179 case ANONYMIZED_CODE:
180 case NOT_ACTIVE_CODE:
181 return _nStatus;
182
183 case EXPIRED_CODE:
184 return ANONYMIZED_CODE;
185
186 default:
187 return ACTIVE_CODE;
188 }
189 }
190
191
192
193
194 public int getRealStatus( )
195 {
196 return _nStatus;
197 }
198
199
200
201
202 public void setStatus( int nStatus )
203 {
204 _nStatus = nStatus;
205 }
206
207
208
209
210
211 public boolean isStatusActive( )
212 {
213 return ( _nStatus == ACTIVE_CODE );
214 }
215
216
217
218
219
220 public boolean isStatusAnonymized( )
221 {
222 return ( _nStatus == ANONYMIZED_CODE );
223 }
224
225
226
227
228
229
230 public String getLastName( )
231 {
232 return _strLastName;
233 }
234
235
236
237
238
239
240 public void setLastName( String strLastName )
241 {
242 _strLastName = ( strLastName == null ) ? StringUtils.EMPTY : strLastName;
243 }
244
245
246
247
248
249
250 public String getFirstName( )
251 {
252 return _strFirstName;
253 }
254
255
256
257
258
259
260 public void setFirstName( String strFirstName )
261 {
262 _strFirstName = ( strFirstName == null ) ? StringUtils.EMPTY : strFirstName;
263 }
264
265
266
267
268
269
270 public String getEmail( )
271 {
272 return _strEmail;
273 }
274
275
276
277
278
279
280 public void setEmail( String strEmail )
281 {
282 _strEmail = ( strEmail == null ) ? StringUtils.EMPTY : strEmail;
283 }
284
285
286
287
288 public String getAccessCode( )
289 {
290 return _strAccessCode;
291 }
292
293
294
295
296 public void setAccessCode( String strAccessCode )
297 {
298 _strAccessCode = strAccessCode;
299 }
300
301
302
303
304
305 public Timestamp getPasswordMaxValidDate( )
306 {
307 return _passwordMaxValidDate;
308 }
309
310
311
312
313
314
315 public void setPasswordMaxValidDate( Timestamp passwordMaxValidDate )
316 {
317 _passwordMaxValidDate = passwordMaxValidDate;
318 }
319
320
321
322
323
324
325 public Timestamp getAccountMaxValidDate( )
326 {
327 return _accountMaxValidDate;
328 }
329
330
331
332
333
334 public void setAccountMaxValidDate( Timestamp accountMaxValidDate )
335 {
336 _accountMaxValidDate = accountMaxValidDate;
337 }
338
339
340
341
342
343 public Map<String, AdminRole> getRoles( )
344 {
345 return _roles;
346 }
347
348
349
350
351
352 public void addRoles( Map<String, AdminRole> roles )
353 {
354 _roles.putAll( roles );
355 }
356
357
358
359
360
361 public void setRoles( Map<String, AdminRole> roles )
362 {
363 _roles.clear( );
364 _roles.putAll( roles );
365 }
366
367
368
369
370
371 public Map<String, Right> getRights( )
372 {
373 return _rights;
374 }
375
376
377
378
379
380
381
382 public boolean checkRight( String strRightCode )
383 {
384 return _rights.containsKey( strRightCode );
385 }
386
387
388
389
390
391 public void setRights( Map<String, Right> rights )
392 {
393 _rights.clear( );
394 _rights.putAll( rights );
395 }
396
397
398
399
400
401
402
403
404 public void setAuthenticationService( String strAuthenticationService )
405 {
406 _strAuthenticationService = strAuthenticationService;
407 }
408
409
410
411
412
413 public String getAuthenticationService( )
414 {
415 return _strAuthenticationService;
416 }
417
418
419
420
421
422 public void setAuthenticationType( String strAuthenticationType )
423 {
424 _strAuthenticationType = strAuthenticationType;
425 }
426
427
428
429
430
431 public String getAuthenticationType( )
432 {
433 return _strAuthenticationType;
434 }
435
436
437
438
439
440 public void setUserLevel( int nUserLevel )
441 {
442 _nUserLevel = nUserLevel;
443 }
444
445
446
447
448
449 public int getUserLevel( )
450 {
451 return _nUserLevel;
452 }
453
454
455
456
457
458
459 public boolean isParent( AdminUser user )
460 {
461 return _nUserLevel < user.getUserLevel( );
462 }
463
464
465
466
467
468
469 public boolean hasRights( int level )
470 {
471 return _nUserLevel < level;
472 }
473
474
475
476
477
478 public boolean isAdmin( )
479 {
480 return _nUserLevel == 0;
481 }
482
483
484
485
486
487
488 public boolean isInRole( String strRole )
489 {
490
491
492 Map<String, AdminRole> roles = AdminUserHome.getRolesListForUser( getUserId( ) );
493
494 return roles.containsKey( strRole );
495 }
496
497
498
499
500
501 public boolean isPasswordReset( )
502 {
503 return _bIsPasswordReset;
504 }
505
506
507
508
509
510
511 public void setPasswordReset( boolean bIsPasswordReset )
512 {
513 _bIsPasswordReset = bIsPasswordReset;
514 }
515
516
517
518
519
520 public void setAccessibilityMode( boolean bAccessibilityMode )
521 {
522 _bAccessibilityMode = bAccessibilityMode;
523 }
524
525
526
527
528
529 public boolean getAccessibilityMode( )
530 {
531 return _bAccessibilityMode;
532 }
533
534
535
536
537
538 public Timestamp getDateLastLogin( )
539 {
540 return _dateLastLogin;
541 }
542
543
544
545
546
547 public void setDateLastLogin( Timestamp dateLastLogin )
548 {
549 _dateLastLogin = dateLastLogin;
550 }
551
552
553
554
555 public String getWorkgroupKey( )
556 {
557 return _strWorkgroupKey;
558 }
559
560
561
562
563 public void setWorkgroupKey( String strWorkgroupKey )
564 {
565 this._strWorkgroupKey = strWorkgroupKey;
566 }
567
568 @Override
569 public String getWorkgroup( )
570 {
571 return _strWorkgroupKey;
572 }
573 }