Class SecurityUtils


  • public class SecurityUtils
    extends java.lang.Object
    Util for security parameters
    • Constructor Detail

      • SecurityUtils

        public SecurityUtils()
    • Method Detail

      • checkSecurityParameters

        public static java.util.Map<java.lang.String,​java.lang.Object> checkSecurityParameters​(IUserParameterService parameterService,
                                                                                                     java.util.Map<java.lang.String,​java.lang.Object> model,
                                                                                                     fr.paris.lutece.portal.service.plugin.Plugin plugin)
        Loads a model with base security parameters
        Parameters:
        parameterService - The parameter service to use
        model - The base model to load
        plugin - The plugin
        Returns:
        The model loaded with security parameters
      • updateSecurityParameters

        public static void updateSecurityParameters​(IUserParameterService parameterService,
                                                    javax.servlet.http.HttpServletRequest request,
                                                    fr.paris.lutece.portal.service.plugin.Plugin plugin)
        Update security parameters from request parameters
        Parameters:
        parameterService - Parameter service
        request - Request to get the parameter from
        plugin - The plugin
      • getPasswordDuration

        public static int getPasswordDuration​(IUserParameterService parameterService,
                                              fr.paris.lutece.portal.service.plugin.Plugin plugin)
        Get the password duration
        Parameters:
        parameterService - Parameter service to get parameters from.
        plugin - The plugin
        Returns:
        The password duration, or 0 if no value or an incorrect value is specified
      • getPasswordHistorySize

        public static int getPasswordHistorySize​(IUserParameterService parameterService,
                                                 fr.paris.lutece.portal.service.plugin.Plugin plugin)
        Get the password history size
        Parameters:
        parameterService - Parameter service to get parameters from.
        plugin - The plugin
        Returns:
        The password history size, or 0 if no value or an incorrect value is specified
      • getTSWSizePasswordChange

        public static int getTSWSizePasswordChange​(IUserParameterService parameterService,
                                                   fr.paris.lutece.portal.service.plugin.Plugin plugin)
        Get the size of the time sliding window of passwor change
        Parameters:
        parameterService - Parameter service to get parameters from.
        plugin - The plugin
        Returns:
        the size of the time sliding window of passwor change, or 0 if none is specified
      • isAdvancedSecurityParametersUsed

        public static boolean isAdvancedSecurityParametersUsed​(IUserParameterService parameterService,
                                                               fr.paris.lutece.portal.service.plugin.Plugin plugin)
        Get the parameter indicating that a password must contain numbers.
        Parameters:
        parameterService - Parameter service to get parameters from.
        plugin - The plugin
        Returns:
        True if passwords must contain numbers, false otherwise
      • getMaximumNumberPasswordChange

        public static int getMaximumNumberPasswordChange​(IUserParameterService parameterService,
                                                         fr.paris.lutece.portal.service.plugin.Plugin plugin)
        Get the maximum number of time a user can change his password in a given period
        Parameters:
        parameterService - Parameter service to get parameters from.
        plugin - The plugin
        Returns:
        The the maximum number of time a user can change his password in a given period, or 0 if no value or an incorrect value is specified
      • getIntegerSecurityParameter

        public static int getIntegerSecurityParameter​(IUserParameterService parameterService,
                                                      fr.paris.lutece.portal.service.plugin.Plugin plugin,
                                                      java.lang.String strParameterkey)
        Get the integer value of a security parameter
        Parameters:
        parameterService - Parameter service to use
        plugin - The plugin
        strParameterkey - Key of the security parameter to get
        Returns:
        The integer value of the security parameter
      • getBooleanSecurityParameter

        public static boolean getBooleanSecurityParameter​(IUserParameterService parameterService,
                                                          fr.paris.lutece.portal.service.plugin.Plugin plugin,
                                                          java.lang.String strParameterkey)
        Get the boolean value of a security parameter
        Parameters:
        parameterService - Parameter service to use
        plugin - The plugin
        strParameterkey - Key of the security parameter to get
        Returns:
        The boolean value of the security parameter
      • getSecurityParameter

        public static java.lang.String getSecurityParameter​(IUserParameterService parameterService,
                                                            fr.paris.lutece.portal.service.plugin.Plugin plugin,
                                                            java.lang.String strParameterkey)
        Get the value of a security parameter
        Parameters:
        parameterService - Parameter service to use
        plugin - The plugin
        strParameterkey - Key of the security parameter to get
        Returns:
        The value of the security parameter
      • getLargeSecurityParameter

        public static java.lang.String getLargeSecurityParameter​(IUserParameterService parameterService,
                                                                 fr.paris.lutece.portal.service.plugin.Plugin plugin,
                                                                 java.lang.String strParameterkey)
        Get the large value of a security parameter.
        Parameters:
        parameterService - Parameter service to use
        plugin - The plugin
        strParameterkey - Key of the security parameter to get
        Returns:
        The value of the security parameter
      • getMessageFrontPasswordFormat

        public static java.lang.String getMessageFrontPasswordFormat​(java.util.Locale locale,
                                                                     IUserParameterService parameterService,
                                                                     fr.paris.lutece.portal.service.plugin.Plugin plugin)
        Gets the password message format required format
        Parameters:
        locale - the locale
        parameterService - Parameter service to use
        plugin - The plugin
        Returns:
        the url of the admin message saying that the password does not match the required format
      • updateParameterValue

        public static void updateParameterValue​(IUserParameterService parameterService,
                                                fr.paris.lutece.portal.service.plugin.Plugin plugin,
                                                java.lang.String strKey,
                                                java.lang.String strValue)
        Updates a parameter from its key with a new value.
        Parameters:
        parameterService - Parameter service to use
        plugin - The plugin
        strKey - The key of the parameter to update
        strValue - The new value of the parameter
      • updateLargeParameterValue

        public static void updateLargeParameterValue​(IUserParameterService parameterService,
                                                     fr.paris.lutece.portal.service.plugin.Plugin plugin,
                                                     java.lang.String strKey,
                                                     java.lang.String strValue)
        Updates a parameter from its key with a new value. The value should be a large value, from exemple a String from a text area.
        Parameters:
        parameterService - Parameter service to use
        plugin - The plugin
        strKey - The key of the parameter to update
        strValue - The new value of the parameter
      • useAdvancedSecurityParameters

        public static void useAdvancedSecurityParameters​(IUserParameterService parameterService,
                                                         fr.paris.lutece.portal.service.plugin.Plugin plugin)
        Enable advanced security parameters
        Parameters:
        parameterService - Parameter service to use
        plugin - The plugin
      • removeAdvancedSecurityParameters

        public static void removeAdvancedSecurityParameters​(IUserParameterService parameterService,
                                                            fr.paris.lutece.portal.service.plugin.Plugin plugin)
        Remove the advanced security parameters
        Parameters:
        parameterService - Parameter service to use
        plugin - The plugin
      • getPasswordMaxValidDate

        public static java.sql.Timestamp getPasswordMaxValidDate​(IUserParameterService parameterService,
                                                                 fr.paris.lutece.portal.service.plugin.Plugin plugin)
        Get the current maximum valid date of a password from the parameter service.
        Parameters:
        parameterService - Parameter service to use
        plugin - The plugin
        Returns:
        The maximum valid date of a password
      • getAccountMaxValidDate

        public static java.sql.Timestamp getAccountMaxValidDate​(IUserParameterService parameterService,
                                                                fr.paris.lutece.portal.service.plugin.Plugin plugin)
        Compute the maximum valid date of an account with the current time and the parameters in the database.
        Parameters:
        parameterService - Parameter service to use
        plugin - The plugin
        Returns:
        The maximum valid date of an account
      • checkPasswordForFrontOffice

        public static java.lang.String checkPasswordForFrontOffice​(IUserParameterService parameterService,
                                                                   fr.paris.lutece.portal.service.plugin.Plugin plugin,
                                                                   java.lang.String strPassword,
                                                                   int nUserId)
        Test a password validity
        Parameters:
        parameterService - Paramter service to use
        plugin - The plugin
        strPassword - The password to test validity
        nUserId - The id of the user
        Returns:
        Returns null if the password is correct, or a code depending on the error found. Errors can be 'password_minimum_length' if the password is too short, or 'password_format' if the format of the password is not correct.
      • checkPasswordForBackOffice

        public static java.lang.String checkPasswordForBackOffice​(IUserParameterService parameterService,
                                                                  fr.paris.lutece.portal.service.plugin.Plugin plugin,
                                                                  java.lang.String strPassword,
                                                                  javax.servlet.http.HttpServletRequest request)
        Test a password validity
        Parameters:
        parameterService - Parameter service to use
        plugin - The plugin
        strPassword - Password to check
        request - The request
        Returns:
        Returns null if the password is correct, or an admin message describing the error
      • buildPassword

        public static java.lang.String buildPassword​(IUserParameterService parameterService,
                                                     fr.paris.lutece.portal.service.plugin.Plugin plugin,
                                                     java.lang.String strUserPassword)
        Build the password depending of the encryption. If the encryption is enable, then it returns the password encrypted, otherwise it just returns the password given in parameter.
        Parameters:
        parameterService - The parameter service to use
        plugin - The plugin
        strUserPassword - the password
        Returns:
        the password encrypted or not
      • makePassword

        public static java.lang.String makePassword​(IUserParameterService parameterService,
                                                    fr.paris.lutece.portal.service.plugin.Plugin plugin)
        Generate a new random password
        Parameters:
        parameterService - The parameter service to use
        Returns:
        the new password
      • getBannedDomainNames

        public static java.lang.String[] getBannedDomainNames​(IUserParameterService parameterService,
                                                              fr.paris.lutece.portal.service.plugin.Plugin plugin)
        Get an array containing banned domain names for email adresses
        Parameters:
        parameterService - Parameter service
        plugin - The plugin
        Returns:
        An array containing banned domain names for email adresses
      • buildResetConnectionLogUrl

        public static java.lang.String buildResetConnectionLogUrl​(int nInterval,
                                                                  javax.servlet.http.HttpServletRequest request)
        Build an url to reset connection logs for an IP and a given user. Data is read from the request.
        Parameters:
        nInterval - Interval of time to reset
        request - The request
        Returns:
        The url to reset connection logs.