fr.paris.lutece.plugins.mylutece.util
Class SecurityUtils

java.lang.Object
  extended by fr.paris.lutece.plugins.mylutece.util.SecurityUtils

public class SecurityUtils
extends java.lang.Object

Util for security parameters


Constructor Summary
SecurityUtils()
           
 
Method Summary
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.
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
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
protected static boolean checkPasswordFormat(java.lang.String strPassword, IUserParameterService parameterService, fr.paris.lutece.portal.service.plugin.Plugin plugin)
          Check the format of the password from the entered parameters.
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
protected static boolean checkUserPasswordMinimumLength(java.lang.String strPassword, IUserParameterService parameterService, fr.paris.lutece.portal.service.plugin.Plugin plugin)
          Check whether a password is long enough.
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.
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
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
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
protected static java.lang.String getMessagePasswordFormat(javax.servlet.http.HttpServletRequest request, fr.paris.lutece.portal.service.plugin.Plugin plugin)
          Gets the admin message saying that the password does not match the required format
protected static java.lang.String getMessagePasswordMinimumLength(javax.servlet.http.HttpServletRequest request, IUserParameterService parameterService, fr.paris.lutece.portal.service.plugin.Plugin plugin)
          Get the admin message telling the password length is too short.
static int getPasswordDuration(IUserParameterService parameterService, fr.paris.lutece.portal.service.plugin.Plugin plugin)
          Get the password duration
static int getPasswordHistorySize(IUserParameterService parameterService, fr.paris.lutece.portal.service.plugin.Plugin plugin)
          Get the password history size
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.
static int getTSWSizePasswordChange(IUserParameterService parameterService, fr.paris.lutece.portal.service.plugin.Plugin plugin)
          Get the size of the time sliding window of passwor change
static boolean isAdvancedSecurityParametersUsed(IUserParameterService parameterService, fr.paris.lutece.portal.service.plugin.Plugin plugin)
          Get the parameter indicating that a password must contain numbers.
protected static boolean isPasswordFormatUsed(IUserParameterService parameterService, fr.paris.lutece.portal.service.plugin.Plugin plugin)
          Get the parameter indicating that a password must contain numbers.
static void removeAdvancedSecurityParameters(IUserParameterService parameterService, fr.paris.lutece.portal.service.plugin.Plugin plugin)
          Remove the advanced security parameters
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.
static void updateSecurityParameters(IUserParameterService parameterService, javax.servlet.http.HttpServletRequest request, fr.paris.lutece.portal.service.plugin.Plugin plugin)
          Update security parameters from request parameters
static void useAdvancedSecurityParameters(IUserParameterService parameterService, fr.paris.lutece.portal.service.plugin.Plugin plugin)
          Enable advanced security parameters
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

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

checkUserPasswordMinimumLength

protected static boolean checkUserPasswordMinimumLength(java.lang.String strPassword,
                                                        IUserParameterService parameterService,
                                                        fr.paris.lutece.portal.service.plugin.Plugin plugin)
Check whether a password is long enough.

Parameters:
strPassword - Password to check
parameterService - Parameter service to get parameters from.
plugin - The plugin
Returns:
true is the password is too short, or false if the password correct or if the password's minimum length is disabled.

getMessagePasswordMinimumLength

protected static java.lang.String getMessagePasswordMinimumLength(javax.servlet.http.HttpServletRequest request,
                                                                  IUserParameterService parameterService,
                                                                  fr.paris.lutece.portal.service.plugin.Plugin plugin)
Get the admin message telling the password length is too short.

Parameters:
request - The request
parameterService - Parameter service to get parameters from.
plugin - The plugin
Returns:
The URL of the admin message indicating that the entered password is too short.

isPasswordFormatUsed

protected static boolean isPasswordFormatUsed(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

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

checkPasswordFormat

protected static boolean checkPasswordFormat(java.lang.String strPassword,
                                             IUserParameterService parameterService,
                                             fr.paris.lutece.portal.service.plugin.Plugin plugin)
Check the format of the password from the entered parameters. The password may have to contain upper and lower case letters, numbers and special characters.

Parameters:
strPassword - The password to check
parameterService - Parameter service to get parameters from.
plugin - The plugin
Returns:
True if the giver parameter respect the parametered format, false if he violate one or more rules.

getMessagePasswordFormat

protected static java.lang.String getMessagePasswordFormat(javax.servlet.http.HttpServletRequest request,
                                                           fr.paris.lutece.portal.service.plugin.Plugin plugin)
Gets the admin message saying that the password does not match the required format

Parameters:
request - The request
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

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


Copyright © 2012 Mairie de Paris. All Rights Reserved.