Beispiel #1
0
  private boolean prepareX509Infrastructure() {
    if (caKeystorePassword == null) {
      JPasswordField pass = new JPasswordField(10);
      pass.setText(caKeystorePassword);
      pass.addAncestorListener(new RequestFocusListener());
      JPanel panel = new JPanel(new BorderLayout());
      panel.add(new JLabel(Translation.get("gb.enterKeystorePassword")), BorderLayout.NORTH);
      panel.add(pass, BorderLayout.CENTER);
      int result =
          JOptionPane.showConfirmDialog(
              GitblitAuthority.this,
              panel,
              Translation.get("gb.password"),
              JOptionPane.OK_CANCEL_OPTION);
      if (result == JOptionPane.OK_OPTION) {
        caKeystorePassword = new String(pass.getPassword());
      } else {
        return false;
      }
    }

    X509Metadata metadata = new X509Metadata("localhost", caKeystorePassword);
    setMetadataDefaults(metadata);
    metadata.notAfter = new Date(System.currentTimeMillis() + 10 * TimeUtils.ONEYEAR);
    X509Utils.prepareX509Infrastructure(metadata, folder, this);
    return true;
  }
Beispiel #2
0
  private boolean sendEmail(UserModel user, X509Metadata metadata, File zip) {
    // send email
    try {
      if (mail.isReady()) {
        Message message = mail.createMessage(user.emailAddress);
        message.setSubject("Your Gitblit client certificate for " + metadata.serverHostname);

        // body of email
        String body =
            X509Utils.processTemplate(
                new File(folder, X509Utils.CERTS + File.separator + "mail.tmpl"), metadata);
        if (StringUtils.isEmpty(body)) {
          body =
              MessageFormat.format(
                  "Hi {0}\n\nHere is your client certificate bundle.\nInside the zip file are installation instructions.",
                  user.getDisplayName());
        }
        Multipart mp = new MimeMultipart();
        MimeBodyPart messagePart = new MimeBodyPart();
        messagePart.setText(body);
        mp.addBodyPart(messagePart);

        // attach zip
        MimeBodyPart filePart = new MimeBodyPart();
        FileDataSource fds = new FileDataSource(zip);
        filePart.setDataHandler(new DataHandler(fds));
        filePart.setFileName(fds.getName());
        mp.addBodyPart(filePart);

        message.setContent(mp);

        mail.sendNow(message);
        return true;
      } else {
        JOptionPane.showMessageDialog(
            GitblitAuthority.this,
            "Sorry, the mail server settings are not configured properly.\nCan not send email.",
            Translation.get("gb.error"),
            JOptionPane.ERROR_MESSAGE);
      }
    } catch (Exception e) {
      Utils.showException(GitblitAuthority.this, e);
    }
    return false;
  }