Пример #1
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;
    }
Пример #2
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;
  }
Пример #3
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")));
    }
  }
Пример #4
0
 public String hashedValue() {
   String decrypted = PasswordUtil.decryptedValue(value);
   return PasswordUtil.generateHash(decrypted);
 }