# validators gatein.validators.username.regexp=^[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-za-z]{2,}$ gatein.validators.username.format.message=Username must be a valid email address.
GateIn Portal3.8 includes a user-configurable validator that can be applied to input fields of different bundled portlets. By default, this validator is only used to configure the validation of username in the user account, user registration and group membership portlets. However, the architecture allows for configurable validation to be used in other contexts, too.
The validator can be configured via properties in the configuration.properties file found in the GateIn Portal configuration directory. By default, this directory is
$JBOSS_HOME/standalone/configuration/gatein/ on JBoss Application Server or
$TOMCAT_HOME/gatein/conf/ on Tomcat.
The architecture supports several configurations that can be activated and associated with specific instances of the user-configurable validator when they are created and assigned to fields in portlets. We will only concern ourselves with the currently supported use cases, which are creation/modification of a username during registration/modification of a user and group membership assignments.
A configuration is created by adding an entry to configuration.properties using the gatein.validators. prefix followed by the name of the configuration, a period . and the name of the validation aspect you want to configure. The user-configurable validator currently supports four different aspects per configuration, as follows, where {configuration} refers to the configuration name:
gatein.validators.{configuration}.length.min: Minimal length of the validated field.
gatein.validators.{configuration}.length.max: Maximal length of the validated field.
gatein.validators.{configuration}.regexp: Regular expression to which values of the validated field must conform.
gatein.validators.{configuration}.format.message: Information message to display when the value of the validated field does not conform to the specified regular expression.
Only the following configurations are currently supported by GateIn Portal:
username which configures the validation of usernames when they are created/modified.
groupmembership which configures the validation of usernames in the context of group memberships.
email which configures the validation of e-mail fields.
displayname which configures the validation of user's display name field.
jobtitle which configures the validation of user profile's job title field.
grouplabel which configures the validation of group membership label.
If you want to make sure that your users use an email address as their usernames, you could use the following configuration:
# validators gatein.validators.username.regexp=^[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-za-z]{2,}$ gatein.validators.username.format.message=Username must be a valid email address.
If you do not change the configuration of the validator, the username will be validated as follows:
Length must be between 3 and 30 characters.
Only lowercase letters, numbers, undescores (_) and period (.) can be used.
No consecutive undescores (_) or period (.) can be used.
Must start with a letter.
Must end with a letter or number.
Some components that leverage GateIn Portal depend on usernames being all lowercase. Therefore, it is strongly recommended that you only accept the lowercase usernames.
The user-configurable validator is implemented by the org.exoplatform.webui.form.validator.UserConfigurableValidator class. Please refer to its documentation for more details.
To use a specific validator configuration to validate a given field value, add the validator to the field where configurationName is a String representing the name of the configuration to use:
addValidator(UserConfigurableValidator.class, configurationName))
If the configuration name is not configured in configuration.properties then the user-configurable validator will not work.
The validator instance can then be configured by adding the relevant information in configuration.properties, for example:
# validators gatein.validators.configurationName.length.min=5 gatein.validators.configurationName.length.max=10 gatein.validators.configurationName.regexp=^u\d{4,9}$ gatein.validators.configurationName.format.message=Username must start with ''u'' and be followed by 4 to 9 digits.
Alternatively, a resource key can also be passed to the addValidator() method to specify which localized message should be used in case a validation error occurs, for example configurationName as follows:
addValidator(UserConfigurableValidator.class, UserConfigurableValidator.GROUPMEMBERSHIP, UserConfigurableValidator.GROUP_MEMBERSHIP_LOCALIZATION_KEY);