AdminMenuJspBean.java

  1. /*
  2.  * Copyright (c) 2002-2022, City of 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.portal.web.admin;

  35. import java.io.Serializable;
  36. import java.util.ArrayList;
  37. import java.util.Collections;
  38. import java.util.HashMap;
  39. import java.util.List;
  40. import java.util.Locale;
  41. import java.util.Map;

  42. import javax.servlet.http.HttpServletRequest;

  43. import org.apache.commons.collections.CollectionUtils;
  44. import org.apache.commons.lang3.StringUtils;
  45. import org.apache.logging.log4j.LogManager;
  46. import org.apache.logging.log4j.Logger;

  47. import fr.paris.lutece.portal.business.right.FeatureGroup;
  48. import fr.paris.lutece.portal.business.right.FeatureGroupHome;
  49. import fr.paris.lutece.portal.business.right.Right;
  50. import fr.paris.lutece.portal.business.user.AdminUser;
  51. import fr.paris.lutece.portal.business.user.AdminUserHome;
  52. import fr.paris.lutece.portal.business.user.authentication.LuteceDefaultAdminUser;
  53. import fr.paris.lutece.portal.business.user.menu.AccessibilityModeAdminUserMenuItemProvider;
  54. import fr.paris.lutece.portal.business.user.menu.LanguageAdminUserMenuItemProvider;
  55. import fr.paris.lutece.portal.service.admin.AccessDeniedException;
  56. import fr.paris.lutece.portal.service.admin.AdminUserService;
  57. import fr.paris.lutece.portal.service.dashboard.DashboardService;
  58. import fr.paris.lutece.portal.service.dashboard.IDashboardComponent;
  59. import fr.paris.lutece.portal.service.datastore.DatastoreService;
  60. import fr.paris.lutece.portal.service.init.AppInfo;
  61. import fr.paris.lutece.portal.service.message.AdminMessage;
  62. import fr.paris.lutece.portal.service.message.AdminMessageService;
  63. import fr.paris.lutece.portal.service.plugin.Plugin;
  64. import fr.paris.lutece.portal.service.plugin.PluginService;
  65. import fr.paris.lutece.portal.service.portal.PortalService;
  66. import fr.paris.lutece.portal.service.security.SecurityTokenService;
  67. import fr.paris.lutece.portal.service.spring.SpringContextService;
  68. import fr.paris.lutece.portal.service.template.AppTemplateService;
  69. import fr.paris.lutece.portal.service.user.menu.AdminUserMenuService;
  70. import fr.paris.lutece.portal.service.util.AppLogService;
  71. import fr.paris.lutece.portal.service.util.AppPathService;
  72. import fr.paris.lutece.portal.service.util.AppPropertiesService;
  73. import fr.paris.lutece.portal.web.constants.Markers;
  74. import fr.paris.lutece.portal.web.constants.Messages;
  75. import fr.paris.lutece.portal.web.constants.Parameters;
  76. import fr.paris.lutece.portal.web.l10n.LocaleService;
  77. import fr.paris.lutece.util.html.HtmlTemplate;
  78. import fr.paris.lutece.util.password.IPassword;
  79. import fr.paris.lutece.util.password.IPasswordFactory;

  80. /**
  81.  * This class provides the user interface to manage admin features ( manage, create, modify, remove)
  82.  */
  83. public class AdminMenuJspBean implements Serializable
  84. {
  85.     // ///////////////////////////////////////////////////////////////////////////////
  86.     // Constants
  87.     private static final String ERROR_INVALID_TOKEN = "Invalid security token";
  88.     public static final String PROPERTY_LOGOUT_URL = "lutece.admin.logout.url";
  89.     public static final String PROPERTY_MENU_DEFAULT_POS = "top";
  90.     public static final String PROPERTY_MENU_DATASTORE_POS = "portal.site.site_property.menu.position";
  91.     private static final long serialVersionUID = -8939026727319948581L;

  92.     // Markers
  93.     private static final String MARK_FEATURE_GROUP_LIST = "feature_group_list";
  94.     private static final String MARK_USER = "user";
  95.     private static final String MARK_ADMIN_URL = "admin_url";
  96.     private static final String MARK_PROD_BASE_URL = "prod_base_url";
  97.     private static final String MARK_ADMIN_LOGOUT_URL = "admin_logout_url";
  98.     private static final String MARK_SITE_NAME = "site_name";
  99.     private static final String MARK_MENU_POS = "menu_pos";
  100.     private static final String MARK_DASHBOARD_ZONE = "dashboard_zone_";
  101.     private static final String MARK_JAVASCRIPT_FILE = "javascript_file";
  102.     private static final String MARK_JAVASCRIPT_FILES = "javascript_files";
  103.     private static final String MARK_PLUGIN_NAME = "plugin_name";
  104.     private static final String MARK_PLUGINS_LIST = "plugins_list";
  105.     private static final String MARK_ADMIN_AVATAR = "adminAvatar";
  106.     private static final String MARK_MINIMUM_PASSWORD_SIZE = "minimumPasswordSize";
  107.     private static final String MARK_USER_MENU_ITEMS = "userMenuItems";
  108.     private static final String MARK_LIST_LOGGER_INFO = "listLoggersInfo";

  109.     // Templates
  110.     private static final String TEMPLATE_ADMIN_HOME = "admin/user/admin_home.html";
  111.     private static final String TEMPLATE_ADMIN_MENU_HEADER = "admin/user/admin_header.html";
  112.     private static final String TEMPLATE_ADMIN_MENU_FOOTER = "admin/user/admin_footer.html";
  113.     private static final String TEMPLATE_MODIFY_PASSWORD_DEFAULT_MODULE = "admin/user/modify_password_default_module.html";
  114.     private static final String TEMPLATE_STYLESHEET_LINK = "admin/stylesheet_link.html";
  115.     private static final String TEMPLATE_JAVASCRIPT_FILE = "admin/javascript_file.html";

  116.     // Parameter
  117.     private static final String PARAMETER_LANGUAGE = "language";

  118.     // Properties
  119.     private static final String PROPERTY_DEFAULT_FEATURE_ICON = "lutece.admin.feature.default.icon";
  120.     private static final String PROPERTY_DASHBOARD_ZONES = "lutece.dashboard.zones.count";
  121.     private static final int PROPERTY_DASHBOARD_ZONES_DEFAULT = 4;
  122.     private static final String REFERER = "referer";

  123.     // Jsp
  124.     private static final String PROPERTY_JSP_URL_ADMIN_LOGOUT = "lutece.admin.logout.url";
  125.     private static final String MESSAGE_CONTROL_PASSWORD_NO_CORRESPONDING = "portal.users.message.password.confirm.error";
  126.     private static final String PASSWORD_ERROR = "portal.users.message.password.wrong.current";
  127.     private static final String PASSWORD_CURRENT_ERROR = "portal.users.message.password.new.equals.current";
  128.     private static final String MESSAGE_PASSWORD_REDIRECT = "portal.users.message.password.ok.redirect";
  129.     private static final String LOGGER_ACCESS = "lutece.adminaccess";

  130.     private static String _strStylesheets;
  131.     private static boolean _bResetAdminStylesheets;
  132.     private static String _strJavascripts;
  133.     private boolean _bAdminAvatar = PluginService.isPluginEnable( "adminavatar" );
  134.     private static Logger _loggerAccess = LogManager.getLogger( LOGGER_ACCESS );

  135.     /**
  136.      * Returns the Administration header menu
  137.      *
  138.      * @param request
  139.      *            The HttpServletRequest
  140.      * @return The html code of the header
  141.      */
  142.     public String getAdminMenuHeader( HttpServletRequest request )
  143.     {
  144.         Map<String, Object> model = new HashMap<>( );
  145.         String strSiteName = PortalService.getSiteName( );
  146.         AdminUser user = AdminUserService.getAdminUser( request );
  147.         List<FeatureGroup> aFeaturesGroupList = getFeatureGroupsList( user );

  148.         // Displays the menus according to the rights of the users
  149.         model.put( MARK_SITE_NAME, strSiteName );
  150.         model.put( MARK_MENU_POS, DatastoreService.getInstanceDataValue( PROPERTY_MENU_DATASTORE_POS, PROPERTY_MENU_DEFAULT_POS ) );
  151.         model.put( MARK_FEATURE_GROUP_LIST, aFeaturesGroupList );
  152.         model.put( MARK_ADMIN_URL, AppPathService.getBaseUrl( request ) + AppPathService.getAdminMenuUrl( ) );
  153.         model.put( MARK_PROD_BASE_URL, AppPathService.getProdUrl( request ) );
  154.         model.put( MARK_USER, user );
  155.         if ( user.isAdmin( ) )
  156.         {
  157.             model.put( MARK_LIST_LOGGER_INFO, AppLogService.getLoggersInfo( ) );
  158.         }

  159.         String strLogoutUrl = AppPropertiesService.getProperty( PROPERTY_LOGOUT_URL );
  160.         model.put( MARK_ADMIN_LOGOUT_URL, ( strLogoutUrl == null ) ? "" : strLogoutUrl );

  161.         int nZoneMax = AppPropertiesService.getPropertyInt( PROPERTY_DASHBOARD_ZONES, PROPERTY_DASHBOARD_ZONES_DEFAULT );
  162.         setDashboardData( model, user, request, nZoneMax );

  163.         model.put( MARK_ADMIN_AVATAR, _bAdminAvatar );
  164.         AdminUserMenuService registry = SpringContextService.getBean( AdminUserMenuService.BEAN_NAME );
  165.         model.put( MARK_USER_MENU_ITEMS, registry.getItems( request ) );

  166.         HtmlTemplate template = AppTemplateService.getTemplate( TEMPLATE_ADMIN_MENU_HEADER, user.getLocale( ), model );

  167.         return template.getHtml( );
  168.     }

  169.     /**
  170.      * Returns the Administration footer menu
  171.      *
  172.      * @param request
  173.      *            The HttpServletRequest
  174.      * @return The html code of the header
  175.      */
  176.     public String getAdminMenuFooter( HttpServletRequest request )
  177.     {
  178.         Map<String, Object> model = new HashMap<>( );
  179.         String strFooterVersion = AppInfo.getVersion( );
  180.         String strFooterSiteName = PortalService.getSiteName( );
  181.         AdminUser user = AdminUserService.getAdminUser( request );
  182.         Locale locale = ( user != null ) ? user.getLocale( ) : LocaleService.getDefault( );
  183.         model.put( Markers.VERSION, strFooterVersion );
  184.         model.put( MARK_SITE_NAME, strFooterSiteName );
  185.         model.put( MARK_JAVASCRIPT_FILES, getAdminJavascripts( ) );

  186.         HtmlTemplate template = AppTemplateService.getTemplate( TEMPLATE_ADMIN_MENU_FOOTER, locale, model );

  187.         traceAdminAccess( request );

  188.         return template.getHtml( );
  189.     }

  190.     /**
  191.      * Returns the html code of the menu of the users
  192.      *
  193.      * @param request
  194.      *            The Http request
  195.      * @return The html code of the users menu
  196.      */
  197.     public String getAdminMenuUser( HttpServletRequest request )
  198.     {
  199.         AdminUser user = AdminUserService.getAdminUser( request );

  200.         Map<String, Object> model = new HashMap<>( );

  201.         setDashboardData( model, user, request );

  202.         HtmlTemplate template = AppTemplateService.getTemplate( TEMPLATE_ADMIN_HOME, user.getLocale( ), model );

  203.         return template.getHtml( );
  204.     }

  205.     /**
  206.      * Add dashboard data to the template's model
  207.      *
  208.      * @param model
  209.      *            The template's model
  210.      * @param user
  211.      *            The Admin User
  212.      * @param request
  213.      *            HttpServletRequest
  214.      */
  215.     private void setDashboardData( Map<String, Object> model, AdminUser user, HttpServletRequest request )
  216.     {
  217.         List<IDashboardComponent> listDashboards = DashboardService.getInstance( ).getDashboards( user, request );
  218.         int nZoneMax = AppPropertiesService.getPropertyInt( PROPERTY_DASHBOARD_ZONES, PROPERTY_DASHBOARD_ZONES_DEFAULT );

  219.         if ( CollectionUtils.isNotEmpty( listDashboards ) )
  220.         {
  221.             int nColumnCount = DashboardService.getInstance( ).getColumnCount( );

  222.             // Personnalized dashboards for the nColumnCount first zones
  223.             for ( int i = 1; i <= nColumnCount; i++ )
  224.             {
  225.                 model.put( MARK_DASHBOARD_ZONE + i, DashboardService.getInstance( ).getDashboardData( listDashboards, user, i, request ) );
  226.             }

  227.             // Default dashboards for the nColumnCount to nZoneMax zones
  228.             for ( int i = nColumnCount + 1; i < nZoneMax; i++ )
  229.             {
  230.                 model.put( MARK_DASHBOARD_ZONE + i, DashboardService.getInstance( ).getDashboardData( user, i, request ) );
  231.             }
  232.         }
  233.         else
  234.         {
  235.             for ( int i = 1; i < nZoneMax; i++ )
  236.             {
  237.                 model.put( MARK_DASHBOARD_ZONE + i, DashboardService.getInstance( ).getDashboardData( user, i, request ) );
  238.             }
  239.         }
  240.     }

  241.     /**
  242.      * Add a specific dashboard data to the template's model
  243.      *
  244.      * @param model
  245.      *            The template's model
  246.      * @param user
  247.      *            The Admin User
  248.      * @param request
  249.      *            HttpServletRequest
  250.      * @param nDashboardZone
  251.      *            the dashboard zone
  252.      */
  253.     private void setDashboardData( Map<String, Object> model, AdminUser user, HttpServletRequest request, int nDashboardZone )
  254.     {
  255.         model.put( MARK_DASHBOARD_ZONE + nDashboardZone, DashboardService.getInstance( ).getDashboardData( user, nDashboardZone, request ) );
  256.     }

  257.     /**
  258.      * Returns an array that contains all feature groups corresponding to the user
  259.      *
  260.      * @param user
  261.      *            The Admin user
  262.      * @return An array of FeatureGroup objects
  263.      */
  264.     private List<FeatureGroup> getFeatureGroupsList( AdminUser user )
  265.     {
  266.         // structure that will be returned
  267.         ArrayList<FeatureGroup> aOutFeatureGroupList = new ArrayList<>( );

  268.         // get the list of user's features
  269.         Map<String, Right> featuresMap = user.getRights( );
  270.         List<Right> features = new ArrayList<>( featuresMap.values( ) );

  271.         List<Right> rightsToDelete = new ArrayList<>( );

  272.         // delete features which have a null URL : these features does not have to be displayed in the menu
  273.         for ( Right right : features )
  274.         {
  275.             if ( right.getUrl( ) == null )
  276.             {
  277.                 rightsToDelete.add( right );
  278.             }
  279.         }

  280.         features.removeAll( rightsToDelete );

  281.         Collections.sort( features );

  282.         // for each group, load the features
  283.         for ( FeatureGroup featureGroup : FeatureGroupHome.getFeatureGroupsList( ) )
  284.         {
  285.             ArrayList<Right> aLeftFeatures = new ArrayList<>( );

  286.             for ( Right right : features )
  287.             {
  288.                 right.setLocale( user.getLocale( ) );
  289.                 right.setIconUrl( getFeatureIcon( right ) );

  290.                 String strFeatureGroup = right.getFeatureGroup( );

  291.                 if ( featureGroup.getId( ).equalsIgnoreCase( strFeatureGroup ) )
  292.                 {
  293.                     featureGroup.addFeature( right );
  294.                 }
  295.                 else
  296.                 {
  297.                     aLeftFeatures.add( right );
  298.                 }
  299.             }

  300.             if ( !featureGroup.isEmpty( ) )
  301.             {
  302.                 featureGroup.setLocale( user.getLocale( ) );
  303.                 aOutFeatureGroupList.add( featureGroup );
  304.             }

  305.             features = aLeftFeatures;
  306.         }

  307.         // add the features with no group to the last group
  308.         if ( CollectionUtils.isNotEmpty( aOutFeatureGroupList ) )
  309.         {
  310.             FeatureGroup lastFeatureGroup = aOutFeatureGroupList.get( aOutFeatureGroupList.size( ) - 1 );

  311.             for ( Right right : features )
  312.             {
  313.                 lastFeatureGroup.addFeature( right );
  314.             }
  315.         }

  316.         return aOutFeatureGroupList;
  317.     }

  318.     /**
  319.      * Change the current language of the user
  320.      *
  321.      * @param request
  322.      *            The HTTP request
  323.      * @return The forward Url
  324.      * @throws AccessDeniedException
  325.      *             if the security token is invalid
  326.      */
  327.     public String doChangeLanguage( HttpServletRequest request ) throws AccessDeniedException
  328.     {
  329.         if ( !SecurityTokenService.getInstance( ).validate( request, LanguageAdminUserMenuItemProvider.TEMPLATE ) )
  330.         {
  331.             throw new AccessDeniedException( ERROR_INVALID_TOKEN );
  332.         }
  333.         String strLanguage = request.getParameter( PARAMETER_LANGUAGE );
  334.         AdminUser user = AdminUserService.getAdminUser( request );
  335.         Locale locale = new Locale( strLanguage );
  336.         user.setLocale( locale );
  337.         AppPathService.getBaseUrl( request );

  338.         return AppPathService.getBaseUrl( request ) + AppPathService.getAdminMenuUrl( );
  339.     }

  340.     /**
  341.      * Gets the feature icon
  342.      *
  343.      * @param right
  344.      *            The right
  345.      * @return The icon
  346.      */
  347.     private String getFeatureIcon( Right right )
  348.     {
  349.         String strIconUrl = AppPropertiesService.getProperty( PROPERTY_DEFAULT_FEATURE_ICON );

  350.         if ( ( right.getIconUrl( ) != null ) && ( !right.getIconUrl( ).equals( "" ) ) )
  351.         {
  352.             strIconUrl = right.getIconUrl( );
  353.         }
  354.         else
  355.         {
  356.             String strPluginName = right.getPluginName( );
  357.             Plugin plugin = PluginService.getPlugin( strPluginName );

  358.             if ( plugin != null )
  359.             {
  360.                 strIconUrl = plugin.getIconUrl( );
  361.             }
  362.         }

  363.         return strIconUrl;
  364.     }

  365.     /**
  366.      * Display the modification form for user password. This is used only by the default module. For other modules, custom implementation should be provided.
  367.      *
  368.      * @param request
  369.      *            the http request
  370.      * @return the form allowing the modification of the user's password
  371.      */
  372.     public String getModifyDefaultAdminUserPassword( HttpServletRequest request )
  373.     {
  374.         AdminUser user = AdminUserService.getAdminUser( request );
  375.         Locale locale = user.getLocale( );
  376.         Map<String, Object> model = new HashMap<>( );
  377.         model.put( MARK_MINIMUM_PASSWORD_SIZE, AdminUserService.getIntegerSecurityParameter( AdminUserService.DSKEY_PASSWORD_MINIMUM_LENGTH ) );
  378.         model.put( SecurityTokenService.MARK_TOKEN, SecurityTokenService.getInstance( ).getToken( request, TEMPLATE_MODIFY_PASSWORD_DEFAULT_MODULE ) );
  379.         HtmlTemplate template = AppTemplateService.getTemplate( TEMPLATE_MODIFY_PASSWORD_DEFAULT_MODULE, locale, model );

  380.         return template.getHtml( );
  381.     }

  382.     /**
  383.      * Perform the user password modification. This is used only by the default module. For other modules, custom implementation should be provided.
  384.      *
  385.      * @param request
  386.      *            the http request
  387.      * @return the form allowing the modification of the user's password
  388.      * @throws AccessDeniedException
  389.      *             if the security token is invalid
  390.      */
  391.     public String doModifyDefaultAdminUserPassword( HttpServletRequest request ) throws AccessDeniedException
  392.     {
  393.         AdminUser user = AdminUserService.getAdminUser( request );

  394.         String strCurrentPassword = request.getParameter( Parameters.PASSWORD_CURRENT );
  395.         String strNewPassword = request.getParameter( Parameters.NEW_PASSWORD );
  396.         String strConfirmNewPassword = request.getParameter( Parameters.CONFIRM_NEW_PASSWORD );

  397.         LuteceDefaultAdminUser userStored = AdminUserHome.findLuteceDefaultAdminUserByPrimaryKey( user.getUserId( ) );

  398.         IPassword password = userStored.getPassword( );

  399.         // Mandatory Fields
  400.         if ( StringUtils.isEmpty( strCurrentPassword ) || StringUtils.isEmpty( strNewPassword ) || StringUtils.isEmpty( strConfirmNewPassword ) )
  401.         {
  402.             return AdminMessageService.getMessageUrl( request, Messages.MANDATORY_FIELDS, AdminMessage.TYPE_STOP );
  403.         }

  404.         // Test the difference between the two fields of new password
  405.         if ( !strNewPassword.equals( strConfirmNewPassword ) )
  406.         {
  407.             return AdminMessageService.getMessageUrl( request, MESSAGE_CONTROL_PASSWORD_NO_CORRESPONDING, AdminMessage.TYPE_STOP );
  408.         }

  409.         String strUrl = AdminUserService.checkPassword( request, strNewPassword, user.getUserId( ) );

  410.         if ( StringUtils.isNotEmpty( strUrl ) )
  411.         {
  412.             return strUrl;
  413.         }

  414.         // Test of the value of the current password
  415.         if ( !password.check( strCurrentPassword ) )
  416.         {
  417.             return AdminMessageService.getMessageUrl( request, PASSWORD_ERROR, AdminMessage.TYPE_STOP );
  418.         }

  419.         // Test of control of difference between the new password and the current one
  420.         if ( strCurrentPassword.equals( strNewPassword ) )
  421.         {
  422.             return AdminMessageService.getMessageUrl( request, PASSWORD_CURRENT_ERROR, AdminMessage.TYPE_STOP );
  423.         }
  424.         if ( !SecurityTokenService.getInstance( ).validate( request, TEMPLATE_MODIFY_PASSWORD_DEFAULT_MODULE ) )
  425.         {
  426.             throw new AccessDeniedException( ERROR_INVALID_TOKEN );
  427.         }

  428.         // Successful tests
  429.         IPasswordFactory passwordFactory = SpringContextService.getBean( IPasswordFactory.BEAN_NAME );
  430.         userStored.setPassword( passwordFactory.getPasswordFromCleartext( strNewPassword ) );
  431.         userStored.setPasswordReset( Boolean.FALSE );
  432.         userStored.setPasswordMaxValidDate( AdminUserService.getPasswordMaxValidDate( ) );
  433.         AdminUserHome.update( userStored );
  434.         AdminUserHome.insertNewPasswordInHistory( userStored.getPassword( ), userStored.getUserId( ) );

  435.         return AdminMessageService.getMessageUrl( request, MESSAGE_PASSWORD_REDIRECT, AppPropertiesService.getProperty( PROPERTY_JSP_URL_ADMIN_LOGOUT ),
  436.                 AdminMessage.TYPE_INFO );
  437.     }

  438.     /**
  439.      * Change the mode accessibility
  440.      *
  441.      * @param request
  442.      *            {@link HttpServletRequest}
  443.      * @return The forward Url
  444.      * @throws AccessDeniedException
  445.      *             if the security token is invalid
  446.      */
  447.     public String doModifyAccessibilityMode( HttpServletRequest request ) throws AccessDeniedException
  448.     {
  449.         if ( !SecurityTokenService.getInstance( ).validate( request, AccessibilityModeAdminUserMenuItemProvider.TEMPLATE ) )
  450.         {
  451.             throw new AccessDeniedException( ERROR_INVALID_TOKEN );
  452.         }
  453.         AdminUser user = AdminUserService.getAdminUser( request );

  454.         if ( user != null )
  455.         {
  456.             boolean bIsAccessible = !user.getAccessibilityMode( );
  457.             user.setAccessibilityMode( bIsAccessible );
  458.             AdminUserHome.update( user );
  459.         }

  460.         String strReferer = request.getHeader( REFERER );

  461.         if ( StringUtils.isNotBlank( strReferer ) )
  462.         {
  463.             return strReferer;
  464.         }

  465.         return AppPathService.getBaseUrl( request ) + AppPathService.getAdminMenuUrl( );
  466.     }

  467.     /**
  468.      * Return the stylesheets block to include in the footer
  469.      *
  470.      * @return the stylesheets files block to include in the footer
  471.      * @since 5.1
  472.      */
  473.     public String getAdminStyleSheets( )
  474.     {
  475.         loadStylesheets( );
  476.         return _strStylesheets;
  477.     }

  478.     private static synchronized void loadStylesheets( )
  479.     {
  480.         if ( _strStylesheets == null || _bResetAdminStylesheets )
  481.         {
  482.             List<Plugin> listPlugins = new ArrayList<>( );
  483.             listPlugins.add( PluginService.getCore( ) );
  484.             listPlugins.addAll( PluginService.getPluginList( ) );

  485.             Map<String, Object> model = new HashMap<>( );
  486.             model.put( MARK_PLUGINS_LIST, listPlugins );

  487.             _strStylesheets = AppTemplateService.getTemplate( TEMPLATE_STYLESHEET_LINK, LocaleService.getDefault( ), model ).getHtml( );
  488.             _bResetAdminStylesheets = false;
  489.         }
  490.     }

  491.     public static void resetAdminStylesheets( )
  492.     {
  493.         _bResetAdminStylesheets = true;
  494.     }

  495.     /**
  496.      * Return the javascript files block to include in the footer
  497.      *
  498.      * @return the javascript files block to include in the footer
  499.      * @since 5.1
  500.      */
  501.     private static synchronized String getAdminJavascripts( )
  502.     {
  503.         if ( _strJavascripts == null )
  504.         {
  505.             StringBuilder sbJavascripts = new StringBuilder( );
  506.             List<Plugin> listPlugins = new ArrayList<>( );
  507.             listPlugins.add( PluginService.getCore( ) );
  508.             listPlugins.addAll( PluginService.getPluginList( ) );

  509.             for ( Plugin plugin : listPlugins )
  510.             {
  511.                 if ( plugin.getAdminJavascriptFiles( ) != null )
  512.                 {
  513.                     for ( String strJavascript : plugin.getAdminJavascriptFiles( ) )
  514.                     {
  515.                         Map<String, Object> model = new HashMap<>( );
  516.                         model.put( MARK_JAVASCRIPT_FILE, strJavascript );
  517.                         model.put( MARK_PLUGIN_NAME, plugin.getName( ) );
  518.                         sbJavascripts.append( AppTemplateService.getTemplate( TEMPLATE_JAVASCRIPT_FILE, LocaleService.getDefault( ), model ).getHtml( ) );
  519.                     }
  520.                 }
  521.             }

  522.             _strJavascripts = sbJavascripts.toString( );
  523.         }

  524.         return _strJavascripts;
  525.     }

  526.     /**
  527.      * Trace in a log file URL accessed by the current admin user
  528.      *
  529.      * @param request
  530.      *            The HTTP request
  531.      */
  532.     private void traceAdminAccess( HttpServletRequest request )
  533.     {
  534.         AdminUser user = AdminUserService.getAdminUser( request );
  535.         if ( user != null )
  536.         {
  537.             StringBuilder sbAccessLog = new StringBuilder( );
  538.             sbAccessLog.append( "USER id:" ).append( user.getUserId( ) ).append( ", name: " ).append( user.getFirstName( ) ).append( " " )
  539.                     .append( user.getLastName( ) ).append( ", ip: " ).append( request.getRemoteAddr( ) ).append( ", url: " ).append( request.getScheme( ) )
  540.                     .append( "://" ).append( request.getServerName( ) ).append( ':' ).append( request.getServerPort( ) ).append( request.getRequestURI( ) );
  541.             String strQuery = request.getQueryString( );
  542.             if ( strQuery != null )
  543.             {
  544.                 sbAccessLog.append( "?" ).append( strQuery );
  545.             }
  546.             _loggerAccess.info( sbAccessLog.toString( ) );

  547.         }
  548.     }
  549. }