示例#1
0
    public void validateSmtp() {
      Validation.required("setup.smtpServer", smtpServer);

      if (HostNameOrIpAddressCheck.isValidHostName(smtpServer)) {
        if (PropertiesConfigurationValidator.validateIpList(nameservers)) {
          Set<String> ips = Sets.newHashSet(nameservers.split(","));
          if (!DnsUtils.validateHostname(ips, smtpServer)) {
            Validation.addError("setup.smtpServer", "setup.smtpServer.invalidSmtpServer");
          }
        } else if (StringUtils.isNotEmpty(nameservers)) {
          Validation.addError(
              "setup.nameservers", "setup.smtpServer.invalidNameserver", nameservers);
        }
      }

      if (!HostNameOrIpAddressCheck.isValidHostNameOrIp(smtpServer)) {
        Validation.addError("setup.smtpServer", "setup.smtpServer.invalid");
      }
      if (!StringUtils.isNumeric(smtpPort)) {
        Validation.addError("setup.smtpServer", "setup.smtpServer.invalidPort");
      }

      Validation.required("setup.smtpFrom", smtpFrom);
      Validation.email("setup.smtpFrom", smtpFrom);

      if (StringUtils.isNotBlank(smtpAuthType)
          && !StringUtils.equalsIgnoreCase(smtpAuthType, "None")) {
        Validation.required("setup.smtpUsername", smtpUsername);
        Validation.required("setup.smtpPassword", smtpPassword);

        if (PasswordUtil.isNotValid(smtpPassword)) {
          Validation.addError("setup.smtpPassword", "setup.password.notValid");
        }
      }
    }
示例#2
0
  /**
   * Validate passwords dynamically from the initial setup form, rendering the result as JSON.
   *
   * @param setup the initial setup form.
   */
  @Restrictions({@Restrict({"SECURITY_ADMIN"}), @Restrict({"RESTRICTED_SECURITY_ADMIN"})})
  public static void validatePasswordDynamic(String password, String fieldName) {
    boolean passed = true;
    if (fieldName.contains("root")) {
      fieldName = "setup.rootPassword";
    }
    if (fieldName.contains("system")) {
      fieldName = "setup.systemPasswords";
    }
    if (PasswordUtil.isNotValid(password)) {
      Validation.addError(fieldName + ".value", "setup.password.notValid");
      passed = false;
    }
    if (passed) {
      String validation = PasswordUtil.validatePassword(password);
      if (StringUtils.isNotBlank(validation)) {
        Validation.addError(fieldName + ".value", validation);
      }
    }

    if (Validation.hasErrors()) {
      renderJSON(ValidationResponse.collectErrors());
    } else {
      renderJSON(ValidationResponse.valid());
    }
  }
示例#3
0
    private boolean localValidation(String fieldName) {
      boolean passed = true;

      if (PasswordUtil.isNotValid(value)) {
        Validation.addError(fieldName + ".value", "setup.password.notValid");
        passed = false;
      }
      if (PasswordUtil.isNotValid(confirm)) {
        Validation.addError(fieldName + ".confirm", "setup.password.notValid");
        passed = false;
      }

      value = PasswordUtil.decryptedValue(value);
      confirm = PasswordUtil.decryptedValue(confirm);
      Validation.valid(fieldName, this);
      if (!StringUtils.equals(value, confirm)) {
        Validation.addError(fieldName + ".value", "setup.password.notEqual");
        passed = false;
      }

      return passed;
    }