示例#1
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());
    }
  }
示例#2
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");
        }
      }
    }
示例#3
0
 private static void protectField(String field) {
   String value = params.get(field);
   if (Validation.hasError(field)) {
     params.remove(field);
   } else if (StringUtils.isNotBlank(value)) {
     params.put(field, PasswordUtil.encryptedValue(value));
   }
 }
示例#4
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;
    }
示例#5
0
  private static Map<String, String> getUpdatedProperties(SetupForm setup) {
    Map<String, String> properties = Maps.newHashMap();
    // Network
    properties.put(ConfigProperty.NAMESERVERS, setup.nameservers);
    properties.put(ConfigProperty.NTPSERVERS, setup.ntpservers);

    // Passwords
    properties.put(ConfigProperty.ROOT_PASSWORD, setup.rootPassword.hashedValue());
    // Use the same password for proxyuser, svcuser, sysmonitor
    properties.put(
        ConfigProperty.PROXYUSER_PASSWORD,
        PasswordUtil.decryptedValue(setup.systemPasswords.value));
    properties.put(ConfigProperty.SVCUSER_PASSWORD, setup.systemPasswords.hashedValue());
    properties.put(ConfigProperty.SYSMONITOR_PASSWORD, setup.systemPasswords.hashedValue());

    // SMTP settings
    if (StringUtils.isNotBlank(setup.smtpServer)) {
      properties.put(ConfigProperty.SMTP_SERVER, setup.smtpServer);
      properties.put(ConfigProperty.SMTP_ENABLE_TLS, setup.smtpEnableTls);
      properties.put(ConfigProperty.SMTP_FROM_ADDRESS, setup.smtpFrom);
      properties.put(ConfigProperty.SMTP_AUTH_TYPE, setup.smtpAuthType);

      if (!StringUtils.equalsIgnoreCase(setup.smtpAuthType, "None")) {
        properties.put(ConfigProperty.SMTP_USERNAME, setup.smtpUsername);
        properties.put(
            ConfigProperty.SMTP_PASSWORD, PasswordUtil.decryptedValue(setup.smtpPassword));
      }
    }

    if (!SetupUtils.isOssBuild()) {
      // ConnectEMC settings
      properties.put(ConfigProperty.CONNECTEMC_TRANSPORT, setup.connectEmcTransport);
      if (!StringUtils.equalsIgnoreCase(setup.connectEmcTransport, "None")) {
        properties.put(ConfigProperty.CONNECTEMC_NOTIFY_EMAIL, setup.connectEmcNotifyEmail);
      }
    }
    return properties;
  }
示例#6
0
  /**
   * Tests the SMTP settings from the initial setup form, rendering the result as JSON.
   *
   * @param setup the initial setup form.
   */
  @Restrictions({
    @Restrict({"SYSTEM_ADMIN", "SECURITY_ADMIN"}),
    @Restrict({"RESTRICTED_SYSTEM_ADMIN", "RESTRICTED_SECURITY_ADMIN"})
  })
  public static void testSmtpSettings(SetupForm setup) {
    setup.validateSmtp();
    Validation.required("setup.smtpTo", setup.smtpTo);
    Validation.email("setup.smtpTo", setup.smtpTo);
    if (Validation.hasErrors()) {
      renderJSON(ValidationResponse.collectErrors());
    }

    MailSettingsValidator.Settings settings = new MailSettingsValidator.Settings();

    if (StringUtils.isNotEmpty(setup.nameservers)
        && !InetAddresses.isInetAddress(setup.smtpServer)) {
      Set<String> ips = Sets.newHashSet(setup.nameservers.split(","));

      try {
        settings.server = DnsUtils.getHostIpAddress(ips, setup.smtpServer).getHostAddress();
      } catch (ViPRException e) {
        renderJSON(ValidationResponse.invalid(e.getMessage()));
      }
    } else {
      settings.server = setup.smtpServer;
    }
    settings.port = ConfigProperties.getPort(setup.smtpPort, setup.smtpEnableTls);
    settings.username = setup.smtpUsername;
    settings.password = PasswordUtil.decryptedValue(setup.smtpPassword);
    settings.channel = StringUtils.equals("yes", setup.smtpEnableTls) ? "starttls" : "clear";
    settings.authType = setup.smtpAuthType;
    settings.fromAddress = setup.smtpFrom;

    try {
      MailSettingsValidator.validate(settings, setup.smtpTo);
    } catch (RuntimeException e) {
      Logger.error(e, "Failed to send email");
      Validation.addError(null, "setup.testEmail.failure", e.getMessage());
      if (StringUtils.isEmpty(setup.nameservers)) {
        Validation.addError(null, "setup.smtpServer.invalidEmptyNameserver");
      }
    }

    if (Validation.hasErrors()) {
      renderJSON(ValidationResponse.collectErrors());
    } else {
      renderJSON(ValidationResponse.valid(MessagesUtils.get("setup.testEmail.success")));
    }
  }
示例#7
0
 private void remoteValidation(String fieldName) {
   String validation = PasswordUtil.validatePassword(value);
   if (StringUtils.isNotBlank(validation)) {
     Validation.addError(fieldName + ".value", validation);
   }
 }
示例#8
0
 public String hashedValue() {
   String decrypted = PasswordUtil.decryptedValue(value);
   return PasswordUtil.generateHash(decrypted);
 }
示例#9
0
 public static String getPasswordValidPromptRule() {
   String promptString = PasswordUtil.getPasswordValidPromptRules(Constants.PASSWORD_VALID_PROMPT);
   return promptString;
 }