Ejemplo n.º 1
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")));
    }
  }
Ejemplo n.º 2
0
  public boolean writeClasses(ConstantPool consts, ConstantPool sharedconsts) {
    ClassClass classes[] = ClassClass.getClassVector(classMaker);
    ClassClass.setTypes();

    // write out some constant pool stuff here,
    writeProlog();

    try {
      writeAllNativeTables(classes);
    } catch (RuntimeException e) {
      out.flush();
      System.out.println(e);
      e.printStackTrace(System.out);
      formatError = true;
    }
    writeEpilog();
    return (!formatError) && (!out.checkError());
  }