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 org.apache.commons.lang.ObjectUtils;
37
38 import java.io.Serializable;
39
40 import java.security.Principal;
41
42 import java.sql.Timestamp;
43
44 import java.util.Collection;
45 import java.util.HashMap;
46 import java.util.Map;
47
48
49
50
51
52 public abstract class LuteceUser implements Principal, Serializable, Cloneable
53 {
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 public static final Timestamp DEFAULT_DATE_LAST_LOGIN = Timestamp.valueOf( "1980-01-01 00:00:00" );
137 private static final long serialVersionUID = -8733640540563208835L;
138
139
140 private Map<String, String> _mapUserInfo = new HashMap<String, String>( );
141
142
143 private String _strUserName;
144
145
146 private String[] _roles;
147
148
149 private String[] _groups;
150
151
152 private String _strAuthenticationService;
153
154
155 private LuteceAuthentication _luteceAuthenticationService;
156
157
158 private String _strAuthenticationType;
159
160
161
162
163
164
165 public LuteceUser( String strUserName, LuteceAuthentication authenticationService )
166 {
167 _strUserName = strUserName;
168 _strAuthenticationService = authenticationService.getAuthServiceName( );
169 _luteceAuthenticationService = authenticationService;
170 }
171
172
173
174
175
176 public final Map<String, String> getUserInfos( )
177 {
178 return _mapUserInfo;
179 }
180
181
182
183
184
185
186 public final void setUserInfo( String key, String value )
187 {
188 _mapUserInfo.put( key, value );
189 }
190
191
192
193
194
195
196 public final String getUserInfo( String key )
197 {
198 String strInfo = _mapUserInfo.get( key );
199
200 return ( strInfo == null ) ? "" : strInfo;
201 }
202
203
204
205
206
207
208
209
210
211 @Override
212 public boolean equals( Object object )
213 {
214
215 return ObjectUtils.equals( this.toString( ), ObjectUtils.toString( object ) );
216 }
217
218
219
220
221
222 @Override
223 public String toString( )
224 {
225 return _strUserName;
226 }
227
228
229
230
231
232 @Override
233 public int hashCode( )
234 {
235 return ( _strUserName == null ) ? 0 : _strUserName.hashCode( );
236 }
237
238
239
240
241
242 @Override
243 public String getName( )
244 {
245 return _strUserName;
246 }
247
248
249
250
251
252
253
254
255 public void setName( String strName )
256 {
257 _strUserName = strName;
258 }
259
260
261
262
263
264 public String[] getRoles( )
265 {
266 return _roles;
267 }
268
269
270
271
272
273 public void addRoles( Collection<String> roles )
274 {
275 _roles = addInArray( _roles, roles );
276 }
277
278
279
280
281
282 public void setRoles( Collection<String> roles )
283 {
284 _roles = getArray( roles );
285 }
286
287
288
289
290
291 public String[] getGroups( )
292 {
293 return _groups;
294 }
295
296
297
298
299
300 public void addGroups( Collection<String> groups )
301 {
302 _groups = addInArray( _groups, groups );
303 }
304
305
306
307
308
309 public void setGroups( Collection<String> groups )
310 {
311 _groups = getArray( groups );
312 }
313
314
315
316
317
318
319
320
321 private String[] addInArray( String[] array, Collection<String> collection )
322 {
323 String[] newArray;
324
325 int j = 0;
326
327 if ( array == null )
328 {
329 newArray = new String[collection.size( )];
330 }
331 else
332 {
333 newArray = new String[collection.size( ) + array.length];
334
335 for ( j = 0; j < array.length; j++ )
336 {
337 newArray[j] = array[j];
338 }
339 }
340
341 for ( String strItem : collection )
342 {
343 newArray[j++] = strItem;
344 }
345
346 return newArray;
347 }
348
349
350
351
352
353
354
355 private String[] getArray( Collection<String> collection )
356 {
357 String[] newArray = new String[collection.size( )];
358
359 int j = 0;
360
361 for ( String strItem : collection )
362 {
363 newArray[j++] = strItem;
364 }
365
366 return newArray;
367 }
368
369
370
371
372
373
374
375
376 public void setAuthenticationService( String strAuthenticationService )
377 {
378 _strAuthenticationService = strAuthenticationService;
379 }
380
381
382
383
384
385 public String getAuthenticationService( )
386 {
387 return _strAuthenticationService;
388 }
389
390
391
392
393
394 public void setAuthenticationType( String strAuthenticationType )
395 {
396 _strAuthenticationType = strAuthenticationType;
397 }
398
399
400
401
402
403 public String getAuthenticationType( )
404 {
405 return _strAuthenticationType;
406 }
407
408
409
410
411
412 public LuteceAuthentication getLuteceAuthenticationService( )
413 {
414 return _luteceAuthenticationService;
415 }
416
417
418
419
420
421 public void setLuteceAuthenticationService( LuteceAuthentication authenticationService )
422 {
423 _luteceAuthenticationService = authenticationService;
424 }
425
426
427
428
429 @Override
430 public Object clone( ) throws CloneNotSupportedException
431 {
432 return super.clone( );
433 }
434
435
436
437
438
439 public String getEmail( )
440 {
441 return null;
442 }
443 }