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.plugins.mydashboard.modules.identity.web;
35
36 import java.util.Arrays;
37 import java.util.Map;
38
39 import javax.servlet.http.HttpServletRequest;
40
41 import org.apache.commons.lang3.StringUtils;
42 import org.apache.commons.validator.routines.EmailValidator;
43
44 import fr.paris.lutece.plugins.avatar.service.AvatarService;
45 import fr.paris.lutece.plugins.identitystore.v3.web.rs.dto.common.IdentityDto;
46 import fr.paris.lutece.plugins.identitystore.v3.web.rs.dto.contract.ServiceContractSearchResponse;
47 import fr.paris.lutece.plugins.identitystore.v3.web.service.IdentityService;
48 import fr.paris.lutece.plugins.mydashboard.modules.identity.business.DashboardIdentity;
49 import fr.paris.lutece.plugins.mydashboard.modules.identity.service.DashboardIdentityService;
50 import fr.paris.lutece.plugins.mydashboard.modules.identity.util.Constants;
51 import fr.paris.lutece.plugins.mydashboard.modules.identity.util.DashboardIdentityUtils;
52 import fr.paris.lutece.plugins.verifybackurl.service.AuthorizedUrlService;
53 import fr.paris.lutece.portal.service.admin.AccessDeniedException;
54 import fr.paris.lutece.portal.service.datastore.DatastoreService;
55 import fr.paris.lutece.portal.service.i18n.I18nService;
56 import fr.paris.lutece.portal.service.security.ISecurityTokenService;
57 import fr.paris.lutece.portal.service.security.LuteceUser;
58 import fr.paris.lutece.portal.service.security.SecurityService;
59 import fr.paris.lutece.portal.service.security.SecurityTokenService;
60 import fr.paris.lutece.portal.service.security.UserNotSignedException;
61 import fr.paris.lutece.portal.service.site.properties.SitePropertiesGroup;
62 import fr.paris.lutece.portal.service.spring.SpringContextService;
63 import fr.paris.lutece.portal.service.util.AppException;
64 import fr.paris.lutece.portal.service.util.AppLogService;
65 import fr.paris.lutece.portal.service.util.AppPathService;
66 import fr.paris.lutece.portal.service.util.AppPropertiesService;
67 import fr.paris.lutece.portal.util.mvc.commons.annotations.Action;
68 import fr.paris.lutece.portal.util.mvc.commons.annotations.View;
69 import fr.paris.lutece.portal.util.mvc.xpage.MVCApplication;
70 import fr.paris.lutece.portal.util.mvc.xpage.annotations.Controller;
71 import fr.paris.lutece.portal.web.xpages.XPage;
72 import fr.paris.lutece.util.ReferenceItem;
73 import fr.paris.lutece.util.ReferenceList;
74
75
76
77
78 @Controller( xpageName = "mydashboardIdentity", pageTitleI18nKey = "module.mydashboard.identity.xpage.getIdentity.pageTitle", pagePathI18nKey = "module.mydashboard.identity.xpage.getIdentity.pagePath" )
79 public class IdentityXPage extends MVCApplication
80 {
81 private static final long serialVersionUID = 1L;
82 private static final String VIEW_GET_VIEW_IDENTITY = "getViewIdentity";
83 private static final String VIEW_GET_MODIFY_IDENTITY = "getModifyIdentity";
84 private static final String VIEW_GET_CHECK_IDENTITY = "getCheckIdentity";
85
86 private static final String ACTION_DO_MODIFY_IDENTITY = "doModifyIdentity";
87 private static final String ACTION_DO_CHECK_IDENTITY = "doCheckIdentity";
88 private static final String ACTION_DO_COMPLETE_SUSPICIOUS_IDENTITY = "doCompleteIdentity";
89
90 private static final String PARAMETER_BACK = "back";
91 private static final String PARAMETER_APP_CODE = "app_code";
92 private static final String PARAMETER_ORIGIN_ACTION = "origin";
93
94 private static final String MARK_IDENTITY = "identity";
95 private static final String MARK_VIEW_MODE = "viewMode";
96 private static final String MARK_AVATAR_URL = "avatar_url";
97 private static final String MARK_AVATARSERVER_POST_URL = "avatarserver_post_url";
98 private static final String MARK_MYDASHBOARD_SITE_PROPERTIES = "mydashboard_site_properties";
99 private static final String BEAN_MYDASHBOARD_IDENTITY_SITE_PROPERTIES = "mydashboard-identity.sitePropertiesGroup";
100 private static final String MARK_SERVICE_URL = "service_url";
101 private static final String MARK_SERVICE_NAME = "service_name";
102 private static final String MARK_MANDATORY_INFORMATIONS_SAVED = "mandatory_informations_saved";
103 private static final String MARK_NEED_CERTIFICATION_FC = "needCertificationFC";
104 private static final String MARK_NEED_LOGIN_CERTIFICATION = "needLoginCertification";
105 private static final String MARK_NEED_EMAIL_CERTIFICATION = "needEmailCertification";
106
107 private static final String TEMPLATE_GET_VIEW_MODIFY_IDENTITY = "skin/plugins/mydashboard/modules/identity/edit_identity.html";
108 private static final String TEMPLATE_GET_VIEW_CHECK_IDENTITY = "skin/plugins/mydashboard/modules/identity/check_identity.html";
109 private static final String TEMPLATE_SUSPICIOUS_COMPLETE_IDENTITY = "skin/plugins/mydashboard/modules/identity/suspiciousIdentity/view_complete_identity.html";
110 private static final String TEMPLATE_GET_VIEW_ERROR = "skin/plugins/mydashboard/modules/identity/view_error.html";
111
112 private static final String MARK_GENDER_LIST = "genderlist";
113 private static final String MARK_CONTACT_MODE_LIST = "contact_modeList";
114 private static final String MARK_ORIGIN_ACTION = "origin";
115 private static final String MARK_NS_NAME = "numericServiceName";
116 private static final String MARK_TOKEN = "token";
117
118 private static final String BEAN_IDENTITYSTORE_SERVICE = "mydashboard-identity.identitystore.service";
119 private static final String SPLIT_PATTERN = ";";
120 private static final String PROPERTY_AVATERSERVER_POST_URL = "mydashboard.identity.avatarserver.post.url";
121 private static final String AVATARSERVER_POST_URL = AppPropertiesService.getProperty( PROPERTY_AVATERSERVER_POST_URL );
122
123 private static final String ROLE_MYDASHBOARD_CS_REQUIREMENTS_FULLFILLED = "mydashboard.identity.roleMydashboardCsRequirementsFullFilled";
124 private static final String APP_CODE_SERVICE_CONTRACT_MON_PARIS = "mydashboard.identity.appCodeServiceContractMonParis";
125
126
127 private static final String VIEW_VALIDATE_LAST_NAME = "validate_lastName";
128 private static final String VIEW_VALIDATE_PREFERRED_USERNAME = "validate_preferredUsername";
129 private static final String VIEW_VALIDATE_FISRTNAME = "validate_firstname";
130 private static final String VIEW_VALIDATE_BIRTHDATE = "validate_birthdate";
131 private static final String VIEW_VALIDATE_BIRTHPLACE = "validate_birthplace";
132 private static final String VIEW_VALIDATE_BIRTHCOUNTRY = "validate_birthcountry";
133 private static final String VIEW_VALIDATE_ADDRESS = "validate_address";
134 private static final String VIEW_VALIDATE_ADDRESS_DETAIL = "validate_addressdetail";
135 private static final String VIEW_VALIDATE_ADDRESS_POSTALCODE = "validate_addressPostalcode";
136 private static final String VIEW_VALIDATE_ADDRESS_CITY = "validate_addressCity";
137 private static final String VIEW_VALIDATE_EMAIL = "validate_email";
138 private static final String VIEW_VALIDATE_PHONE = "validate_phone";
139 private static final String VIEW_VALIDATE_MOBILEPHONE = "validate_mobilephone";
140 private static final String VIEW_SUSPICION_IDENTITY_COMPLETION = "completeIdentity";
141
142
143 private static final String PROPERTY_REDIRECT_MODIFY_ACCOUNT_PAGE = AppPropertiesService.getProperty( "mydashboard.identity.suspicious.modify_account.redirect.page" );
144 private static final String PROPERTY_REDIRECT_MODIFY_ACCOUNT_VIEW = AppPropertiesService.getProperty( "mydashboard.identity.suspicious.modify_account.redirect.view" );
145 private static final String PROPERTY_REDIRECT_COMPLETION_ACCOUNT_VIEW = AppPropertiesService.getProperty( "mydashboard.identity.suspicious.completion_account.redirect.view" );
146 private static final String PROPERTY_COMPLETION_ATTRIBUTES_NEED_FC = AppPropertiesService.getProperty( "mydashboard.identity.completion_attributes_need_certification" );
147 private static final String PROPERTY_IDENTITYSTORE_EMAIL_CERTIFIER_CODE = AppPropertiesService.getProperty( "myluteceusergu.identitystore.emailcertifier.code", "emailcertifier");
148 private static final String PROPERTY_FC_CERTIFIER_CODE = AppPropertiesService.getProperty( "myluteceusergu.identitystore.fccertifier.code", "fccertifier" );
149 private static final String PROPERTY_REDIRECT_URL_CERTIFY_EMAIL = AppPropertiesService.getProperty( "mydashboard.identity.completion.certify_email");
150 private static final int PROPERTY_IDENTITYSTORE_EMAIL_LEVEL_MIN = AppPropertiesService.getPropertyInt( "mydashboard.identity.emailcertifier.level_min", 200);
151
152 private ReferenceList _lstContactModeList;
153 private ReferenceList _lstGenderList;
154
155
156 private DashboardIdentity _dashboardIdentity;
157 private DashboardIdentity _checkdIdentity;
158 private DashboardIdentity _completionIdentity;
159 private String _strAppCode;
160 private boolean _bMandatoryInformationsSaved;
161
162 private IdentityService _identityService;
163 private boolean _bReInitAppCode = false;
164 private String _originActionCompletion;
165 private ISecurityTokenService _securityTokenService = SecurityTokenService.getInstance( );
166
167
168
169
170 public IdentityXPage( )
171 {
172 super( );
173 _identityService = SpringContextService.getBean( BEAN_IDENTITYSTORE_SERVICE );
174
175 _lstGenderList = new ReferenceList( );
176
177 int i = 0;
178
179 for ( String sItem : Constants.PROPERTY_KEY_GENDER_LIST.split( SPLIT_PATTERN ) )
180 {
181 ReferenceItem refItm = new ReferenceItem( );
182 refItm.setName( sItem );
183 refItm.setCode( String.valueOf( i ) );
184 _lstGenderList.add( refItm );
185 i++;
186 }
187
188 _lstContactModeList = new ReferenceList( );
189
190 for ( String sItem : Constants.PROPERTY_KEY_CONTACT_MODE_LIST.split( SPLIT_PATTERN ) )
191 {
192 ReferenceItem refItm = new ReferenceItem( );
193 refItm.setName( sItem );
194 refItm.setCode( sItem );
195 _lstContactModeList.add( refItm );
196 }
197 }
198
199
200
201
202
203
204
205
206
207
208 @View( value = VIEW_GET_VIEW_IDENTITY, defaultView = true )
209 public XPage getViewIdentity( HttpServletRequest request ) throws UserNotSignedException
210 {
211 LuteceUser luteceUser = getConnectedUser( request );
212
213 String strAppCode = request.getParameter( PARAMETER_APP_CODE );
214
215 if ( _strAppCode == null || strAppCode != null && !strAppCode.equals( _strAppCode ) )
216 {
217 _bReInitAppCode = true;
218 _strAppCode = strAppCode;
219 }
220
221 SitePropertiesGroup dashboardPropertiesGroup = ( SitePropertiesGroup ) SpringContextService.getBean( BEAN_MYDASHBOARD_IDENTITY_SITE_PROPERTIES );
222 String strMyDashboardPropertiesPrefix = dashboardPropertiesGroup.getDatastoreKeysPrefix( );
223
224 Map<String, Object> model = getModel( );
225 IdentityDto identity = DashboardIdentityUtils.getInstance( ).getIdentity( luteceUser.getName( ) );
226 _dashboardIdentity = DashboardIdentityUtils.getInstance( ).convertToDashboardIdentity( identity );
227
228 model.put( MARK_MYDASHBOARD_SITE_PROPERTIES, DatastoreService.getDataByPrefix( strMyDashboardPropertiesPrefix ).toMap( ) );
229 model.put( MARK_IDENTITY, _dashboardIdentity );
230 model.put( MARK_VIEW_MODE, Boolean.TRUE );
231 model.put( MARK_CONTACT_MODE_LIST, _lstContactModeList );
232 model.put( MARK_GENDER_LIST, _lstGenderList );
233 model.put( MARK_AVATAR_URL, getAvatarUrl( request ) );
234 model.put( MARK_TOKEN, _securityTokenService.getToken( request, ACTION_DO_MODIFY_IDENTITY ) );
235
236
237 String strBackUrl = AuthorizedUrlService.getInstance( ).getServiceBackUrl( request );
238
239 if ( !StringUtils.isEmpty( strBackUrl ) )
240 {
241 model.put( MARK_SERVICE_URL, strBackUrl );
242 String strServiceName = !StringUtils.isEmpty( _strAppCode ) ? AuthorizedUrlService.getInstance( ).getNameByApplicationCode( _strAppCode, strBackUrl ) : AuthorizedUrlService.getInstance( ).getName( strBackUrl );
243 if ( !StringUtils.isEmpty( strServiceName ) )
244 {
245 model.put( MARK_SERVICE_NAME, strServiceName );
246 }
247 }
248
249 addMessage( request, model );
250
251 return getXPage( TEMPLATE_GET_VIEW_MODIFY_IDENTITY, request.getLocale( ), model );
252 }
253
254
255
256
257
258
259
260
261
262
263 @View( VIEW_GET_MODIFY_IDENTITY )
264 public XPage getModifyIdentity( HttpServletRequest request ) throws UserNotSignedException
265 {
266 LuteceUser luteceUser = getConnectedUser( request );
267
268 String strAppCode = request.getParameter( PARAMETER_APP_CODE );
269
270 if ( _strAppCode == null || strAppCode != null && !strAppCode.equals( _strAppCode ) )
271 {
272 _bReInitAppCode = true;
273 _strAppCode = strAppCode;
274 }
275
276 if ( ( _dashboardIdentity == null ) || ( _dashboardIdentity.getConnectionId( ) == null ) || !_dashboardIdentity.getConnectionId( ).getValue( ).equals( luteceUser.getName( ) ) )
277 {
278 IdentityDto identity = DashboardIdentityUtils.getInstance( ).getIdentity( luteceUser.getName( ) );
279 _dashboardIdentity = DashboardIdentityUtils.getInstance( ).convertToDashboardIdentity( identity );
280 }
281
282 SitePropertiesGroup dashboardPropertiesGroup = ( SitePropertiesGroup ) SpringContextService.getBean( BEAN_MYDASHBOARD_IDENTITY_SITE_PROPERTIES );
283 String strMyDashboardPropertiesPrefix = dashboardPropertiesGroup.getDatastoreKeysPrefix( );
284
285 Map<String, Object> model = getModel( );
286
287 model.put( MARK_MYDASHBOARD_SITE_PROPERTIES, DatastoreService.getDataByPrefix( strMyDashboardPropertiesPrefix ).toMap( ) );
288 model.put( MARK_IDENTITY, _dashboardIdentity );
289 model.put( MARK_VIEW_MODE, Boolean.FALSE );
290 model.put( MARK_CONTACT_MODE_LIST, _lstContactModeList );
291 model.put( MARK_GENDER_LIST, _lstGenderList );
292 model.put( MARK_AVATAR_URL, getAvatarUrl( request ) );
293 model.put( MARK_AVATARSERVER_POST_URL, AVATARSERVER_POST_URL );
294 model.put( MARK_TOKEN, _securityTokenService.getToken( request, ACTION_DO_MODIFY_IDENTITY ) );
295
296
297 String strBackUrl = AuthorizedUrlService.getInstance( ).getServiceBackUrl( request );
298 if ( !StringUtils.isEmpty( strBackUrl ) )
299 {
300 model.put( MARK_SERVICE_URL, strBackUrl );
301 String strServiceName = !StringUtils.isEmpty( _strAppCode ) ? AuthorizedUrlService.getInstance( ).getNameByApplicationCode( _strAppCode, strBackUrl ) : AuthorizedUrlService.getInstance( ).getName( strBackUrl );
302 if ( !StringUtils.isEmpty( strServiceName ) )
303 {
304 model.put( MARK_SERVICE_NAME, strServiceName );
305 }
306 }
307
308 addMessage( request, model );
309
310 return getXPage( TEMPLATE_GET_VIEW_MODIFY_IDENTITY, request.getLocale( ), model );
311 }
312
313 private void addMessage( HttpServletRequest request, Map<String, Object> model )
314 {
315 String strErrorMessageInSession = DashboardIdentityUtils.getInstance( ).getMessageInSession( true, true, request );
316 String stInfoMessageInSession = DashboardIdentityUtils.getInstance( ).getMessageInSession( false, true, request );
317
318 if( StringUtils.isNotEmpty( strErrorMessageInSession ) )
319 {
320 addError( strErrorMessageInSession, request.getLocale( ) );
321 fillCommons( model );
322 }
323 if( StringUtils.isNotEmpty( stInfoMessageInSession ) )
324 {
325 addInfo( stInfoMessageInSession, request.getLocale( ) );
326 fillCommons( model );
327 }
328 }
329
330
331
332
333
334
335
336
337
338
339 @View( VIEW_GET_CHECK_IDENTITY )
340 public XPage getCheckIdentity( HttpServletRequest request ) throws UserNotSignedException
341 {
342 LuteceUser luteceUser = getConnectedUser( request );
343 String strAppCode = request.getParameter( PARAMETER_APP_CODE );
344
345 if ( _strAppCode == null || strAppCode != null && !strAppCode.equals( _strAppCode ) )
346 {
347 _bReInitAppCode = true;
348 _strAppCode = strAppCode;
349 }
350
351
352 try
353 {
354 _checkdIdentity = DashboardIdentityService.getInstance( ).getDashBoardIdentity( _strAppCode, luteceUser.getName( ) );
355 }
356 catch ( AppException e )
357 {
358 AppLogService.error( "An error appear during retreaving Identity information for app_code {} and user guid {} ", strAppCode, luteceUser.getName( ), e );
359 return getXPage( TEMPLATE_GET_VIEW_ERROR, request.getLocale( ) );
360 }
361
362 _bReInitAppCode = false;
363
364 SitePropertiesGroup dashboardPropertiesGroup = ( SitePropertiesGroup ) SpringContextService.getBean( BEAN_MYDASHBOARD_IDENTITY_SITE_PROPERTIES );
365 String strMyDashboardPropertiesPrefix = dashboardPropertiesGroup.getDatastoreKeysPrefix( );
366
367 Map<String, Object> model = getModel( );
368
369 model.put( MARK_MYDASHBOARD_SITE_PROPERTIES, DatastoreService.getDataByPrefix( strMyDashboardPropertiesPrefix ).toMap( ) );
370 model.put( MARK_IDENTITY, _checkdIdentity );
371 model.put( MARK_CONTACT_MODE_LIST, _lstContactModeList );
372 model.put( MARK_GENDER_LIST, _lstGenderList );
373 model.put( MARK_AVATAR_URL, getAvatarUrl( request ) );
374 model.put( MARK_AVATARSERVER_POST_URL, AVATARSERVER_POST_URL );
375 model.put( MARK_MANDATORY_INFORMATIONS_SAVED, _bMandatoryInformationsSaved );
376 model.put( MARK_TOKEN, _securityTokenService.getToken( request, ACTION_DO_CHECK_IDENTITY ) );
377
378
379
380 String strBackUrl = AuthorizedUrlService.getInstance( ).getServiceBackUrl( request );
381 if ( !StringUtils.isEmpty( strBackUrl ) )
382 {
383 model.put( MARK_SERVICE_URL, strBackUrl );
384 String strServiceName = !StringUtils.isEmpty( _strAppCode ) ? AuthorizedUrlService.getInstance( ).getNameByApplicationCode( _strAppCode, strBackUrl ) : AuthorizedUrlService.getInstance( ).getName( strBackUrl );
385 if ( !StringUtils.isEmpty( strServiceName ) )
386 {
387 model.put( MARK_SERVICE_NAME, strServiceName );
388 }
389 }
390
391 if ( _strAppCode != null && _checkdIdentity != null )
392 {
393 String strAppCodeMonParis = AppPropertiesService.getProperty( APP_CODE_SERVICE_CONTRACT_MON_PARIS );
394
395 if ( _strAppCode.equals( strAppCodeMonParis ) && DashboardIdentityUtils.getInstance().getIdentityCoverage(luteceUser.getName( ), _strAppCode) == 1)
396 {
397
398 String strRoleCertifier = AppPropertiesService.getProperty( ROLE_MYDASHBOARD_CS_REQUIREMENTS_FULLFILLED );
399
400 if( luteceUser.getRoles( ) != null )
401 {
402 if( !Arrays.stream( luteceUser.getRoles( ) ).anyMatch( x -> x.equals( strRoleCertifier ) ) )
403 {
404 luteceUser.addRoles( Arrays.asList( strRoleCertifier ) );
405 }
406 }
407 else
408 {
409 luteceUser.setRoles( Arrays.asList( strRoleCertifier ) );
410 }
411 }
412
413 model.put( MARK_NEED_CERTIFICATION_FC, DashboardIdentityService.getInstance().needCertification( _strAppCode, luteceUser.getName( ), _checkdIdentity, Arrays.asList( PROPERTY_COMPLETION_ATTRIBUTES_NEED_FC.split( "," ) ), 400 ) );
414
415 boolean bLoginNeedCertification = DashboardIdentityService.getInstance().needCertification( _strAppCode, luteceUser.getName( ), _checkdIdentity, Arrays.asList( Constants.ATTRIBUTE_DB_IDENTITY_LOGIN ), PROPERTY_IDENTITYSTORE_EMAIL_LEVEL_MIN )
416 && ( StringUtils.isEmpty( _checkdIdentity.getLogin( ).getCertifierCode( ) ) || !_checkdIdentity.getLogin( ).getCertifierCode( ).equals( PROPERTY_IDENTITYSTORE_EMAIL_CERTIFIER_CODE ) );
417
418 if( bLoginNeedCertification && StringUtils.isNotEmpty( PROPERTY_REDIRECT_URL_CERTIFY_EMAIL ) )
419 {
420 return redirect( request, PROPERTY_REDIRECT_URL_CERTIFY_EMAIL + "&type=login" ) ;
421 }
422
423 boolean bContactEmailNeedCertification = DashboardIdentityService.getInstance().needCertification( _strAppCode, luteceUser.getName( ), _checkdIdentity, Arrays.asList( Constants.ATTRIBUTE_DB_IDENTITY_EMAIL ), PROPERTY_IDENTITYSTORE_EMAIL_LEVEL_MIN )
424 && ( StringUtils.isEmpty( _checkdIdentity.getEmail( ).getCertifierCode( ) ) || !_checkdIdentity.getEmail( ).getCertifierCode( ).equals( PROPERTY_IDENTITYSTORE_EMAIL_CERTIFIER_CODE ) );
425
426 if( ( bContactEmailNeedCertification || StringUtils.isEmpty( _checkdIdentity.getEmail( ).getValue( ) ) ) && StringUtils.isNotEmpty( PROPERTY_REDIRECT_URL_CERTIFY_EMAIL ) )
427 {
428 return redirect( request, PROPERTY_REDIRECT_URL_CERTIFY_EMAIL + "&type=email" ) ;
429 }
430
431 model.put( MARK_NEED_EMAIL_CERTIFICATION, bContactEmailNeedCertification );
432 model.put( MARK_NEED_LOGIN_CERTIFICATION, bLoginNeedCertification );
433 }
434
435
436 _bMandatoryInformationsSaved = false;
437
438 return getXPage( TEMPLATE_GET_VIEW_CHECK_IDENTITY, request.getLocale( ), model );
439 }
440
441
442
443
444
445
446
447
448
449
450
451 @Action( ACTION_DO_MODIFY_IDENTITY )
452 public XPage doModifyIdentity( HttpServletRequest request ) throws UserNotSignedException, AccessDeniedException
453 {
454
455 if ( !_securityTokenService.validate( request, ACTION_DO_MODIFY_IDENTITY ) )
456 {
457 throw new AccessDeniedException( Constants.MESSAGE_ERROR_TOKEN );
458 }
459
460 AuthorizedUrlService.getInstance( ).getServiceBackUrl( request );
461 checkUserAuthentication( request );
462
463 if ( _dashboardIdentity == null || request.getParameter( PARAMETER_BACK ) != null )
464 {
465 return redirectView( request, VIEW_GET_VIEW_IDENTITY );
466 }
467
468
469 DashboardIdentityService.getInstance( ).populateDashboardIdentity( _dashboardIdentity, request );
470 _dashboardIdentity.getLastName().setMandatory( true );
471 _dashboardIdentity.getFirstname().setMandatory( true );
472 _dashboardIdentity.getBirthdate().setMandatory( true );
473 _dashboardIdentity.getGender( ).setMandatory( true );
474
475
476 Map<String, String> hashErros = DashboardIdentityService.getInstance( ).checkDashboardIdentityFields( _dashboardIdentity, request, false );
477 if ( !hashErros.isEmpty( ) )
478 {
479 hashErros.forEach( ( x, y ) -> addError( y ) );
480 return redirectView( request, VIEW_GET_MODIFY_IDENTITY );
481 }
482
483
484 if( DashboardIdentityService.getInstance( ).existSuspiciousIdentities( _dashboardIdentity,DashboardIdentityUtils.getInstance( ).getAllSuspiciousIdentityRules( ) ) )
485 {
486 DashboardIdentityUtils.getInstance( ).setCurrentDashboardIdentityInSession( request, _dashboardIdentity );
487 DashboardIdentityUtils.getInstance( ).setRedirectUrlAfterCompletionInSession( PROPERTY_REDIRECT_MODIFY_ACCOUNT_PAGE, PROPERTY_REDIRECT_MODIFY_ACCOUNT_VIEW, request );
488
489 return redirect( request, VIEW_SUSPICION_IDENTITY_COMPLETION, PARAMETER_ORIGIN_ACTION, Constants.ORIGIN_ACTION_MODIFY_ACCOUNT );
490 }
491
492 try
493 {
494 DashboardIdentityService.getInstance( ).updateDashboardIdentity( _dashboardIdentity, false );
495 } catch ( Exception appEx )
496 {
497
498 AppLogService.error( "An error appear during updating Identity information for user guid {} ", _dashboardIdentity.getConnectionId( ), appEx );
499
500 addError( Constants.MESSAGE_ERROR_UPDATE_IDENTITY, request.getLocale( ) );
501
502 return redirectView( request, VIEW_GET_MODIFY_IDENTITY );
503 }
504
505
506 _dashboardIdentity = null;
507 _checkdIdentity = null;
508
509 addInfo( Constants.MESSAGE_INFO_IDENTITY_UPDATED, request.getLocale( ) );
510
511 return redirectView( request, VIEW_GET_VIEW_IDENTITY );
512 }
513
514
515
516
517
518
519
520
521
522
523
524
525 @Action( ACTION_DO_CHECK_IDENTITY )
526 public XPage doCheckIdentity( HttpServletRequest request ) throws UserNotSignedException, AccessDeniedException
527 {
528
529 if ( !_securityTokenService.validate( request, ACTION_DO_CHECK_IDENTITY ) )
530 {
531 throw new AccessDeniedException( Constants.MESSAGE_ERROR_TOKEN );
532 }
533
534 checkUserAuthentication( request );
535 AuthorizedUrlService.getInstance( ).getServiceBackUrl( request );
536
537 if ( _checkdIdentity == null || request.getParameter( PARAMETER_BACK ) != null )
538 {
539 return redirectView( request, VIEW_GET_CHECK_IDENTITY );
540 }
541
542
543 DashboardIdentityService.getInstance( ).populateDashboardIdentity( _checkdIdentity, request );
544 Map<String, String> hashErros = DashboardIdentityService.getInstance( ).checkDashboardIdentityFields( _checkdIdentity, request, true );
545 hashErros.putAll( DashboardIdentityService.getInstance( ).checkDashboardIdentityFieldsFromServiceContract( _checkdIdentity, request, true, _strAppCode ) );
546 if ( !hashErros.isEmpty( ) )
547 {
548 hashErros.forEach( ( x, y ) -> addError( y, x ) );
549 return redirectView( request, VIEW_GET_CHECK_IDENTITY );
550 }
551
552
553 if( DashboardIdentityService.getInstance( ).existSuspiciousIdentities( _checkdIdentity,DashboardIdentityUtils.getInstance( ).getAllSuspiciousIdentityRules( ) ) )
554 {
555 DashboardIdentityUtils.getInstance( ).setCurrentDashboardIdentityInSession( request, _checkdIdentity );
556 DashboardIdentityUtils.getInstance( ).setRedirectUrlAfterCompletionInSession( PROPERTY_REDIRECT_MODIFY_ACCOUNT_PAGE, PROPERTY_REDIRECT_COMPLETION_ACCOUNT_VIEW, request );
557
558
559 ServiceContractSearchResponse serviceContract = DashboardIdentityService.getInstance( ).getActiveServiceContract( _strAppCode );
560 if( serviceContract != null && serviceContract.getServiceContract( ) != null )
561 {
562 DashboardIdentityUtils.getInstance( ).setNumericServiceNameInSession( serviceContract.getServiceContract( ).getName( ), request );
563 }
564
565 return redirect( request, VIEW_SUSPICION_IDENTITY_COMPLETION, PARAMETER_ORIGIN_ACTION, Constants.ORIGIN_ACTION_COMPLETION_ACCOUNT );
566 }
567
568 try
569 {
570 DashboardIdentityService.getInstance( ).updateDashboardIdentity( _checkdIdentity, false );
571 } catch ( Exception appEx )
572 {
573 addError( Constants.MESSAGE_ERROR_UPDATE_IDENTITY, request.getLocale( ) );
574
575 return redirectView( request, VIEW_GET_CHECK_IDENTITY );
576 }
577
578 _dashboardIdentity = null;
579 _checkdIdentity = null;
580 addInfo( Constants.MESSAGE_INFO_IDENTITY_UPDATED, request.getLocale( ) );
581 _bMandatoryInformationsSaved = true;
582
583 return redirectView( request, VIEW_GET_CHECK_IDENTITY );
584 }
585
586
587
588
589
590
591
592
593
594
595 private LuteceUser getConnectedUser( HttpServletRequest request ) throws UserNotSignedException
596 {
597 LuteceUser luteceUser = SecurityService.isAuthenticationEnable( ) ? SecurityService.getInstance( ).getRegisteredUser( request ) : null;
598
599 if ( luteceUser == null )
600 {
601 throw new UserNotSignedException( );
602 }
603
604 return luteceUser;
605 }
606
607
608
609
610
611
612
613
614
615 private void checkUserAuthentication( HttpServletRequest request ) throws UserNotSignedException
616 {
617 getConnectedUser( request );
618 }
619
620
621
622
623
624
625 @View( VIEW_VALIDATE_LAST_NAME )
626 public XPage validateLastName( HttpServletRequest request )
627 {
628
629 XPage xpContent = getXPage( );
630 xpContent.setContent(
631 getErrorValidation( request, Constants.ATTRIBUTE_DB_IDENTITY_LAST_NAME, Constants.PROPERTY_KEY_VALIDATION_REGEXP_LAST_NAME, Constants.MESSAGE_ERROR_VALIDATION_LASTNAME ) );
632 xpContent.setStandalone( true );
633
634 return xpContent;
635 }
636
637
638
639
640
641
642 @View( VIEW_VALIDATE_PREFERRED_USERNAME )
643 public XPage validatePreferredUserName( HttpServletRequest request )
644 {
645
646 XPage xpContent = getXPage( );
647 xpContent.setContent( getErrorValidation( request, "preferredUsername", Constants.PROPERTY_KEY_VALIDATION_REGEXP_PREFERREDUSERNAME, Constants.MESSAGE_ERROR_VALIDATION_PREFFEREDUSERNAME ) );
648
649 xpContent.setStandalone( true );
650
651 return xpContent;
652 }
653
654
655
656
657
658
659 @View( VIEW_VALIDATE_FISRTNAME )
660 public XPage validateFirstName( HttpServletRequest request )
661 {
662
663 XPage xpContent = getXPage( );
664 xpContent.setContent( getErrorValidation( request, "firstname", Constants.PROPERTY_KEY_VALIDATION_REGEXP_FIRSTNAME, Constants.MESSAGE_ERROR_VALIDATION_FIRSTNAME ) );
665
666 xpContent.setStandalone( true );
667
668 return xpContent;
669 }
670
671
672
673
674
675
676 @View( VIEW_VALIDATE_BIRTHDATE )
677 public XPage validateBirthDate( HttpServletRequest request )
678 {
679
680 XPage xpContent = getXPage( );
681 xpContent.setContent( getErrorValidation( request, "birthdate", Constants.PROPERTY_KEY_VALIDATION_REGEXP_BIRTHDATE, Constants.MESSAGE_ERROR_VALIDATION_BIRTHDATE ) );
682 xpContent.setStandalone( true );
683
684 return xpContent;
685 }
686
687
688
689
690
691
692 @View( VIEW_VALIDATE_BIRTHPLACE )
693 public XPage validateBirthPlace( HttpServletRequest request )
694 {
695
696 XPage xpContent = getXPage( );
697 xpContent.setContent( getErrorValidation( request, "birthplace", Constants.PROPERTY_KEY_VALIDATION_REGEXP_BIRTHPLACE, Constants.MESSAGE_ERROR_VALIDATION_BIRTHPLACE ) );
698
699 xpContent.setStandalone( true );
700
701 return xpContent;
702 }
703
704
705
706
707
708
709 @View( VIEW_VALIDATE_BIRTHCOUNTRY )
710 public XPage validateBirthCountry( HttpServletRequest request )
711 {
712
713 XPage xpContent = getXPage( );
714 xpContent.setContent(
715 getErrorValidation( request, Constants.ATTRIBUTE_DB_IDENTITY_BIRTHCOUNTRY, Constants.PROPERTY_KEY_VALIDATION_REGEXP_BIRTHCOUNTRY, Constants.MESSAGE_ERROR_VALIDATION_BIRTHCOUNTRY ) );
716 xpContent.setStandalone( true );
717
718 return xpContent;
719 }
720
721
722
723
724
725
726 @View( VIEW_VALIDATE_ADDRESS )
727 public XPage validateAddress( HttpServletRequest request )
728 {
729
730 XPage xpContent = getXPage( );
731 xpContent.setContent( getErrorValidation( request, Constants.ATTRIBUTE_DB_IDENTITY_ADDRESS, Constants.PROPERTY_KEY_VALIDATION_REGEXP_ADDRESS, Constants.MESSAGE_ERROR_VALIDATION_ADDRESS ) );
732 xpContent.setStandalone( true );
733
734 return xpContent;
735 }
736
737
738
739
740
741
742 @View( VIEW_VALIDATE_ADDRESS_DETAIL )
743 public XPage validateAddressDetail( HttpServletRequest request )
744 {
745
746 XPage xpContent = getXPage( );
747 xpContent.setContent( getErrorValidation( request, Constants.ATTRIBUTE_DB_IDENTITY_ADDRESS_DETAIL, Constants.PROPERTY_KEY_VALIDATION_REGEXP_ADDRESS_DETAIL,
748 Constants.MESSAGE_ERROR_VALIDATION_ADDRESS_DETAIL ) );
749 xpContent.setStandalone( true );
750
751 return xpContent;
752 }
753
754
755
756
757
758
759 @View( VIEW_VALIDATE_ADDRESS_POSTALCODE )
760 public XPage validateAddressPostalCode( HttpServletRequest request )
761 {
762
763 XPage xpContent = getXPage( );
764 xpContent.setContent( getErrorValidation( request, Constants.ATTRIBUTE_DB_IDENTITY_ADDRESS_POSTAL_CODE, Constants.PROPERTY_KEY_VALIDATION_REGEXP_ADDRESS_POSTALCODE,
765 Constants.MESSAGE_ERROR_VALIDATION_ADDRESS_POSTALCODE ) );
766 xpContent.setStandalone( true );
767
768 return xpContent;
769 }
770
771
772
773
774
775
776 @View( VIEW_VALIDATE_ADDRESS_CITY )
777 public XPage validateAddressCity( HttpServletRequest request )
778 {
779
780 XPage xpContent = getXPage( );
781 xpContent.setContent(
782 getErrorValidation( request, Constants.ATTRIBUTE_DB_IDENTITY_ADDRESS_CITY, Constants.PROPERTY_KEY_VALIDATION_REGEXP_ADDRESS_CITY, Constants.MESSAGE_ERROR_VALIDATION_ADDRESS_CITY ) );
783 xpContent.setStandalone( true );
784
785 return xpContent;
786 }
787
788
789
790
791
792
793 @View( VIEW_VALIDATE_EMAIL )
794 public XPage validateEmail( HttpServletRequest request )
795 {
796
797 XPage xpContent = getXPage( );
798 xpContent.setContent( getErrorValidation( request, Constants.ATTRIBUTE_DB_IDENTITY_EMAIL, null, Constants.MESSAGE_ERROR_VALIDATION_EMAIL ) );
799
800 xpContent.setStandalone( true );
801
802 return xpContent;
803 }
804
805
806
807
808
809
810 @View( VIEW_VALIDATE_PHONE )
811 public XPage validatePhone( HttpServletRequest request )
812 {
813 XPage xpContent = getXPage( );
814 xpContent.setContent( getErrorValidation( request, Constants.ATTRIBUTE_DB_IDENTITY_PHONE, Constants.PROPERTY_KEY_VALIDATION_REGEXP_PHONE, Constants.MESSAGE_ERROR_VALIDATION_PHONE ) );
815 xpContent.setStandalone( true );
816
817 return xpContent;
818 }
819
820
821
822
823
824
825 @View( VIEW_VALIDATE_MOBILEPHONE )
826 public XPage validateMobilePhone( HttpServletRequest request )
827 {
828
829 XPage xpContent = getXPage( );
830 xpContent.setContent(
831 getErrorValidation( request, Constants.ATTRIBUTE_DB_IDENTITY_MOBILE_PHONE, Constants.PROPERTY_KEY_VALIDATION_REGEXP_MOBILEPHONE, Constants.MESSAGE_ERROR_VALIDATION_MOBILEPHONE ) );
832 xpContent.setStandalone( true );
833
834 return xpContent;
835 }
836
837 private String getErrorValidation( HttpServletRequest request, String strAttributeKey, String strRegExp, String i18nErrorMessage )
838 {
839
840 return getErrorValidation( request, strAttributeKey, strRegExp, i18nErrorMessage, false );
841
842 }
843
844
845
846
847
848
849
850
851
852
853
854
855
856 private String getErrorValidation( HttpServletRequest request, String strAttributeKey, String strRegExp, String i18nErrorMessage, boolean bCheckMandatory )
857 {
858 String strError = StringUtils.EMPTY;
859 if ( strAttributeKey.equals( Constants.ATTRIBUTE_DB_IDENTITY_EMAIL ) && ( request.getParameter( strAttributeKey ) == null
860 || ( StringUtils.isEmpty( strAttributeKey ) && !EmailValidator.getInstance( ).isValid( request.getParameter( strAttributeKey ) ) ) ) )
861 {
862 strError = I18nService.getLocalizedString( i18nErrorMessage, request.getLocale( ) );
863
864 }
865
866 else if ( request.getParameter( strAttributeKey ) == null || !request.getParameter( strAttributeKey ).matches( strRegExp ) )
867 {
868 strError = I18nService.getLocalizedString( i18nErrorMessage, request.getLocale( ) );
869 } else if ( bCheckMandatory && StringUtils.isBlank( request.getParameter( strAttributeKey ) ) )
870 {
871
872 strError = I18nService.getLocalizedString( Constants.MESSAGE_ERROR_EMPTY_ERROR_PREFIX + strAttributeKey, request.getLocale( ) );
873
874 }
875
876 return strError;
877
878 }
879
880
881
882
883
884
885
886
887 private String getAvatarUrl( HttpServletRequest request )
888 {
889 LuteceUser user = SecurityService.getInstance( ).getRegisteredUser( request );
890
891 return AvatarService.getAvatarUrl( user.getEmail( ) );
892 }
893
894 @View( VIEW_SUSPICION_IDENTITY_COMPLETION )
895 public XPage getViewSuspiciousIdentity( HttpServletRequest request )
896 {
897 Map<String, Object> model = getModel( );
898 _originActionCompletion = request.getParameter( PARAMETER_ORIGIN_ACTION );
899
900 DashboardIdentity dasboardIdentitySession = DashboardIdentityUtils.getInstance( ).getCurrentDashboardIdentityInSession( request );
901
902 if ( dasboardIdentitySession == null )
903 {
904 return redirect( request, AppPathService.getRootForwardUrl( ) );
905 }
906
907 model.put( MARK_GENDER_LIST, _lstGenderList );
908 model.put( MARK_IDENTITY, _completionIdentity == null ? dasboardIdentitySession : _completionIdentity );
909 model.put( MARK_ORIGIN_ACTION, _originActionCompletion );
910 model.put( MARK_NS_NAME, DashboardIdentityUtils.getInstance( ).getNumericServiceNameInSession( request ) );
911 model.put( MARK_TOKEN, _securityTokenService.getToken( request, ACTION_DO_COMPLETE_SUSPICIOUS_IDENTITY ) );
912
913 return getXPage( TEMPLATE_SUSPICIOUS_COMPLETE_IDENTITY, I18nService.getDefaultLocale( ), model );
914 }
915
916 @Action( ACTION_DO_COMPLETE_SUSPICIOUS_IDENTITY )
917 public XPage doCompleteSuspiciousIdentity( HttpServletRequest request ) throws AccessDeniedException
918 {
919
920 if ( !_securityTokenService.validate( request, ACTION_DO_COMPLETE_SUSPICIOUS_IDENTITY ) )
921 {
922 throw new AccessDeniedException( Constants.MESSAGE_ERROR_TOKEN );
923 }
924
925 DashboardIdentity dasboardIdentitySession = DashboardIdentityUtils.getInstance( ).getCurrentDashboardIdentityInSession( request );
926
927 if ( dasboardIdentitySession == null )
928 {
929 return redirect( request, AppPathService.getRootForwardUrl( ) );
930 }
931
932 _completionIdentity = DashboardIdentityUtils.getInstance( ).initMandatoryAttributeForCompletionIdentity( dasboardIdentitySession, _originActionCompletion );
933
934 DashboardIdentityService.getInstance( ).populateDashboardIdentity( _completionIdentity, request );
935
936 Map<String, String> hashErros = DashboardIdentityService.getInstance( ).checkDashboardIdentityFields( _completionIdentity, request, false );
937 if ( !hashErros.isEmpty( ) )
938 {
939 hashErros.forEach( ( x, y ) -> addError( y ) );
940 return redirect( request, VIEW_SUSPICION_IDENTITY_COMPLETION, PARAMETER_ORIGIN_ACTION, Integer.parseInt( _originActionCompletion ));
941 }
942
943 DashboardIdentityUtils.getInstance( ).updateDashboardIdentityInSession( _completionIdentity, dasboardIdentitySession );
944
945 DashboardIdentityUtils.getInstance( ).setCurrentDashboardIdentityInSession( request, dasboardIdentitySession );
946
947
948 String strRedirectUrl = DashboardIdentityUtils.getInstance( ).getRedirectUrlAfterCompletionInSession( request );
949
950 return redirect( request, strRedirectUrl );
951
952 }
953
954 }