Esempio n. 1
0
  private void validateCreateOrgData(
      String orgName,
      String password,
      String firstName,
      String lastName,
      String email,
      Boolean usePamAuth) {

    Map<String, String> values = new HashMap<String, String>();
    values.put("orgName", orgName);
    values.put("desiredPassword", password);
    values.put("desiredPasswordConfirm", password);
    values.put("firstNames", firstName);
    values.put("lastName", lastName);

    ValidatorResult result =
        RhnValidationHelper.validate(
            this.getClass(), values, new LinkedList<String>(values.keySet()), VALIDATION_XSD);

    if (!result.isEmpty()) {
      log.error("Validation errors:");
      for (ValidatorError error : result.getErrors()) {
        log.error("   " + error.getMessage());
      }
      // Multiple errors could return here, but we'll have to just throw an
      // exception for the first one and return that to the user.
      ValidatorError e = result.getErrors().get(0);
      throw new ValidationException(e.getMessage());
    }

    if (!usePamAuth && StringUtils.isEmpty(password)) {
      throw new FaultException(
          -501, "passwordRequiredOrUsePam", "Password is required if not using PAM authentication");
    }
  }
Esempio n. 2
0
 /**
  * create an exception from a ValidatorResult
  *
  * @param errorIn error number
  * @param labelIn label
  * @param resultIn validator result
  * @return new FaultException
  */
 public static FaultException create(int errorIn, String labelIn, ValidatorResult resultIn) {
   for (Iterator<ValidatorError> iter = resultIn.getErrors().iterator(); iter.hasNext(); ) {
     ValidatorError ve = iter.next();
     return new FaultException(errorIn, labelIn, ve.getKey(), ve.getValues());
   }
   for (Iterator<ValidatorWarning> iter = resultIn.getWarnings().iterator(); iter.hasNext(); ) {
     ValidatorWarning vw = iter.next();
     return new FaultException(errorIn, labelIn, vw.getKey(), vw.getValues());
   }
   return new FaultException(errorIn, labelIn, "");
 }