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.service.security;
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 java.io.Serializable;
40 import java.security.Principal;
41 import java.util.ArrayList;
42 import java.util.Arrays;
43 import java.util.Collection;
44 import java.util.HashMap;
45 import java.util.List;
46 import java.util.Map;
47
48 import org.apache.commons.lang3.ObjectUtils;
49
50
51
52
53 public abstract class LuteceUser implements Principal, Serializable, Cloneable, User
54 {
55
56
57
58
59 public static final String BDATE = "user.bdate";
60 public static final String GENDER = "user.gender";
61 public static final String EMPLOYER = "user.employer";
62 public static final String DEPARTMENT = "user.department";
63 public static final String JOBTITLE = "user.jobtitle";
64 public static final String PREFIX = "user.name.prefix";
65 public static final String DATE_LAST_LOGIN = "user.lastLogin";
66 public static final String NAME_GIVEN = "user.name.given";
67 public static final String NAME_FAMILY = "user.name.family";
68 public static final String NAME_MIDDLE = "user.name.middle";
69 public static final String NAME_SUFFIX = "user.name.suffix";
70 public static final String NAME_NICKNAME = "user.name.nickName";
71 public static final String NAME_CIVILITY = "user.name.civility";
72 public static final String HOME_INFO_POSTAL_NAME = "user.home-info.postal.name";
73 public static final String HOME_INFO_POSTAL_STREET = "user.home-info.postal.street";
74 public static final String HOME_INFO_POSTAL_STREET_NUMBER = "user.home-info.postal.street.number";
75 public static final String HOME_INFO_POSTAL_STREET_SUFFIX = "user.home-info.postal.street.suffix";
76 public static final String HOME_INFO_POSTAL_STREET_NAME = "user.home-info.postal.street.name";
77 public static final String HOME_INFO_POSTAL_STREET_TYPE = "user.home-info.postal.street.type";
78 public static final String HOME_INFO_POSTAL_STREET_URBAN_DISTRICT = "user.home-info.postal.street.urbandistrict";
79 public static final String HOME_INFO_POSTAL_CITY = "user.home-info.postal.city";
80 public static final String HOME_INFO_POSTAL_STATEPROV = "user.home-info.postal.stateprov";
81 public static final String HOME_INFO_POSTAL_POSTALCODE = "user.home-info.postal.postalcode";
82 public static final String HOME_INFO_POSTAL_COUNTRY = "user.home-info.postal.country";
83 public static final String HOME_INFO_POSTAL_ORGANIZATION = "user.home-info.postal.organization";
84 public static final String HOME_INFO_TELECOM_TELEPHONE_INTCODE = "user.home-info.telecom.telephone.intcode";
85 public static final String HOME_INFO_TELECOM_TELEPHONE_LOCCODE = "user.home-info.telecom.telephone.loccode";
86 public static final String HOME_INFO_TELECOM_TELEPHONE_NUMBER = "user.home-info.telecom.telephone.number";
87 public static final String HOME_INFO_TELECOM_TELEPHONE_EXT = "user.home-info.telecom.telephone.ext";
88 public static final String HOME_INFO_TELECOM_TELEPHONE_COMMENT = "user.home-info.telecom.telephone.comment";
89 public static final String HOME_INFO_TELECOM_FAX_INT = "user.home-info.telecom.fax.intcode";
90 public static final String HOME_INFO_TELECOM_FAX_LOCCODE = "user.home-info.telecom.fax.loccode";
91 public static final String HOME_INFO_TELECOM_FAX_NUMBER = "user.home-info.telecom.fax.number";
92 public static final String HOME_INFO_TELECOM_FAX_EXT = "user.home-info.telecom.fax.ext";
93 public static final String HOME_INFO_TELECOM_FAX_COMMENT = "user.home-info.telecom.fax.comment";
94 public static final String HOME_INFO_TELECOM_MOBILE_INTCODE = "user.home-info.telecom.mobile.intcode";
95 public static final String HOME_INFO_TELECOM_MOBILE_LOCCODE = "user.home-info.telecom.mobile.loccode";
96 public static final String HOME_INFO_TELECOM_MOBILE_NUMBER = "user.home-info.telecom.mobile.number";
97 public static final String HOME_INFO_TELECOM_MOBILE_EXT = "user.home-info.telecom.mobile.ext";
98 public static final String HOME_INFO_TELECOM_MOBILE_COMMENT = "user.home-info.telecom.mobile.comment";
99 public static final String HOME_INFO_TELECOM_PAGER_INTCODE = "user.home-info.telecom.pager.intcode";
100 public static final String HOME_INFO_TELECOM_PAGER_LOCCODE = "user.home-info.telecom.pager.loccode";
101 public static final String HOME_INFO_TELECOM_PAGER_NUMBER = "user.home-info.telecom.pager.number";
102 public static final String HOME_INFO_TELECOM_PAGER_EXT = "user.home-info.telecom.pager.ext";
103 public static final String HOME_INFO_TELECOM_PAGER_COMMENT = "user.home-info.telecom.pager.comment";
104 public static final String HOME_INFO_ONLINE_EMAIL = "user.home-info.online.email";
105 public static final String HOME_INFO_ONLINE_URI = "user.home-info.online.uri";
106 public static final String BUSINESS_INFO_POSTAL_NAME = "user.business-info.postal.name";
107 public static final String BUSINESS_INFO_POSTAL_STREET = "user.business-info.postal.street";
108 public static final String BUSINESS_INFO_POSTAL_CITY = "user.business-info.postal.city";
109 public static final String BUSINESS_INFO_POSTAL_STATEPROV = "user.business-info.postal.stateprov";
110 public static final String BUSINESS_INFO_POSTAL_POSTALCODE = "user.business-info.postal.postalcode";
111 public static final String BUSINESS_INFO_POSTAL_COUNTRY = "user.business-info.postal.country";
112 public static final String BUSINESS_INFO_POSTAL_ORGANIZATION = "user.business-info.postal.organization";
113 public static final String BUSINESS_INFO_TELECOM_TELEPHONE_INTCODE = "user.business-info.telecom.telephone.intcode";
114 public static final String BUSINESS_INFO_TELECOM_TELEPHONE_LOCCODE = "user.business-info.telecom.telephone.loccode";
115 public static final String BUSINESS_INFO_TELECOM_TELEPHONE_NUMBER = "user.business-info.telecom.telephone.number";
116 public static final String BUSINESS_INFO_TELECOM_TELEPHONE_EXT = "user.business-info.telecom.telephone.ext";
117 public static final String BUSINESS_INFO_TELECOM_TELEPHONE_COMMENT = "user.business-info.telecom.telephone.comment";
118 public static final String BUSINESS_INFO_TELECOM_FAX_INTCODE = "user.business-info.telecom.fax.intcode";
119 public static final String BUSINESS_INFO_TELECOM_FAX_LOCCODE = "user.business-info.telecom.fax.loccode";
120 public static final String BUSINESS_INFO_TELECOM_FAX_NUMBER = "user.business-info.telecom.fax.number";
121 public static final String BUSINESS_INFO_TELECOM_FAX_EXT = "user.business-info.telecom.fax.ext";
122 public static final String BUSINESS_INFO_TELECOM_FAX_COMMENT = "user.business-info.telecom.fax.comment";
123 public static final String BUSINESS_INFO_TELECOM_MOBILE_INTCODE = "user.business-info.telecom.mobile.intcode";
124 public static final String BUSINESS_INFO_TELECOM_MOBILE_LOCCODE = "user.business-info.telecom.mobile.loccode";
125 public static final String BUSINESS_INFO_TELECOM_MOBILE_NUMBER = "user.business-info.telecom.mobile.number";
126 public static final String BUSINESS_INFO_TELECOM_MOBILE_EXT = "user.business-info.telecom.mobile.ext";
127 public static final String BUSINESS_INFO_TELECOM_MOBILE_COMMENT = "user.business-info.telecom.mobile.comment";
128 public static final String BUSINESS_INFO_TELECOM_PAGER_INTCODE = "user.business-info.telecom.pager.intcode";
129 public static final String BUSINESS_INFO_TELECOM_PAGER_LOCCODE = "user.business-info.telecom.pager.loccode";
130 public static final String BUSINESS_INFO_TELECOM_PAGER_NUMBER = "user.business-info.telecom.pager.number";
131 public static final String BUSINESS_INFO_TELECOM_PAGER_EXT = "user.business-info.telecom.pager.ext";
132 public static final String BUSINESS_INFO_TELECOM_PAGER_COMMENT = "user.business-info.telecom.pager.comment";
133 public static final String BUSINESS_INFO_ONLINE_EMAIL = "user.business-info.online.email";
134 public static final String BUSINESS_INFO_ONLINE_URI = "user.business-info.online.uri";
135 public static final String ANONYMOUS_USERNAME = "GUEST";
136
137 public static final String USER_REALM = "FRONT_OFFICE_USER";
138 private static final long serialVersionUID = -8733640540563208835L;
139
140
141 private Map<String, String> _mapUserInfo = new HashMap<>( );
142
143
144 private String _strUserName;
145
146
147 private String [ ] _roles;
148
149
150 private String [ ] _groups;
151
152
153 private String _strAuthenticationService;
154
155
156 private LuteceAuthentication _luteceAuthenticationService;
157
158
159 private String _strAuthenticationType;
160
161 private List<String> _workgroups = new ArrayList<String>( );
162
163
164
165
166
167
168
169
170
171 public LuteceUser( String strUserName, LuteceAuthentication authenticationService )
172 {
173 _strUserName = strUserName;
174 _strAuthenticationService = authenticationService.getAuthServiceName( );
175 _luteceAuthenticationService = authenticationService;
176 }
177
178
179
180
181
182
183 public final Map<String, String> getUserInfos( )
184 {
185 return _mapUserInfo;
186 }
187
188
189
190
191
192
193
194
195
196 public final void setUserInfo( String key, String value )
197 {
198 _mapUserInfo.put( key, value );
199 }
200
201
202
203
204
205
206
207
208
209 public final String getUserInfo( String key )
210 {
211 String strInfo = _mapUserInfo.get( key );
212 return ( strInfo == null ) ? "" : strInfo;
213 }
214
215
216
217
218
219
220
221
222
223
224
225 @Override
226 public boolean equals( Object object )
227 {
228
229 return ObjectUtils.equals( this.toString( ), ObjectUtils.toString( object ) );
230 }
231
232
233
234
235
236
237 @Override
238 public String toString( )
239 {
240 return _strUserName;
241 }
242
243
244
245
246
247
248 @Override
249 public int hashCode( )
250 {
251 return ( _strUserName == null ) ? 0 : _strUserName.hashCode( );
252 }
253
254
255
256
257
258
259 @Override
260 public String getName( )
261 {
262 return _strUserName;
263 }
264
265
266
267
268
269
270
271
272
273
274 public void setName( String strName )
275 {
276 _strUserName = strName;
277 }
278
279
280
281
282
283
284 public String [ ] getRoles( )
285 {
286 return _roles;
287 }
288
289
290
291
292 @Override
293 public Map<String, UserRole> getUserRoles( )
294 {
295 Map<String, UserRole> mapRoles = new HashMap<>( );
296 for ( String strRole : _roles )
297 {
298 mapRoles.put( strRole, new RBACRole( strRole, strRole ) );
299 }
300 return mapRoles;
301 }
302
303
304
305
306
307
308
309 public void addRoles( Collection<String> roles )
310 {
311 _roles = addInArray( _roles, roles );
312 }
313
314
315
316
317
318
319
320 public void setRoles( Collection<String> roles )
321 {
322 _roles = getArray( roles );
323 }
324
325
326
327
328
329
330 public String [ ] getGroups( )
331 {
332 return _groups;
333 }
334
335
336
337
338
339
340
341 public void addGroups( Collection<String> groups )
342 {
343 _groups = addInArray( _groups, groups );
344 }
345
346
347
348
349
350
351
352 public void setGroups( Collection<String> groups )
353 {
354 _groups = getArray( groups );
355 }
356
357
358
359
360
361
362
363
364
365
366 private String [ ] addInArray( String [ ] array, Collection<String> collection )
367 {
368 String [ ] newArray;
369
370 int j = 0;
371
372 if ( array == null )
373 {
374 newArray = new String [ collection.size( )];
375 }
376 else
377 {
378 newArray = Arrays.copyOf( array, collection.size( ) + array.length );
379 j= array.length;
380 }
381
382 for ( String strItem : collection )
383 {
384 newArray [j++] = strItem;
385 }
386
387 return newArray;
388 }
389
390
391
392
393
394
395
396
397 private String [ ] getArray( Collection<String> collection )
398 {
399 String [ ] newArray = new String [ collection.size( )];
400
401 int j = 0;
402
403 for ( String strItem : collection )
404 {
405 newArray [j++] = strItem;
406 }
407
408 return newArray;
409 }
410
411
412
413
414
415
416
417
418
419
420 public void setAuthenticationService( String strAuthenticationService )
421 {
422 _strAuthenticationService = strAuthenticationService;
423 }
424
425
426
427
428
429
430 public String getAuthenticationService( )
431 {
432 return _strAuthenticationService;
433 }
434
435
436
437
438
439
440
441 public void setAuthenticationType( String strAuthenticationType )
442 {
443 _strAuthenticationType = strAuthenticationType;
444 }
445
446
447
448
449
450
451 public String getAuthenticationType( )
452 {
453 return _strAuthenticationType;
454 }
455
456
457
458
459
460
461 public LuteceAuthentication getLuteceAuthenticationService( )
462 {
463 return _luteceAuthenticationService;
464 }
465
466
467
468
469
470
471
472 public void setLuteceAuthenticationService( LuteceAuthentication authenticationService )
473 {
474 _luteceAuthenticationService = authenticationService;
475 }
476
477
478
479
480 @Override
481 public Object clone( ) throws CloneNotSupportedException
482 {
483 return super.clone( );
484 }
485
486
487
488
489
490
491 @Override
492 public String getEmail( )
493 {
494 return null;
495 }
496
497
498
499
500 @Override
501 public String getAccessCode( )
502 {
503 return getName( );
504 }
505
506
507
508
509 @Override
510 public String getLastName( )
511 {
512 return this.getUserInfo( LuteceUser.NAME_FAMILY );
513 }
514
515
516
517
518 public @Override String getFirstName( )
519 {
520 return this.getUserInfo( LuteceUser.NAME_GIVEN );
521
522 }
523
524
525
526
527 @Override
528 public List<String> getUserWorkgroups( )
529 {
530 return _workgroups;
531 }
532
533
534
535
536 @Override
537 public String getRealm( )
538 {
539 return USER_REALM;
540 }
541 }