Java Code Examples for org.apache.commons.validator.GenericValidator#matchRegexp()

The following examples show how to use org.apache.commons.validator.GenericValidator#matchRegexp() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ActionValidatorUtils.java    From hop with Apache License 2.0 5 votes vote down vote up
/**
 * Fails if a field's value does not match the given mask.
 */
public static boolean validateMask( ICheckResultSource source, String propertyName, int levelOnFail,
                                    List<ICheckResult> remarks, String mask ) {
  final String VALIDATOR_NAME = "matches";
  String value = null;

  value = ValidatorUtils.getValueAsString( source, propertyName );

  try {
    if ( null == mask ) {
      addGeneralRemark(
        source, propertyName, VALIDATOR_NAME, remarks, "errors.missingVar",
        ICheckResult.TYPE_RESULT_ERROR );
      return false;
    }

    if ( StringUtils.isNotBlank( value ) && !GenericValidator.matchRegexp( value, mask ) ) {
      addFailureRemark( source, propertyName, VALIDATOR_NAME, remarks, levelOnFail );
      return false;
    } else {
      return true;
    }
  } catch ( Exception e ) {
    addExceptionRemark( source, propertyName, VALIDATOR_NAME, remarks, e );
    return false;
  }
}
 
Example 2
Source File: JobEntryValidatorUtils.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
/**
 * Fails if a field's value does not match the given mask.
 */
public static boolean validateMask( CheckResultSourceInterface source, String propertyName, int levelOnFail,
  List<CheckResultInterface> remarks, String mask ) {
  final String VALIDATOR_NAME = "matches";
  String value = null;

  value = ValidatorUtils.getValueAsString( source, propertyName );

  try {
    if ( null == mask ) {
      addGeneralRemark(
        source, propertyName, VALIDATOR_NAME, remarks, "errors.missingVar",
        CheckResultInterface.TYPE_RESULT_ERROR );
      return false;
    }

    if ( StringUtils.isNotBlank( value ) && !GenericValidator.matchRegexp( value, mask ) ) {
      addFailureRemark( source, propertyName, VALIDATOR_NAME, remarks, levelOnFail );
      return false;
    } else {
      return true;
    }
  } catch ( Exception e ) {
    addExceptionRemark( source, propertyName, VALIDATOR_NAME, remarks, e );
    return false;
  }
}
 
Example 3
Source File: SpagoBIUtilities.java    From Knowage-Server with GNU Affero General Public License v3.0 4 votes vote down vote up
private static boolean isMultivalueProfileAttribute(String value) {
	return GenericValidator.matchRegexp(value, MULTI_VALUE_PROFILE_ATTRIBUTE_REGEXP);
}
 
Example 4
Source File: LoginController.java    From JDeSurvey with GNU Affero General Public License v3.0 4 votes vote down vote up
@RequestMapping(method = RequestMethod.POST, value = "/rpass", produces = "text/html")
public String forgotPasswordPost(@RequestParam(value = "password", required = true) String password,
								@RequestParam(value = "cpassword", required = true) String cpassword,
								@RequestParam(value = "key", required = true) String key,
								@RequestParam(value = "_proceed", required = false) String proceed,
								Model uiModel,HttpServletRequest httpServletRequest) {
	try {
		if(proceed != null){
			//validate the passed key
			if (! userService.user_validateForgotPasswordKey(key)) {
				log.warn("Attempt to reset password with invalid key, Not successful");
				uiModel.addAttribute("status", "E"); //Error
				throw (new RuntimeException("Attempt to reset password with invalid key, Not successful"));
			}
			
			//check that passwords match 	
			if (!password.equals(cpassword)) {
				uiModel.asMap().clear();
				uiModel.addAttribute("key", key);
				uiModel.addAttribute("status", "U"); //Unmatching Passwords
				return "public/rpass";
			}
			
			GlobalSettings globalSettings = applicationSettingsService.getSettings();
			
			//Check new password strength 
			if(!GenericValidator.matchRegexp(password,globalSettings.getPasswordEnforcementRegex())){
				uiModel.asMap().clear();
				uiModel.addAttribute("key", key);
				uiModel.addAttribute("status", "I"); //Unmatching Passwords
				uiModel.addAttribute("passwordPolicyMsg", globalSettings.getPasswordEnforcementMessage());
				return "public/rpass";
			}
							
			//All validations passed, save the HASH of the password in the database
			PasswordResetRequest passwordResetRequest =userService.passwordResetRequest_findByHash(key);
			User user = userService.user_findByLogin(passwordResetRequest.getLogin());
			user.setPassword(password);
			userService.user_updatePassword(user,passwordResetRequest);
			uiModel.addAttribute("status", "S");//success
			return "public/rpass";
		}
		else{
			//cancel button
			return "public/login";	
		}
	} catch (Exception e) {
		log.error(e.getMessage(),e);
		throw (new RuntimeException(e));
	}	
}