View Javadoc
1   /*
2    * Copyright (c) 2002-2014, Mairie de Paris
3    * All rights reserved.
4    *
5    * Redistribution and use in source and binary forms, with or without
6    * modification, are permitted provided that the following conditions
7    * are met:
8    *
9    *  1. Redistributions of source code must retain the above copyright notice
10   *     and the following disclaimer.
11   *
12   *  2. Redistributions in binary form must reproduce the above copyright notice
13   *     and the following disclaimer in the documentation and/or other materials
14   *     provided with the distribution.
15   *
16   *  3. Neither the name of 'Mairie de Paris' nor 'Lutece' nor the names of its
17   *     contributors may be used to endorse or promote products derived from
18   *     this software without specific prior written permission.
19   *
20   * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21   * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22   * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23   * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
24   * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25   * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26   * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27   * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28   * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29   * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30   * POSSIBILITY OF SUCH DAMAGE.
31   *
32   * License 1.0
33   */
34  package fr.paris.lutece.plugins.mylutece.modules.wssodatabase.authentication.web;
35  
36  import fr.paris.lutece.plugins.mylutece.business.attribute.AttributeHome;
37  import fr.paris.lutece.plugins.mylutece.business.attribute.IAttribute;
38  import fr.paris.lutece.plugins.mylutece.modules.wssodatabase.authentication.business.IdxWSSODatabaseHome;
39  import fr.paris.lutece.plugins.mylutece.modules.wssodatabase.authentication.business.WssoProfil;
40  import fr.paris.lutece.plugins.mylutece.modules.wssodatabase.authentication.business.WssoProfilHome;
41  import fr.paris.lutece.plugins.mylutece.modules.wssodatabase.authentication.business.WssoUser;
42  import fr.paris.lutece.plugins.mylutece.modules.wssodatabase.authentication.business.WssoUserHome;
43  import fr.paris.lutece.plugins.mylutece.modules.wssodatabase.authentication.business.WssoUserRoleHome;
44  import fr.paris.lutece.plugins.mylutece.modules.wssodatabase.authentication.service.ImportWssoDatabaseUserService;
45  import fr.paris.lutece.plugins.mylutece.modules.wssodatabase.authentication.service.WssoDatabaseService;
46  import fr.paris.lutece.plugins.mylutece.modules.wssodatabase.authentication.util.LdapBrowser;
47  import fr.paris.lutece.plugins.mylutece.service.MyLutecePlugin;
48  import fr.paris.lutece.plugins.mylutece.service.RoleResourceIdService;
49  import fr.paris.lutece.portal.business.role.Role;
50  import fr.paris.lutece.portal.business.role.RoleHome;
51  import fr.paris.lutece.portal.business.user.AdminUser;
52  import fr.paris.lutece.portal.business.xsl.XslExport;
53  import fr.paris.lutece.portal.business.xsl.XslExportHome;
54  import fr.paris.lutece.portal.service.admin.AdminUserService;
55  import fr.paris.lutece.portal.service.csv.CSVMessageDescriptor;
56  import fr.paris.lutece.portal.service.fileupload.FileUploadService;
57  import fr.paris.lutece.portal.service.i18n.I18nService;
58  import fr.paris.lutece.portal.service.mail.MailService;
59  import fr.paris.lutece.portal.service.message.AdminMessage;
60  import fr.paris.lutece.portal.service.message.AdminMessageService;
61  import fr.paris.lutece.portal.service.plugin.Plugin;
62  import fr.paris.lutece.portal.service.plugin.PluginService;
63  import fr.paris.lutece.portal.service.rbac.RBACService;
64  import fr.paris.lutece.portal.service.template.AppTemplateService;
65  import fr.paris.lutece.portal.service.util.AppLogService;
66  import fr.paris.lutece.portal.service.util.AppPathService;
67  import fr.paris.lutece.portal.service.util.AppPropertiesService;
68  import fr.paris.lutece.portal.service.xsl.XslExportService;
69  import fr.paris.lutece.portal.web.admin.PluginAdminPageJspBean;
70  import fr.paris.lutece.portal.web.constants.Messages;
71  import fr.paris.lutece.portal.web.constants.Parameters;
72  import fr.paris.lutece.portal.web.pluginaction.DefaultPluginActionResult;
73  import fr.paris.lutece.portal.web.upload.MultipartHttpServletRequest;
74  import fr.paris.lutece.portal.web.util.LocalizedPaginator;
75  import fr.paris.lutece.util.ReferenceItem;
76  import fr.paris.lutece.util.ReferenceList;
77  import fr.paris.lutece.util.filesystem.FileSystemUtil;
78  import fr.paris.lutece.util.html.HtmlTemplate;
79  import fr.paris.lutece.util.html.ItemNavigator;
80  import fr.paris.lutece.util.html.Paginator;
81  import fr.paris.lutece.util.sort.AttributeComparator;
82  import fr.paris.lutece.util.string.StringUtil;
83  import fr.paris.lutece.util.url.UrlItem;
84  import fr.paris.lutece.util.xml.XmlUtil;
85  
86  import java.io.IOException;
87  import java.io.PrintWriter;
88  import java.util.ArrayList;
89  import java.util.Collection;
90  import java.util.Collections;
91  import java.util.HashMap;
92  import java.util.List;
93  import java.util.Locale;
94  import java.util.Map;
95  
96  import javax.servlet.http.HttpServletRequest;
97  import javax.servlet.http.HttpServletResponse;
98  
99  import org.apache.commons.fileupload.FileItem;
100 import org.apache.commons.lang.StringUtils;
101 
102 
103 /**
104  * This class provides the user interface to manage roles features ( manage,
105  * create, modify, remove )
106  */
107 public class WssodatabaseJspBean extends PluginAdminPageJspBean
108 {
109     // Right
110     public static final String RIGHT_MANAGE_WSSO_USERS = "WSSODATABASE_MANAGEMENT_USERS";
111     public static final String RIGHT_MANAGE_WSSO_ROLES = "CORE_ROLES_MANAGEMENT";
112     public static final String RIGHT_MANAGE_WSSO_PROFILS = "WSSODATABASE_MANAGEMENT_PROFILS";
113     public static final String RESOURCE_TYPE = "WSSO_DATABASE";
114     public static final String PERMISSION_IMPORT_EXPORT_WSSO_DATABASE_USERS = "IMPORT_EXPORT_WSSO_DATABASE_USERS";
115     public static final String WSSODATABASE_MANAGEMENT_USERS = "WSSODATABASE_MANAGEMENT_USERS";
116 
117     /**
118      *
119      */
120     private static final long serialVersionUID = 1389282258444625177L;
121 
122     /////////////////////////////////////////////////////////////////////////////////////////
123     // Constants
124     private static final String SPACE = " ";
125     private static final String CONSTANT_EXTENSION_CSV_FILE = ".csv";
126     private static final String CONSTANT_EXTENSION_XML_FILE = ".xml";
127     private static final String CONSTANT_MIME_TYPE_CSV = "application/csv";
128     private static final String CONSTANT_MIME_TYPE_XML = "application/xml";
129     private static final String CONSTANT_MIME_TYPE_TEXT_CSV = "text/csv";
130     private static final String CONSTANT_MIME_TYPE_OCTETSTREAM = "application/octet-stream";
131     private static final String CONSTANT_EXPORT_USERS_FILE_NAME = "users";
132     private static final String CONSTANT_POINT = ".";
133     private static final String CONSTANT_QUOTE = "\"";
134     private static final String CONSTANT_ATTACHEMENT_FILE_NAME = "attachement; filename=\"";
135     private static final String CONSTANT_ATTACHEMENT_DISPOSITION = "Content-Disposition";
136     private static final String CONSTANT_XML_USERS = "users";
137 
138     //JSP
139     private static final String MANAGE_USERS = "ManageUsers.jsp";
140     private static final String JSP_DO_REMOVE_USER = "jsp/admin/plugins/mylutece/modules/wssodatabase/DoRemoveUser.jsp";
141     private static final String JSP_DO_REMOVE_PROFIL = "jsp/admin/plugins/mylutece/modules/wssodatabase/DoRemoveProfil.jsp";
142     private static final String MANAGE_PROFILS = "ManageProfils.jsp";
143     private static final String MANAGE_ROLES_PROFIL = "ManageRolesProfil.jsp";
144     private static final String JSP_URL_MANAGE_USERS_PROFIL = "jsp/admin/plugins/mylutece/modules/database/ManageUsersProfil.jsp";
145     private static final String JSP_DO_REMOVE_ASIGN_USER_PROFIL = "jsp/admin/plugins/mylutece/modules/wssodatabase/DoRemoveAssignUserProfil.jsp";
146     private static final String MANAGE_PROFILS_USER = "ManageProfilsUser.jsp";
147 
148     //Propety
149     private static final String PROPERTY_PAGE_TITLE_MANAGE_USERS = "module.mylutece.wssodatabase.manage_users.pageTitle";
150     private static final String PROPERTY_PAGE_TITLE_MANAGE_ROLES_USER = "module.mylutece.wssodatabase.manage_roles_user.pageTitle";
151     private static final String PROPERTY_PAGE_TITLE_CREATE_USER = "module.mylutece.wssodatabase.create_user.pageTitle";
152 
153     //    private static final String PROPERTY_USERS_PER_PAGE = "paginator.users.itemsPerPage";
154     private static final String PROPERTY_PROFILS_PER_PAGE = "paginator.profils.itemsPerPage";
155     private static final String PROPERTY_PAGE_TITLE_MANAGE_PROFILS = "module.mylutece.wssodatabase.manage_profils.pageTitle";
156     private static final String PROPERTY_PAGE_TITLE_MANAGE_ROLES_PROFIL = "module.mylutece.wssodatabase.manage_roles_profil.pageTitle";
157     private static final String PROPERTY_PAGE_TITLE_MANAGE_USERS_PROFIL = "module.mylutece.wssodatabase.manage_users_profil.pageTitle";
158     private static final String PROPERTY_PAGE_TITLE_CREATE_PROFIL = "module.mylutece.wssodatabase.create_profil.pageTitle";
159     private static final String PROPERTY_PAGE_TITLE_MANAGE_PROFILS_USER = "module.mylutece.wssodatabase.manage_profils_user.pageTitle";
160     private static final String PROPERTY_IMPORT_USERS_FROM_FILE_PAGETITLE = "module.mylutece.wssodatabase.import_users_from_file.pageTitle";
161     private static final String PROPERTY_NO_REPLY_EMAIL = "mail.noreply.email";
162     private static final String PROPERTY_SITE_NAME = "lutece.name";
163 
164     //Messages
165     private static final String MESSAGE_CONFIRM_REMOVE_USER = "module.mylutece.wssodatabase.message.confirmRemoveUser";
166     private static final String MESSAGE_USER_EXIST = "module.mylutece.wssodatabase.message.user_exist";
167     private static final String MESSAGE_ERROR_CREATE_USER = "module.mylutece.wssodatabase.message.create.user";
168     private static final String MESSAGE_ERROR_REMOVE_USER = "module.mylutece.wssodatabase.message.remove.user";
169     private static final String MESSAGE_CONFIRM_REMOVE_PROFIL = "module.mylutece.wssodatabase.message.confirmRemoveProfil";
170     private static final String MESSAGE_CONFIRM_REMOVE_ASSIGN_PROFIL_USER = "module.mylutece.wssodatabase.message.confirmAssignProfilUser";
171     private static final String MESSAGE_ERROR_REMOVE_PROFIL = "module.mylutece.wssodatabase.message.remove.profil";
172     private static final String MESSAGE_ERROR_REMOVE_ASSIGNED_PROFIL = "module.mylutece.wssodatabase.message.remove.assigned_profil";
173     private static final String MESSAGE_PROFIL_EXIST = "module.mylutece.wssodatabase.message.profil_exist";
174     private static final String MESSAGE_MANDATORY_FIELD = "portal.util.message.mandatoryField";
175     private static final String MESSAGE_ERROR_CSV_FILE_IMPORT = "module.mylutece.wssodatabase.import_users_from_file.error_csv_file_import";
176     private static final String MESSAGE_ACCOUNT_IMPORTED_MAIL_SUBJECT = "module.mylutece.wssodatabase.import_users_from_file.email.mailSubject";
177 
178     // Parameters
179     private static final String PARAMETER_PLUGIN_NAME = "plugin_name";
180     private static final String PARAMETER_MYLUTECE_WSSO_ROLE_ID = "mylutece_wsso_role_id";
181     private static final String PARAMETER_MYLUTECE_WSSO_USER_ID = "mylutece_wsso_user_id";
182     private static final String PARAMETER_GUID = "guid";
183     private static final String PARAMETER_LAST_NAME = "last_name";
184     private static final String PARAMETER_FIRST_NAME = "first_name";
185     private static final String PARAMETER_EMAIL = "email";
186     private static final String PARAMETER_MYLUTECE_WSSO_PROFIL_CODE = "mylutece_wsso_profil_code";
187     private static final String PARAMETER_CODE = "code";
188     private static final String PARAMETER_DESCRIPTION = "description";
189     private static final String PARAMETER_MYLUTECE_DATABASE_ROLE_IDS = "mylutece_database_role_id";
190     private static final String PARAMETER_AVAILABLE_USERS = "available_users";
191     private static final String MARK_AND_PARAMETER_SEARCH_CODE = "search_code";
192     private static final String MARK_AND_PARAMETER_SEARCH_DESCRIPTION = "search_description";
193     private static final String MARK_AND_PARAMETER_SEARCH_LASTNAME = "search_last_name";
194     private static final String MARK_AND_PARAMETER_SEARCH_FIRSTNAME = "search_first_name";
195     private static final String MARK_AND_PARAMETER_SEARCH_EMAIL = "search_email";
196     private static final String MARK_AND_PARAMETER_ASSIGNED_USER_ID = "assigned_user_id";
197     private static final String PARAMETER_XSL_EXPORT_ID = "xsl_export_id";
198     private static final String PARAMETER_EXPORT_PROFILS = "export_profils";
199     private static final String PARAMETER_EXPORT_ROLES = "export_roles";
200     private static final String PARAMETER_EXPORT_GROUPS = "export_groups";
201     private static final String PARAMETER_IMPORT_USERS_FILE = "import_file";
202     private static final String PARAMETER_SKIP_FIRST_LINE = "ignore_first_line";
203     private static final String PARAMETER_UPDATE_USERS = "update_existing_users";
204     private static final String MARK_SITE_NAME = "site_name";
205     private static final String MARK_SITE_LINK = "site_link";
206 
207     // Marks FreeMarker
208     private static final String MARK_ROLES_LIST = "role_list";
209     private static final String MARK_ROLES_LIST_FOR_USER = "user_role_list";
210     private static final String MARK_USERS_LIST = "user_list";
211     private static final String MARK_USER = "user";
212     private static final String MARK_PLUGIN_NAME = "plugin_name";
213     private static final String MARK_LAST_NAME = "last_name";
214     private static final String MARK_FIRST_NAME = "first_name";
215     private static final String MARK_EMAIL = "email";
216     private static final String MARK_PROFILS_LIST = "profil_list";
217     private static final String MARK_PAGINATOR = "paginator";
218     private static final String MARK_NB_ITEMS_PER_PAGE = "nb_items_per_page";
219     private static final String MARK_ITEM_NAVIGATOR = "item_navigator";
220     private static final String MARK_PROFIL = "profil";
221     private static final String MARK_LOCALE = "locale";
222     private static final String MARK_AVAILABLE_USERS = "available_users";
223     private static final String MARK_ASSIGNED_USERS = "assigned_users";
224     private static final String MARK_ASSIGNED_USERS_NUMBER = "assigned_users_number";
225     private static final String MARK_LIST_XSL_EXPORT = "refListXsl";
226     private static final String MARK_LIST_MESSAGES = "messages";
227     private static final String MARK_CSV_SEPARATOR = "csv_separator";
228     private static final String MARK_CSV_ESCAPE = "csv_escape";
229     private static final String MARK_ATTRIBUTES_SEPARATOR = "attributes_separator";
230     private static final String MARK_PROFILS_LIST_FOR_USER = "profil_user_list";
231     private static final String MARK_RIGHT_MANAGE_ROLES = "manageRoles";
232     private static final String ATTRIBUTE_IMPORT_USERS_LIST_MESSAGES = "importUsersListMessages";
233 
234     // Templates
235     private static final String TEMPLATE_CREATE_USER = "admin/plugins/mylutece/modules/wssodatabase/create_user.html";
236     private static final String TEMPLATE_MANAGE_USERS = "admin/plugins/mylutece/modules/wssodatabase/manage_users.html";
237     private static final String TEMPLATE_MANAGE_ROLES_USER = "admin/plugins/mylutece/modules/wssodatabase/manage_roles_user.html";
238     private static final String TEMPLATE_MANAGE_PROFILS = "admin/plugins/mylutece/modules/wssodatabase/manage_profils.html";
239     private static final String TEMPLATE_CREATE_PROFIL = "admin/plugins/mylutece/modules/wssodatabase/create_profil.html";
240     private static final String TEMPLATE_MODIFY_PROFIL = "admin/plugins/mylutece/modules/wssodatabase/modify_profil.html";
241     private static final String TEMPLATE_MANAGE_ROLES_PROFIL = "admin/plugins/mylutece/modules/wssodatabase/manage_roles_profil.html";
242     private static final String TEMPLATE_MANAGE_USERS_PROFIL = "admin/plugins/mylutece/modules/wssodatabase/manage_users_profil.html";
243     private static final String TEMPLATE_EXPORT_USERS_FROM_FILE = "admin/plugins/mylutece/modules/wssodatabase/export_users.html";
244     private static final String TEMPLATE_IMPORT_USERS_FROM_FILE = "admin/plugins/mylutece/modules/wssodatabase/import_users_from_file.html";
245     private static final String TEMPLATE_MANAGE_PROFILS_USER = "admin/plugins/mylutece/modules/wssodatabase/manage_profils_user.html";
246     private static final String TEMPLATE_MAIL_USER_IMPORTED = "admin/plugins/mylutece/modules/wssodatabase/mail_user_imported.html";
247 
248     private static final String FIELD_IMPORT_USERS_FILE = "module.mylutece.wssodatabase.import_users_from_file.labelImportFile";
249     private static final String FIELD_XSL_EXPORT = "module.mylutece.wssodatabase.export_users.labelXslt";
250     private static final String CONSTANT_WILDCARD = "*";
251 
252     //    private Plugin _plugin;
253 
254     // Variables
255     private int _nItemsPerPage;
256     private int _nDefaultItemsPerPage;
257     private String _strCurrentPageIndex;
258     private String _strSortedAttributeName;
259     private boolean _bIsAscSort = true;
260     private ItemNavigator _itemNavigator;
261     private WssoDatabaseService _databaseService = WssoDatabaseService.getInstance( );
262     private ImportWssoDatabaseUserService _importWssoDatabaseUserService = new ImportWssoDatabaseUserService( );
263 
264     /**
265      * Creates a new WssodatabaseJspBean object.
266      */
267     public WssodatabaseJspBean( )
268     {
269     }
270 
271     /**
272      * Returns the User creation form
273      * 
274      * @param request The Http request
275      * @return Html creation form
276      */
277     public String getCreateUser( HttpServletRequest request )
278     {
279         LdapBrowser ldap = new LdapBrowser( );
280         Collection userList = null;
281 
282         setPageTitleProperty( PROPERTY_PAGE_TITLE_CREATE_USER );
283 
284         // get the filter parameters
285         String strUserLastName = request.getParameter( PARAMETER_LAST_NAME );
286 
287         if ( strUserLastName == null )
288         {
289             strUserLastName = "";
290         }
291 
292         String strUserFirstName = request.getParameter( PARAMETER_FIRST_NAME );
293 
294         if ( strUserFirstName == null )
295         {
296             strUserFirstName = "";
297         }
298 
299         String strUserEMail = request.getParameter( PARAMETER_EMAIL );
300 
301         if ( strUserEMail == null )
302         {
303             strUserEMail = "";
304         }
305 
306         //search in LDAP
307         if ( !( ( strUserLastName.equals( "" ) ) && ( strUserFirstName.equals( "" ) ) && ( strUserEMail.equals( "" ) ) ) )
308         {
309             try
310             {
311                 userList = ldap.getUserList( strUserLastName + CONSTANT_WILDCARD, strUserFirstName + CONSTANT_WILDCARD,
312                         strUserEMail + CONSTANT_WILDCARD );
313             }
314             catch ( Exception e )
315             {
316                 AppLogService.error( e.getMessage( ), e );
317             }
318         }
319 
320         Map<String, Object> model = new HashMap<String, Object>( );
321         model.put( MARK_USERS_LIST, userList );
322         model.put( MARK_PLUGIN_NAME, getPlugin( ).getName( ) );
323         model.put( MARK_LAST_NAME, strUserLastName );
324         model.put( MARK_FIRST_NAME, strUserFirstName );
325         model.put( MARK_EMAIL, strUserEMail );
326 
327         HtmlTemplate template = AppTemplateService.getTemplate( TEMPLATE_CREATE_USER, getLocale( ), model );
328 
329         return getAdminPage( template.getHtml( ) );
330     }
331 
332     /**
333      * Returns the Profil creation form
334      * 
335      * @param request The Http request
336      * @return Html creation form
337      */
338     public String getCreateProfil( HttpServletRequest request )
339     {
340         setPageTitleProperty( PROPERTY_PAGE_TITLE_CREATE_PROFIL );
341 
342         HashMap<String, Object> model = new HashMap<String, Object>( );
343         model.put( MARK_PLUGIN_NAME, getPlugin( ).getName( ) );
344 
345         HtmlTemplate template = AppTemplateService.getTemplate( TEMPLATE_CREATE_PROFIL, getLocale( ), model );
346 
347         return getAdminPage( template.getHtml( ) );
348     }
349 
350     /**
351      * Process user's creation
352      * 
353      * @param request The Http request
354      * @return The user's Displaying Url
355      */
356     public String doCreateUser( HttpServletRequest request )
357     {
358         WssoUser user = null;
359         LdapBrowser ldap = new LdapBrowser( );
360 
361         String strUserGuid = request.getParameter( PARAMETER_GUID );
362 
363         if ( strUserGuid == null )
364         {
365             return AdminMessageService.getMessageUrl( request, MESSAGE_ERROR_CREATE_USER, AdminMessage.TYPE_ERROR );
366         }
367 
368         Collection userList = WssoUserHome.findWssoUsersListForGuid( strUserGuid, getPlugin( ) );
369 
370         if ( userList.size( ) == 0 )
371         {
372             user = ldap.getUserPublicData( strUserGuid );
373 
374             if ( user == null )
375             {
376                 return AdminMessageService.getMessageUrl( request, MESSAGE_ERROR_CREATE_USER, AdminMessage.TYPE_ERROR );
377             }
378 
379             WssoUserHome.create( user, getPlugin( ) );
380             notifyUserAccountCreated( user, AdminUserService.getLocale( request ), AppPathService.getBaseUrl( request ) );
381         }
382         else
383         {
384             return AdminMessageService.getMessageUrl( request, MESSAGE_USER_EXIST, AdminMessage.TYPE_STOP );
385         }
386 
387         return MANAGE_USERS + "?" + PARAMETER_PLUGIN_NAME + "=" + getPlugin( ).getName( );
388     }
389 
390     /**
391      * Process profil's creation
392      * 
393      * @param request The Http request
394      * @return The user's Displaying Url
395      */
396     public String doCreateProfil( HttpServletRequest request )
397     {
398         String strCode = request.getParameter( PARAMETER_CODE );
399         String strDescription = request.getParameter( PARAMETER_DESCRIPTION );
400 
401         if ( StringUtils.isBlank( strCode ) || StringUtils.isBlank( strDescription ) )
402         {
403             return AdminMessageService.getMessageUrl( request, Messages.MANDATORY_FIELDS, AdminMessage.TYPE_STOP );
404         }
405 
406         WssoProfil wssoProfil = WssoProfilHome.findWssoProfilByCode( strCode, getPlugin( ) );
407 
408         if ( wssoProfil != null )
409         {
410             return AdminMessageService.getMessageUrl( request, MESSAGE_PROFIL_EXIST, AdminMessage.TYPE_STOP );
411         }
412 
413         wssoProfil = new WssoProfil( );
414         wssoProfil.setCode( strCode );
415         wssoProfil.setDescription( strDescription );
416 
417         WssoProfilHome.create( wssoProfil, getPlugin( ) );
418 
419         return MANAGE_PROFILS + "?" + PARAMETER_PLUGIN_NAME + "=" + getPlugin( ).getName( );
420     }
421 
422     /**
423      * Process profil's modification
424      * 
425      * @param request The Http request
426      * @return The user's Displaying Url
427      */
428     public String doModifyProfil( HttpServletRequest request )
429     {
430         String mlWssoProfilCode = request.getParameter( PARAMETER_MYLUTECE_WSSO_PROFIL_CODE );
431 
432         if ( mlWssoProfilCode == null )
433         {
434             return getManageProfils( request );
435         }
436 
437         WssoProfil wssoProfil = WssoProfilHome.findWssoProfilByCode( mlWssoProfilCode, getPlugin( ) );
438 
439         if ( wssoProfil == null )
440         {
441             getManageProfils( request );
442         }
443 
444         String strDescription = request.getParameter( PARAMETER_DESCRIPTION );
445 
446         if ( StringUtils.isBlank( strDescription ) )
447         {
448             return AdminMessageService.getMessageUrl( request, Messages.MANDATORY_FIELDS, AdminMessage.TYPE_STOP );
449         }
450 
451         wssoProfil.setDescription( strDescription );
452 
453         WssoProfilHome.update( wssoProfil, getPlugin( ) );
454 
455         return MANAGE_PROFILS + "?" + PARAMETER_PLUGIN_NAME + "=" + getPlugin( ).getName( );
456     }
457 
458     /**
459      * Returns removal user's form
460      * 
461      * @param request The Http request
462      * @return Html form
463      */
464     public String getRemoveUser( HttpServletRequest request )
465     {
466         int nUserId = Integer.parseInt( request.getParameter( PARAMETER_MYLUTECE_WSSO_USER_ID ) );
467 
468         UrlItem url = new UrlItem( JSP_DO_REMOVE_USER );
469         url.addParameter( PARAMETER_PLUGIN_NAME, getPlugin( ).getName( ) );
470         url.addParameter( PARAMETER_MYLUTECE_WSSO_USER_ID, nUserId );
471 
472         return AdminMessageService.getMessageUrl( request, MESSAGE_CONFIRM_REMOVE_USER, url.getUrl( ),
473                 AdminMessage.TYPE_CONFIRMATION );
474     }
475 
476     /**
477      * Returns removal profil's form
478      * 
479      * @param request The Http request
480      * @return Html form
481      */
482     public String getRemoveProfil( HttpServletRequest request )
483     {
484         String mlWssoProfilCode = request.getParameter( PARAMETER_MYLUTECE_WSSO_PROFIL_CODE );
485 
486         if ( mlWssoProfilCode == null )
487         {
488             return getManageProfils( request );
489         }
490 
491         UrlItem url = new UrlItem( JSP_DO_REMOVE_PROFIL );
492         url.addParameter( PARAMETER_PLUGIN_NAME, getPlugin( ).getName( ) );
493         url.addParameter( PARAMETER_MYLUTECE_WSSO_PROFIL_CODE, mlWssoProfilCode );
494 
495         boolean isAssigned = WssoProfilHome.checkProfilAssigned( mlWssoProfilCode, getPlugin( ) );
496 
497         if ( isAssigned )
498         {
499             return AdminMessageService.getMessageUrl( request, MESSAGE_ERROR_REMOVE_ASSIGNED_PROFIL,
500                     AdminMessage.TYPE_STOP );
501         }
502 
503         return AdminMessageService.getMessageUrl( request, MESSAGE_CONFIRM_REMOVE_PROFIL, url.getUrl( ),
504                 AdminMessage.TYPE_CONFIRMATION );
505     }
506 
507     /**
508      * Process user's removal
509      * 
510      * @param request The Http request
511      * @return The Jsp management URL of the process result
512      */
513     public String doRemoveUser( HttpServletRequest request )
514     {
515         if ( request.getParameter( PARAMETER_MYLUTECE_WSSO_USER_ID ) == null )
516         {
517             return AdminMessageService.getMessageUrl( request, MESSAGE_ERROR_REMOVE_USER, AdminMessage.TYPE_ERROR );
518         }
519 
520         int nUserId = Integer.parseInt( request.getParameter( PARAMETER_MYLUTECE_WSSO_USER_ID ) );
521 
522         WssoUser user = WssoUserHome.findByPrimaryKey( nUserId, getPlugin( ) );
523 
524         if ( user == null )
525         {
526             return AdminMessageService.getMessageUrl( request, MESSAGE_ERROR_REMOVE_USER, AdminMessage.TYPE_ERROR );
527         }
528 
529         WssoUserHome.remove( user, getPlugin( ) );
530         WssoUserRoleHome.deleteRolesForUser( user.getMyluteceWssoUserId( ), getPlugin( ) );
531 
532         return MANAGE_USERS + "?" + PARAMETER_PLUGIN_NAME + "=" + getPlugin( ).getName( );
533     }
534 
535     /**
536      * Process profil's removal
537      * 
538      * @param request The Http request
539      * @return The Jsp management URL of the process result
540      */
541     public String doRemoveProfil( HttpServletRequest request )
542     {
543         String mlWssoProfilCode = request.getParameter( PARAMETER_MYLUTECE_WSSO_PROFIL_CODE );
544 
545         if ( mlWssoProfilCode == null )
546         {
547             return AdminMessageService.getMessageUrl( request, MESSAGE_ERROR_REMOVE_PROFIL, AdminMessage.TYPE_STOP );
548         }
549 
550         WssoProfil wssoProfil = WssoProfilHome.findWssoProfilByCode( mlWssoProfilCode, getPlugin( ) );
551 
552         if ( wssoProfil == null )
553         {
554             return AdminMessageService.getMessageUrl( request, MESSAGE_ERROR_REMOVE_PROFIL, AdminMessage.TYPE_STOP );
555         }
556 
557         WssoProfilHome.remove( wssoProfil, getPlugin( ) );
558 
559         return MANAGE_PROFILS + "?" + PARAMETER_PLUGIN_NAME + "=" + getPlugin( ).getName( );
560     }
561 
562     /**
563      * Returns users management form
564      * 
565      * @param request The Http request
566      * @return Html form
567      */
568     public String getManageUsers( HttpServletRequest request )
569     {
570         setPageTitleProperty( PROPERTY_PAGE_TITLE_MANAGE_USERS );
571 
572         AdminUser user = AdminUserService.getAdminUser( request );
573 
574         boolean rightRoles = false;
575 
576         if ( user.checkRight( RIGHT_MANAGE_WSSO_ROLES ) )
577         {
578             rightRoles = true;
579         }
580 
581         String strEmail = StringUtils.defaultString( request.getParameter( MARK_EMAIL ) );
582         String strUserLastName = StringUtils.defaultString( request.getParameter( MARK_LAST_NAME ) );
583         String strUserFirstName = StringUtils.defaultString( request.getParameter( MARK_FIRST_NAME ) );
584 
585         Collection<WssoUser> userList = WssoUserHome.findWssoUsersByLastNameOrFirstNameOrEmailByProfil(
586                 strUserLastName, strUserFirstName, strEmail, getPlugin( ) );
587         Map<String, Object> model = new HashMap<String, Object>( );
588         model.put( MARK_USERS_LIST, userList );
589         model.put( MARK_PLUGIN_NAME, getPlugin( ).getName( ) );
590         model.put( MARK_RIGHT_MANAGE_ROLES, rightRoles );
591         model.put( MARK_EMAIL, strEmail );
592         model.put( MARK_LAST_NAME, strUserLastName );
593         model.put( MARK_FIRST_NAME, strUserFirstName );
594 
595         HtmlTemplate template = AppTemplateService.getTemplate( TEMPLATE_MANAGE_USERS, getLocale( ), model );
596 
597         return getAdminPage( template.getHtml( ) );
598     }
599 
600     /**
601      * Returns profils management form
602      * 
603      * @param request The Http request
604      * @return Html form
605      */
606     public String getManageProfils( HttpServletRequest request )
607     {
608         setPageTitleProperty( PROPERTY_PAGE_TITLE_MANAGE_PROFILS );
609 
610         HashMap<String, Object> model = new HashMap<String, Object>( );
611 
612         // Reinit session
613         reinitItemNavigators( );
614 
615         String strURL = getHomeUrl( request );
616         UrlItem url = new UrlItem( strURL );
617 
618         _nDefaultItemsPerPage = AppPropertiesService.getPropertyInt( PROPERTY_PROFILS_PER_PAGE, 50 );
619         _strCurrentPageIndex = Paginator.getPageIndex( request, Paginator.PARAMETER_PAGE_INDEX, _strCurrentPageIndex );
620         _nItemsPerPage = Paginator.getItemsPerPage( request, Paginator.PARAMETER_ITEMS_PER_PAGE, _nItemsPerPage,
621                 _nDefaultItemsPerPage );
622 
623         // Get profils
624         List<WssoProfil> profilList = new ArrayList<WssoProfil>( );
625 
626         String searchCode = request.getParameter( MARK_AND_PARAMETER_SEARCH_CODE );
627         String searchDescription = request.getParameter( MARK_AND_PARAMETER_SEARCH_DESCRIPTION );
628 
629         if ( StringUtils.isNotBlank( searchCode ) && StringUtils.isNotBlank( searchDescription ) )
630         {
631             WssoProfil wssoProfil = WssoProfilHome.findWssoProfilByCodeAndDescription( searchCode.trim( ),
632                     searchDescription.trim( ), getPlugin( ) );
633 
634             if ( wssoProfil != null )
635             {
636                 profilList.add( wssoProfil );
637             }
638         }
639         else if ( StringUtils.isNotBlank( searchCode ) && StringUtils.isBlank( searchDescription ) )
640         {
641             WssoProfil wssoProfil = WssoProfilHome.findWssoProfilByCode( searchCode.trim( ), getPlugin( ) );
642 
643             if ( wssoProfil != null )
644             {
645                 profilList.add( wssoProfil );
646             }
647         }
648         else if ( StringUtils.isBlank( searchCode ) && StringUtils.isNotBlank( searchDescription ) )
649         {
650             List<WssoProfil> profilsByDescription = WssoProfilHome.findWssoProfilsByDescription(
651                     searchDescription.trim( ), getPlugin( ) );
652             profilList.addAll( profilsByDescription );
653         }
654         else
655         {
656             List<WssoProfil> allProfils = WssoProfilHome.findWssoProfilsList( getPlugin( ) );
657             profilList.addAll( allProfils );
658         }
659 
660         // SORT
661         _strSortedAttributeName = request.getParameter( Parameters.SORTED_ATTRIBUTE_NAME );
662 
663         String strAscSort = null;
664 
665         if ( _strSortedAttributeName != null )
666         {
667             strAscSort = request.getParameter( Parameters.SORTED_ASC );
668 
669             _bIsAscSort = Boolean.parseBoolean( strAscSort );
670 
671             Collections.sort( profilList, new AttributeComparator( _strSortedAttributeName, _bIsAscSort ) );
672         }
673 
674         if ( _strSortedAttributeName != null )
675         {
676             url.addParameter( Parameters.SORTED_ATTRIBUTE_NAME, _strSortedAttributeName );
677         }
678 
679         if ( strAscSort != null )
680         {
681             url.addParameter( Parameters.SORTED_ASC, strAscSort );
682         }
683 
684         LocalizedPaginator<WssoProfil> paginator = new LocalizedPaginator<WssoProfil>( profilList, _nItemsPerPage,
685                 url.getUrl( ), Paginator.PARAMETER_PAGE_INDEX, _strCurrentPageIndex, getLocale( ) );
686 
687         model.put( MARK_PROFILS_LIST, profilList );
688         model.put( MARK_PLUGIN_NAME, getPlugin( ).getName( ) );
689         model.put( MARK_AND_PARAMETER_SEARCH_CODE, searchCode );
690         model.put( MARK_AND_PARAMETER_SEARCH_DESCRIPTION, searchDescription );
691         model.put( MARK_NB_ITEMS_PER_PAGE, Integer.toString( _nItemsPerPage ) );
692         model.put( MARK_PAGINATOR, paginator );
693         model.put( MARK_PROFILS_LIST, paginator.getPageItems( ) );
694         model.put( MARK_PLUGIN_NAME, getPlugin( ).getName( ) );
695 
696         HtmlTemplate template = AppTemplateService.getTemplate( TEMPLATE_MANAGE_PROFILS, getLocale( ), model );
697 
698         return getAdminPage( template.getHtml( ) );
699     }
700 
701     /**
702      * Returns the profil modification form
703      * 
704      * @param request The Http request
705      * @return Html modification form
706      */
707     public String getModifyProfil( HttpServletRequest request )
708     {
709         setPageTitleProperty( PROPERTY_PAGE_TITLE_MANAGE_PROFILS );
710 
711         String mlWssoProfilCode = request.getParameter( PARAMETER_MYLUTECE_WSSO_PROFIL_CODE );
712 
713         if ( mlWssoProfilCode == null )
714         {
715             return getManageProfils( request );
716         }
717 
718         WssoProfil wssoProfil = WssoProfilHome.findWssoProfilByCode( mlWssoProfilCode, getPlugin( ) );
719 
720         if ( wssoProfil == null )
721         {
722             return getManageProfils( request );
723         }
724 
725         // ITEM NAVIGATION
726         List<WssoProfil> allProfils = WssoProfilHome.findWssoProfilsList( getPlugin( ) );
727         setItemNavigator( mlWssoProfilCode, AppPathService.getBaseUrl( request )
728                 + "jsp/admin/plugins/mylutece/modules/wssodatabase/ModifyProfil.jsp", allProfils );
729 
730         Map<String, Object> model = new HashMap<String, Object>( );
731 
732         model.put( MARK_PLUGIN_NAME, getPlugin( ).getName( ) );
733         model.put( MARK_PROFIL, wssoProfil );
734         model.put( MARK_LOCALE, getLocale( ) );
735         model.put( MARK_ITEM_NAVIGATOR, _itemNavigator );
736 
737         HtmlTemplate template = AppTemplateService.getTemplate( TEMPLATE_MODIFY_PROFIL, getLocale( ), model );
738 
739         return getAdminPage( template.getHtml( ) );
740     }
741 
742     /**
743      * Reinit the item navigator
744      */
745     private void reinitItemNavigators( )
746     {
747         _strSortedAttributeName = StringUtils.EMPTY;
748         _bIsAscSort = true;
749     }
750 
751     /**
752      * Returns roles management form for a specified user
753      * 
754      * @param request The Http request
755      * @return Html form
756      */
757     public String getManageRolesUser( HttpServletRequest request )
758     {
759         AdminUser adminUser = getUser( );
760 
761         setPageTitleProperty( PROPERTY_PAGE_TITLE_MANAGE_ROLES_USER );
762 
763         int nUserId = Integer.parseInt( request.getParameter( PARAMETER_MYLUTECE_WSSO_USER_ID ) );
764 
765         WssoUser user = WssoUserHome.findByPrimaryKey( nUserId, getPlugin( ) );
766 
767         Collection<Role> allRoleList = RoleHome.findAll( );
768         allRoleList = (ArrayList<Role>) RBACService.getAuthorizedCollection( allRoleList,
769                 RoleResourceIdService.PERMISSION_ASSIGN_ROLE, adminUser );
770 
771         Collection<String> userRoleList = WssoUserRoleHome.findRolesListForUser( nUserId, getPlugin( ) );
772 
773         List<WssoUser> allUsers = new ArrayList<WssoUser>( );
774         allUsers.addAll( WssoUserHome.findWssoUsersList( getPlugin( ) ) );
775         setItemNavigator( String.valueOf( nUserId ), AppPathService.getBaseUrl( request )
776                 + "jsp/admin/plugins/mylutece/modules/wssodatabase/ManageRolesUser.jsp", allUsers );
777 
778         Map<String, Object> model = new HashMap<String, Object>( );
779         model.put( MARK_ROLES_LIST, allRoleList );
780         model.put( MARK_ROLES_LIST_FOR_USER, userRoleList );
781         model.put( MARK_USER, user );
782         model.put( MARK_PLUGIN_NAME, getPlugin( ).getName( ) );
783         model.put( MARK_ITEM_NAVIGATOR, _itemNavigator );
784 
785         HtmlTemplate template = AppTemplateService.getTemplate( TEMPLATE_MANAGE_ROLES_USER, getLocale( ), model );
786 
787         return getAdminPage( template.getHtml( ) );
788     }
789 
790     /**
791      * Process assignation roles for a specified user
792      * 
793      * @param request The Http request
794      * @return Html form
795      */
796     public String doAssignRoleUser( HttpServletRequest request )
797     {
798         int nUserId = Integer.parseInt( request.getParameter( PARAMETER_MYLUTECE_WSSO_USER_ID ) );
799         WssoUser user = WssoUserHome.findByPrimaryKey( nUserId, getPlugin( ) );
800 
801         String[] roleArray = request.getParameterValues( PARAMETER_MYLUTECE_WSSO_ROLE_ID );
802 
803         WssoUserRoleHome.deleteRolesForUser( user.getMyluteceWssoUserId( ), getPlugin( ) );
804 
805         if ( roleArray != null )
806         {
807             for ( int i = 0; i < roleArray.length; i++ )
808             {
809                 WssoUserRoleHome.createRoleForUser( nUserId, roleArray[i], getPlugin( ) );
810             }
811         }
812 
813         return MANAGE_USERS + "?" + PARAMETER_PLUGIN_NAME + "=" + getPlugin( ).getName( );
814     }
815 
816     /**
817      * Get the item navigator
818      * @param idElement the id of the element
819      * @param strUrl the url
820      * @param listElements the list of elements
821      */
822     private void setItemNavigator( String idElement, String strUrl, List<?> listElements )
823     {
824         if ( _itemNavigator == null )
825         {
826             List<String> listIds = new ArrayList<String>( );
827             int nCurrentItemId = 0;
828             int nIndex = 0;
829             boolean profil = false;
830             boolean user = false;
831 
832             for ( Object element : listElements )
833             {
834                 if ( element instanceof WssoProfil )
835                 {
836                     String code = ( (WssoProfil) element ).getCode( );
837                     listIds.add( code );
838 
839                     if ( code.equals( idElement ) )
840                     {
841                         nCurrentItemId = nIndex;
842                     }
843 
844                     profil = true;
845                     nIndex++;
846                 }
847                 else if ( element instanceof WssoUser )
848                 {
849                     String idUser = String.valueOf( ( (WssoUser) element ).getMyluteceWssoUserId( ) );
850                     listIds.add( idUser );
851 
852                     if ( idUser.equals( idElement ) )
853                     {
854                         nCurrentItemId = nIndex;
855                     }
856 
857                     user = true;
858                     nIndex++;
859                 }
860             }
861 
862             String iterateur = "";
863 
864             if ( profil )
865             {
866                 iterateur = PARAMETER_MYLUTECE_WSSO_PROFIL_CODE;
867             }
868             else if ( user )
869             {
870                 iterateur = PARAMETER_MYLUTECE_WSSO_USER_ID;
871             }
872 
873             _itemNavigator = new ItemNavigator( listIds, nCurrentItemId, strUrl, iterateur );
874         }
875         else
876         {
877             _itemNavigator.setCurrentItemId( idElement );
878             _itemNavigator.setBaseUrl( strUrl );
879         }
880     }
881 
882     /**
883      * Returns roles management form for a specified profil
884      * 
885      * @param request The Http request
886      * @return Html form
887      */
888     public String getManageRolesProfil( HttpServletRequest request )
889     {
890         setPageTitleProperty( PROPERTY_PAGE_TITLE_MANAGE_ROLES_PROFIL );
891 
892         String mlWssoProfilCode = request.getParameter( PARAMETER_MYLUTECE_WSSO_PROFIL_CODE );
893 
894         if ( mlWssoProfilCode == null )
895         {
896             return getManageProfils( request );
897         }
898 
899         WssoProfil wssoProfil = WssoProfilHome.findWssoProfilByCode( mlWssoProfilCode, getPlugin( ) );
900 
901         if ( wssoProfil == null )
902         {
903             return getManageProfils( request );
904         }
905 
906         Collection<Role> allRoleList = RoleHome.findAll( );
907 
908         List<String> profilRoleKeyList = IdxWSSODatabaseHome.findRolesFromProfil( wssoProfil.getCode( ), getPlugin( ) );
909         Collection<Role> profilRoleList = new ArrayList<Role>( );
910 
911         for ( String strRoleKey : profilRoleKeyList )
912         {
913             for ( Role role : allRoleList )
914             {
915                 if ( role.getRole( ).equals( strRoleKey ) )
916                 {
917                     profilRoleList.add( RoleHome.findByPrimaryKey( strRoleKey ) );
918                 }
919             }
920         }
921 
922         // ITEM NAVIGATION
923         List<WssoProfil> allProfils = WssoProfilHome.findWssoProfilsList( getPlugin( ) );
924         setItemNavigator( mlWssoProfilCode, AppPathService.getBaseUrl( request )
925                 + "jsp/admin/plugins/mylutece/modules/wssodatabase/ManageRolesProfil.jsp", allProfils );
926 
927         Map<String, Object> model = new HashMap<String, Object>( );
928         model.put( MARK_ROLES_LIST, allRoleList );
929         model.put( MARK_ROLES_LIST_FOR_USER, profilRoleList );
930         model.put( MARK_PROFIL, wssoProfil );
931         model.put( MARK_PLUGIN_NAME, getPlugin( ).getName( ) );
932         model.put( MARK_ITEM_NAVIGATOR, _itemNavigator );
933 
934         HtmlTemplate template = AppTemplateService.getTemplate( TEMPLATE_MANAGE_ROLES_PROFIL, getLocale( ), model );
935 
936         return getAdminPage( template.getHtml( ) );
937     }
938 
939     /**
940      * Assign roles to a profil
941      * @param request HttpServletRequest
942      * @return JSP return
943      */
944     public String doManageRolesProfil( HttpServletRequest request )
945     {
946         String mlWssoProfilCode = request.getParameter( PARAMETER_MYLUTECE_WSSO_PROFIL_CODE );
947 
948         if ( mlWssoProfilCode == null )
949         {
950             return getManageProfils( request );
951         }
952 
953         WssoProfil wssoProfil = WssoProfilHome.findWssoProfilByCode( mlWssoProfilCode, getPlugin( ) );
954 
955         if ( wssoProfil == null )
956         {
957             return getManageProfils( request );
958         }
959 
960         String[] roleArray = request.getParameterValues( PARAMETER_MYLUTECE_DATABASE_ROLE_IDS );
961 
962         IdxWSSODatabaseHome.removeRolesForProfil( wssoProfil.getCode( ), getPlugin( ) );
963 
964         if ( roleArray != null )
965         {
966             for ( int i = 0; i < roleArray.length; i++ )
967             {
968                 IdxWSSODatabaseHome.addRoleForProfil( wssoProfil.getCode( ), roleArray[i], getPlugin( ) );
969             }
970         }
971 
972         return MANAGE_ROLES_PROFIL + "?" + PARAMETER_PLUGIN_NAME + "=" + getPlugin( ).getName( ) + "&"
973                 + PARAMETER_MYLUTECE_WSSO_PROFIL_CODE + "=" + mlWssoProfilCode;
974     }
975 
976     /**
977      * Returns roles management form for a specified user
978      * 
979      * @param request The Http request
980      * @return Html form
981      */
982     public String getManageProfilsUser( HttpServletRequest request )
983     {
984         setPageTitleProperty( PROPERTY_PAGE_TITLE_MANAGE_PROFILS_USER );
985 
986         String strUserId = request.getParameter( PARAMETER_MYLUTECE_WSSO_USER_ID );
987 
988         if ( StringUtils.isBlank( strUserId ) )
989         {
990             return getManageUsers( request );
991         }
992 
993         int nUserId = Integer.parseInt( strUserId );
994 
995         WssoUser wssoUser = WssoUserHome.findByPrimaryKey( nUserId, getPlugin( ) );
996 
997         if ( wssoUser == null )
998         {
999             return getManageUsers( request );
1000         }
1001 
1002         Collection<WssoProfil> allWssoProfilList = WssoProfilHome.findWssoProfilsList( getPlugin( ) );
1003 
1004         List<String> profilKeyList = WssoProfilHome.findWssoProfilsForUser( wssoUser.getMyluteceWssoUserId( ),
1005                 getPlugin( ) );
1006 
1007         Collection<WssoProfil> profilList = new ArrayList<WssoProfil>( );
1008 
1009         for ( String strProfilKey : profilKeyList )
1010         {
1011             for ( WssoProfil wssoProfil : allWssoProfilList )
1012             {
1013                 if ( wssoProfil.getCode( ).equals( strProfilKey ) )
1014                 {
1015                     profilList.add( WssoProfilHome.findWssoProfilByCode( strProfilKey, getPlugin( ) ) );
1016                 }
1017             }
1018         }
1019 
1020         // ITEM NAVIGATION
1021         List<WssoUser> allUsers = new ArrayList<WssoUser>( );
1022         allUsers.addAll( WssoUserHome.findWssoUsersList( getPlugin( ) ) );
1023         setItemNavigator( strUserId, AppPathService.getBaseUrl( request )
1024                 + "jsp/admin/plugins/mylutece/modules/wssodatabase/ManageProfilsUser.jsp", allUsers );
1025 
1026         AdminUser user = AdminUserService.getAdminUser( request );
1027 
1028         boolean rightRoles = false;
1029 
1030         if ( user.checkRight( RIGHT_MANAGE_WSSO_ROLES ) )
1031         {
1032             rightRoles = true;
1033         }
1034 
1035         Map<String, Object> model = new HashMap<String, Object>( );
1036         model.put( MARK_PROFILS_LIST, allWssoProfilList );
1037         model.put( MARK_PROFILS_LIST_FOR_USER, profilList );
1038         model.put( MARK_USER, wssoUser );
1039         model.put( MARK_PLUGIN_NAME, getPlugin( ).getName( ) );
1040         model.put( MARK_ITEM_NAVIGATOR, _itemNavigator );
1041         model.put( MARK_RIGHT_MANAGE_ROLES, rightRoles );
1042 
1043         HtmlTemplate template = AppTemplateService.getTemplate( TEMPLATE_MANAGE_PROFILS_USER, getLocale( ), model );
1044 
1045         return getAdminPage( template.getHtml( ) );
1046     }
1047 
1048     /**
1049      * Assign profils to a user
1050      * @param request HttpServletRequest
1051      * @return JSP return
1052      */
1053     public String doManageProfilsUser( HttpServletRequest request )
1054     {
1055         String strUserId = request.getParameter( PARAMETER_MYLUTECE_WSSO_USER_ID );
1056 
1057         if ( StringUtils.isBlank( strUserId ) )
1058         {
1059             return getManageUsers( request );
1060         }
1061 
1062         int nWssoUserId = Integer.parseInt( strUserId );
1063 
1064         WssoUser wssoUser = WssoUserHome.findByPrimaryKey( nWssoUserId, getPlugin( ) );
1065 
1066         if ( wssoUser == null )
1067         {
1068             return getManageUsers( request );
1069         }
1070 
1071         String[] profilArray = request.getParameterValues( PARAMETER_MYLUTECE_WSSO_PROFIL_CODE );
1072 
1073         IdxWSSODatabaseHome.removeProfilsForUser( nWssoUserId, getPlugin( ) );
1074 
1075         if ( profilArray != null )
1076         {
1077             for ( int i = 0; i < profilArray.length; i++ )
1078             {
1079                 IdxWSSODatabaseHome.addUserForProfil( nWssoUserId, profilArray[i], getPlugin( ) );
1080             }
1081         }
1082 
1083         return MANAGE_PROFILS_USER + "?" + PARAMETER_MYLUTECE_WSSO_USER_ID + "=" + nWssoUserId;
1084     }
1085 
1086     /**
1087      * Returns users management form for a specified profil
1088      * 
1089      * @param request The Http request
1090      * @return Html form
1091      */
1092     public String getManageUsersProfil( HttpServletRequest request )
1093     {
1094         setPageTitleProperty( PROPERTY_PAGE_TITLE_MANAGE_USERS_PROFIL );
1095 
1096         String mlWssoProfilCode = request.getParameter( PARAMETER_MYLUTECE_WSSO_PROFIL_CODE );
1097 
1098         if ( mlWssoProfilCode == null )
1099         {
1100             return getManageProfils( request );
1101         }
1102 
1103         WssoProfil wssoProfil = WssoProfilHome.findWssoProfilByCode( mlWssoProfilCode, getPlugin( ) );
1104 
1105         if ( wssoProfil == null )
1106         {
1107             return getManageProfils( request );
1108         }
1109 
1110         Map<String, Object> model = new HashMap<String, Object>( );
1111         String strURL = AppPathService.getBaseUrl( request ) + JSP_URL_MANAGE_USERS_PROFIL;
1112         UrlItem url = new UrlItem( strURL );
1113 
1114         String searchLastName = request.getParameter( "search_last_name" );
1115         String searchFirstName = request.getParameter( "search_first_name" );
1116         String searchEmail = request.getParameter( "search_email" );
1117 
1118         // ASSIGNED USERS
1119         List<WssoUser> listAllAssignedUsers = WssoUserHome.findWssoUserssByLastNameOrFirtNameOrEmailByProfil(
1120                 wssoProfil.getCode( ), searchLastName, searchFirstName, searchEmail, getPlugin( ) );
1121 
1122         // AVAILABLE USERS
1123         ReferenceList listAvailableUsers = getAvailableUsers( listAllAssignedUsers );
1124 
1125         // SORT
1126         String strSortedAttributeName = request.getParameter( Parameters.SORTED_ATTRIBUTE_NAME );
1127         String strAscSort = null;
1128 
1129         if ( strSortedAttributeName != null )
1130         {
1131             strAscSort = request.getParameter( Parameters.SORTED_ASC );
1132 
1133             boolean bIsAscSort = Boolean.parseBoolean( strAscSort );
1134 
1135             Collections.sort( listAvailableUsers, new AttributeComparator( strSortedAttributeName, bIsAscSort ) );
1136         }
1137 
1138         _strCurrentPageIndex = Paginator.getPageIndex( request, Paginator.PARAMETER_PAGE_INDEX, _strCurrentPageIndex );
1139         _nDefaultItemsPerPage = AppPropertiesService.getPropertyInt( PROPERTY_PROFILS_PER_PAGE, 50 );
1140         _nItemsPerPage = Paginator.getItemsPerPage( request, Paginator.PARAMETER_ITEMS_PER_PAGE, _nItemsPerPage,
1141                 _nDefaultItemsPerPage );
1142 
1143         if ( strSortedAttributeName != null )
1144         {
1145             url.addParameter( Parameters.SORTED_ATTRIBUTE_NAME, strSortedAttributeName );
1146         }
1147 
1148         if ( strAscSort != null )
1149         {
1150             url.addParameter( Parameters.SORTED_ASC, strAscSort );
1151         }
1152 
1153         // ITEM NAVIGATION
1154         setItemNavigator( mlWssoProfilCode, AppPathService.getBaseUrl( request )
1155                 + "jsp/admin/plugins/mylutece/modules/wssodatabase/ManageUsersProfil.jsp", listAllAssignedUsers );
1156 
1157         LocalizedPaginator<WssoUser> paginator = new LocalizedPaginator<WssoUser>( listAllAssignedUsers,
1158                 _nItemsPerPage, url.getUrl( ), Paginator.PARAMETER_PAGE_INDEX, _strCurrentPageIndex, getLocale( ) );
1159 
1160         model.put( MARK_PLUGIN_NAME, getPlugin( ).getName( ) );
1161         model.put( MARK_PROFIL, wssoProfil );
1162         model.put( MARK_ITEM_NAVIGATOR, _itemNavigator );
1163         model.put( MARK_PAGINATOR, paginator );
1164         model.put( MARK_NB_ITEMS_PER_PAGE, Integer.toString( _nItemsPerPage ) );
1165         model.put( MARK_AVAILABLE_USERS, listAvailableUsers );
1166         model.put( MARK_ASSIGNED_USERS, paginator.getPageItems( ) );
1167         model.put( MARK_ASSIGNED_USERS_NUMBER, listAllAssignedUsers.size( ) );
1168         model.put( MARK_AND_PARAMETER_SEARCH_LASTNAME, searchLastName );
1169         model.put( MARK_AND_PARAMETER_SEARCH_FIRSTNAME, searchFirstName );
1170         model.put( MARK_AND_PARAMETER_SEARCH_EMAIL, searchEmail );
1171 
1172         HtmlTemplate template = AppTemplateService.getTemplate( TEMPLATE_MANAGE_USERS_PROFIL, getLocale( ), model );
1173 
1174         return getAdminPage( template.getHtml( ) );
1175     }
1176 
1177     /**
1178      * Get the list of avaivable users
1179      * @param listAssignedUsers the list of assigned users
1180      * @return a {@link ReferenceList}
1181      */
1182     private ReferenceList getAvailableUsers( List<WssoUser> listAssignedUsers )
1183     {
1184         ReferenceList listAvailableUsers = new ReferenceList( );
1185 
1186         for ( WssoUser user : (Collection<WssoUser>) WssoUserHome.findWssoUsersList( getPlugin( ) ) )
1187         {
1188             boolean bIsAvailable = Boolean.TRUE;
1189 
1190             for ( WssoUser assignedUser : listAssignedUsers )
1191             {
1192                 if ( user.getMyluteceWssoUserId( ) == assignedUser.getMyluteceWssoUserId( ) )
1193                 {
1194                     bIsAvailable = Boolean.FALSE;
1195 
1196                     break;
1197                 }
1198             }
1199 
1200             if ( bIsAvailable )
1201             {
1202                 ReferenceItem userItem = new ReferenceItem( );
1203                 userItem.setCode( String.valueOf( user.getMyluteceWssoUserId( ) ) );
1204                 userItem.setName( user.getLastName( ) + SPACE + user.getFirstName( ) );
1205                 listAvailableUsers.add( userItem );
1206             }
1207         }
1208 
1209         return listAvailableUsers;
1210     }
1211 
1212     /**
1213      * Assign users to a profil
1214      * @param request HttpServletRequest
1215      * @return JSP return
1216      */
1217     public String doManageUsersProfil( HttpServletRequest request )
1218     {
1219         setPageTitleProperty( PROPERTY_PAGE_TITLE_MANAGE_PROFILS );
1220 
1221         String mlWssoProfilCode = request.getParameter( PARAMETER_MYLUTECE_WSSO_PROFIL_CODE );
1222 
1223         if ( mlWssoProfilCode == null )
1224         {
1225             return getManageProfils( request );
1226         }
1227 
1228         WssoProfil wssoProfil = WssoProfilHome.findWssoProfilByCode( mlWssoProfilCode, getPlugin( ) );
1229 
1230         if ( wssoProfil == null )
1231         {
1232             return getManageProfils( request );
1233         }
1234 
1235         //retrieve the selected portlets ids
1236         String[] arrayUsersIds = request.getParameterValues( PARAMETER_AVAILABLE_USERS );
1237 
1238         if ( ( arrayUsersIds != null ) )
1239         {
1240             for ( int i = 0; i < arrayUsersIds.length; i++ )
1241             {
1242                 int nUserId = Integer.parseInt( arrayUsersIds[i] );
1243                 WssoUser user = WssoUserHome.findByPrimaryKey( nUserId, getPlugin( ) );
1244 
1245                 if ( user != null )
1246                 {
1247                     IdxWSSODatabaseHome.addUserForProfil( nUserId, wssoProfil.getCode( ), getPlugin( ) );
1248                 }
1249 
1250             }
1251         }
1252 
1253         return getManageUsersProfil( request );
1254     }
1255 
1256     /**
1257      * Returns removal user's form
1258      * 
1259      * @param request The Http request
1260      * @return Html form
1261      */
1262     public String getUnassignUserProfil( HttpServletRequest request )
1263     {
1264         String mlWssoProfilCode = request.getParameter( PARAMETER_MYLUTECE_WSSO_PROFIL_CODE );
1265 
1266         if ( mlWssoProfilCode == null )
1267         {
1268             return AdminMessageService.getMessageUrl( request, MESSAGE_ERROR_REMOVE_PROFIL, AdminMessage.TYPE_STOP );
1269         }
1270 
1271         String assignedUseId = request.getParameter( MARK_AND_PARAMETER_ASSIGNED_USER_ID );
1272 
1273         if ( assignedUseId == null )
1274         {
1275             return AdminMessageService.getMessageUrl( request, MESSAGE_ERROR_REMOVE_PROFIL, AdminMessage.TYPE_STOP );
1276         }
1277 
1278         UrlItem url = new UrlItem( JSP_DO_REMOVE_ASIGN_USER_PROFIL );
1279         url.addParameter( PARAMETER_PLUGIN_NAME, getPlugin( ).getName( ) );
1280         url.addParameter( PARAMETER_MYLUTECE_WSSO_PROFIL_CODE, mlWssoProfilCode );
1281         url.addParameter( MARK_AND_PARAMETER_ASSIGNED_USER_ID, assignedUseId );
1282 
1283         return AdminMessageService.getMessageUrl( request, MESSAGE_CONFIRM_REMOVE_ASSIGN_PROFIL_USER, url.getUrl( ),
1284                 AdminMessage.TYPE_CONFIRMATION );
1285     }
1286 
1287     /**
1288      * Process user's removal
1289      * 
1290      * @param request The Http request
1291      * @return The Jsp management URL of the process result
1292      */
1293     public String doUnassignUserProfil( HttpServletRequest request )
1294     {
1295         String mlWssoProfilCode = request.getParameter( PARAMETER_MYLUTECE_WSSO_PROFIL_CODE );
1296 
1297         if ( mlWssoProfilCode == null )
1298         {
1299             return AdminMessageService.getMessageUrl( request, MESSAGE_ERROR_REMOVE_PROFIL, AdminMessage.TYPE_STOP );
1300         }
1301 
1302         WssoProfil wssoProfil = WssoProfilHome.findWssoProfilByCode( mlWssoProfilCode, getPlugin( ) );
1303 
1304         if ( wssoProfil == null )
1305         {
1306             return AdminMessageService.getMessageUrl( request, MESSAGE_ERROR_REMOVE_PROFIL, AdminMessage.TYPE_STOP );
1307         }
1308 
1309         String assignedUseId = request.getParameter( MARK_AND_PARAMETER_ASSIGNED_USER_ID );
1310 
1311         if ( assignedUseId == null )
1312         {
1313             return AdminMessageService.getMessageUrl( request, MESSAGE_ERROR_REMOVE_PROFIL, AdminMessage.TYPE_STOP );
1314         }
1315 
1316         WssoUser assignedUser = WssoUserHome.findByPrimaryKey( Integer.valueOf( assignedUseId ), getPlugin( ) );
1317 
1318         if ( assignedUser == null )
1319         {
1320             return AdminMessageService.getMessageUrl( request, MESSAGE_ERROR_REMOVE_PROFIL, AdminMessage.TYPE_STOP );
1321         }
1322 
1323         IdxWSSODatabaseHome.removeUserForProfil( assignedUser.getMyluteceWssoUserId( ), wssoProfil.getCode( ),
1324                 getPlugin( ) );
1325 
1326         return getManageUsersProfil( request );
1327     }
1328 
1329     /**
1330      * Get a page to export users
1331      * @param request The request
1332      * @return The html content
1333      */
1334     public String getExportUsers( HttpServletRequest request )
1335     {
1336         setPageTitleProperty( PROPERTY_PAGE_TITLE_MANAGE_USERS );
1337 
1338         Map<String, Object> model = new HashMap<String, Object>( );
1339 
1340         ReferenceList refListXsl = XslExportHome.getRefListByPlugin( getPlugin( ) );
1341 
1342         model.put( MARK_LIST_XSL_EXPORT, refListXsl );
1343 
1344         HtmlTemplate template = AppTemplateService.getTemplate( TEMPLATE_EXPORT_USERS_FROM_FILE,
1345                 AdminUserService.getLocale( request ), model );
1346 
1347         return getAdminPage( template.getHtml( ) );
1348     }
1349 
1350     /**
1351      * Do export users
1352      * @param request The request
1353      * @param response The response
1354      * @return A DefaultPluginActionResult containing the result, or null if the
1355      *         file download has been initialized
1356      * @throws IOException If an IOException occurs
1357      */
1358     public DefaultPluginActionResult doExportUsers( HttpServletRequest request, HttpServletResponse response )
1359             throws IOException
1360     {
1361         Plugin plugin = getPlugin( );
1362 
1363         DefaultPluginActionResult result = new DefaultPluginActionResult( );
1364 
1365         String strXslExportId = request.getParameter( PARAMETER_XSL_EXPORT_ID );
1366         String strExportProfils = request.getParameter( PARAMETER_EXPORT_PROFILS );
1367         String strExportRoles = request.getParameter( PARAMETER_EXPORT_ROLES );
1368         String strExportGroups = request.getParameter( PARAMETER_EXPORT_GROUPS );
1369         boolean bExportProfils = StringUtils.isNotEmpty( strExportProfils );
1370         boolean bExportRoles = StringUtils.isNotEmpty( strExportRoles );
1371         boolean bExportGroups = StringUtils.isNotEmpty( strExportGroups );
1372 
1373         if ( StringUtils.isBlank( strXslExportId ) )
1374         {
1375             Object[] tabRequiredFields = { I18nService.getLocalizedString( FIELD_XSL_EXPORT, getLocale( ) ) };
1376             result.setRedirect( AdminMessageService.getMessageUrl( request, MESSAGE_MANDATORY_FIELD, tabRequiredFields,
1377                     AdminMessage.TYPE_STOP ) );
1378 
1379             return result;
1380         }
1381 
1382         int nIdXslExport = Integer.parseInt( strXslExportId );
1383 
1384         XslExport xslExport = XslExportHome.findByPrimaryKey( nIdXslExport );
1385 
1386         Collection<WssoUser> listUsers = WssoUserHome.findWssoUsersList( plugin );
1387 
1388         StringBuffer sbXml = new StringBuffer( XmlUtil.getXmlHeader( ) );
1389         XmlUtil.beginElement( sbXml, CONSTANT_XML_USERS );
1390 
1391         List<IAttribute> listAttributes = AttributeHome.findAll( getLocale( ),
1392                 PluginService.getPlugin( MyLutecePlugin.PLUGIN_NAME ) );
1393 
1394         for ( WssoUser user : listUsers )
1395         {
1396             sbXml.append( _databaseService.getXmlFromUser( user, bExportRoles, bExportGroups, bExportProfils,
1397                     listAttributes, getLocale( ) ) );
1398         }
1399 
1400         XmlUtil.endElement( sbXml, CONSTANT_XML_USERS );
1401 
1402         String strXml = StringUtil.replaceAccent( sbXml.toString( ) );
1403         String strExportedUsers = XslExportService.exportXMLWithXSL( nIdXslExport, strXml );
1404 
1405         if ( CONSTANT_MIME_TYPE_CSV.contains( xslExport.getExtension( ) ) )
1406         {
1407             response.setContentType( CONSTANT_MIME_TYPE_CSV );
1408         }
1409         else if ( CONSTANT_EXTENSION_XML_FILE.contains( xslExport.getExtension( ) ) )
1410         {
1411             response.setContentType( CONSTANT_MIME_TYPE_XML );
1412         }
1413         else
1414         {
1415             response.setContentType( CONSTANT_MIME_TYPE_OCTETSTREAM );
1416         }
1417 
1418         String strFileName = CONSTANT_EXPORT_USERS_FILE_NAME + CONSTANT_POINT + xslExport.getExtension( );
1419         response.setHeader( CONSTANT_ATTACHEMENT_DISPOSITION, CONSTANT_ATTACHEMENT_FILE_NAME + strFileName
1420                 + CONSTANT_QUOTE );
1421 
1422         PrintWriter out = response.getWriter( );
1423         out.write( strExportedUsers );
1424         out.flush( );
1425         out.close( );
1426 
1427         return null;
1428     }
1429 
1430     /**
1431      * Get a page to import users from a CSV file.
1432      * @param request The request
1433      * @return The HTML content
1434      */
1435     public String getImportUsersFromFile( HttpServletRequest request )
1436     {
1437         setPageTitleProperty( PROPERTY_IMPORT_USERS_FROM_FILE_PAGETITLE );
1438 
1439         Map<String, Object> model = new HashMap<String, Object>( );
1440 
1441         model.put( MARK_LIST_MESSAGES, request.getAttribute( ATTRIBUTE_IMPORT_USERS_LIST_MESSAGES ) );
1442 
1443         String strCsvSeparator = StringUtils.EMPTY + _importWssoDatabaseUserService.getCSVSeparator( );
1444         String strCsvEscapeCharacter = StringUtils.EMPTY + _importWssoDatabaseUserService.getCSVEscapeCharacter( );
1445         String strAttributesSeparator = StringUtils.EMPTY + _importWssoDatabaseUserService.getAttributesSeparator( );
1446         model.put( MARK_CSV_SEPARATOR, strCsvSeparator );
1447         model.put( MARK_CSV_ESCAPE, strCsvEscapeCharacter );
1448         model.put( MARK_ATTRIBUTES_SEPARATOR, strAttributesSeparator );
1449 
1450         HtmlTemplate template = AppTemplateService.getTemplate( TEMPLATE_IMPORT_USERS_FROM_FILE,
1451                 AdminUserService.getLocale( request ), model );
1452 
1453         return getAdminPage( template.getHtml( ) );
1454     }
1455 
1456     /**
1457      * Do import users from a CSV file
1458      * @param request The request
1459      * @return A DefaultPluginActionResult with the URL of the page to display,
1460      *         or the HTML content
1461      */
1462     public DefaultPluginActionResult doImportUsersFromFile( HttpServletRequest request )
1463     {
1464         DefaultPluginActionResult result = new DefaultPluginActionResult( );
1465 
1466         if ( request instanceof MultipartHttpServletRequest )
1467         {
1468             MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
1469             FileItem fileItem = multipartRequest.getFile( PARAMETER_IMPORT_USERS_FILE );
1470             String strMimeType = FileSystemUtil.getMIMEType( FileUploadService.getFileNameOnly( fileItem ) );
1471 
1472             if ( !( ( fileItem != null ) && !StringUtils.EMPTY.equals( fileItem.getName( ) ) ) )
1473             {
1474                 Object[] tabRequiredFields = { I18nService.getLocalizedString( FIELD_IMPORT_USERS_FILE, getLocale( ) ) };
1475                 result.setRedirect( AdminMessageService.getMessageUrl( request, MESSAGE_MANDATORY_FIELD,
1476                         tabRequiredFields, AdminMessage.TYPE_STOP ) );
1477 
1478                 return result;
1479             }
1480 
1481             if ( ( !strMimeType.equals( CONSTANT_MIME_TYPE_CSV )
1482                     && !strMimeType.equals( CONSTANT_MIME_TYPE_OCTETSTREAM ) && !strMimeType
1483                         .equals( CONSTANT_MIME_TYPE_TEXT_CSV ) )
1484                     || !fileItem.getName( ).toLowerCase( ).endsWith( CONSTANT_EXTENSION_CSV_FILE ) )
1485             {
1486                 result.setRedirect( AdminMessageService.getMessageUrl( request, MESSAGE_ERROR_CSV_FILE_IMPORT,
1487                         AdminMessage.TYPE_STOP ) );
1488 
1489                 return result;
1490             }
1491 
1492             String strSkipFirstLine = multipartRequest.getParameter( PARAMETER_SKIP_FIRST_LINE );
1493             boolean bSkipFirstLine = StringUtils.isNotEmpty( strSkipFirstLine );
1494             String strUpdateUsers = multipartRequest.getParameter( PARAMETER_UPDATE_USERS );
1495             boolean bUpdateUsers = StringUtils.isNotEmpty( strUpdateUsers );
1496             _importWssoDatabaseUserService.setUpdateExistingUsers( bUpdateUsers );
1497 
1498             List<CSVMessageDescriptor> listMessages = _importWssoDatabaseUserService.readCSVFile( fileItem, 0, false,
1499                     false, bSkipFirstLine, AdminUserService.getLocale( request ), AppPathService.getBaseUrl( request ) );
1500 
1501             request.setAttribute( ATTRIBUTE_IMPORT_USERS_LIST_MESSAGES, listMessages );
1502 
1503             String strHtmlResult = getImportUsersFromFile( request );
1504             result.setHtmlContent( strHtmlResult );
1505         }
1506         else
1507         {
1508             Object[] tabRequiredFields = { I18nService.getLocalizedString( FIELD_IMPORT_USERS_FILE, getLocale( ) ) };
1509             result.setRedirect( AdminMessageService.getMessageUrl( request, MESSAGE_MANDATORY_FIELD, tabRequiredFields,
1510                     AdminMessage.TYPE_STOP ) );
1511         }
1512 
1513         return result;
1514     }
1515 
1516     /**
1517      * Notify a user of the creation of his account and give him his credentials
1518      * @param user the user to notify
1519      * @param locale The locale
1520      * @param strProdUrl The prod URL
1521      */
1522     private void notifyUserAccountCreated( WssoUser user, Locale locale, String strProdUrl )
1523     {
1524         String strSenderEmail = AppPropertiesService.getProperty( PROPERTY_NO_REPLY_EMAIL );
1525         String strSiteName = AppPropertiesService.getProperty( PROPERTY_SITE_NAME );
1526 
1527         String strEmailSubject = I18nService.getLocalizedString( MESSAGE_ACCOUNT_IMPORTED_MAIL_SUBJECT,
1528                 new String[] { strSiteName }, locale );
1529         String strBaseURL = strProdUrl;
1530         Map<String, Object> model = new HashMap<String, Object>( );
1531         model.put( MARK_USER, user );
1532         model.put( MARK_SITE_NAME, strSiteName );
1533         model.put( MARK_SITE_LINK, MailService.getSiteLink( strBaseURL, true ) );
1534 
1535         HtmlTemplate template = AppTemplateService.getTemplate( TEMPLATE_MAIL_USER_IMPORTED, locale, model );
1536 
1537         MailService
1538                 .sendMailHtml( user.getEmail( ), strSenderEmail, strSenderEmail, strEmailSubject, template.getHtml( ) );
1539     }
1540 }