James Moger
2012-12-05 d63157b22bb8a7294080be29ca0fca8ecda96db9
Checkbox to automatically set the new ssl certificate alias
3 files modified
37 ■■■■ changed files
src/com/gitblit/authority/GitblitAuthority.java 21 ●●●● patch | view | raw | blame | history
src/com/gitblit/authority/NewSSLCertificateDialog.java 12 ●●●●● patch | view | raw | blame | history
src/com/gitblit/wicket/GitBlitWebApp.properties 4 ●●● patch | view | raw | blame | history
src/com/gitblit/authority/GitblitAuthority.java
@@ -607,7 +607,8 @@
                }
                final Date expires = dialog.getExpiration();
                final String hostname = dialog.getHostname();
                final boolean serveCertificate = dialog.isServeCertificate();
                AuthorityWorker worker = new AuthorityWorker(GitblitAuthority.this) {
                    @Override
@@ -623,17 +624,31 @@
                        
                        // generate new SSL certificate
                        X509Metadata metadata = new X509Metadata(hostname, caKeystorePassword);
                        setMetadataDefaults(metadata);
                        metadata.notAfter = expires;
                        File serverKeystoreFile = new File(folder, X509Utils.SERVER_KEY_STORE);
                        X509Certificate cert = X509Utils.newSSLCertificate(metadata, caPrivateKey, caCert, serverKeystoreFile, GitblitAuthority.this);
                        return cert != null;
                        boolean hasCert = cert != null;
                        if (hasCert && serveCertificate) {
                            // update Gitblit https connector alias
                            Map<String, String> updates = new HashMap<String, String>();
                            updates.put(Keys.server.certificateAlias, metadata.commonName);
                            gitblitSettings.saveSettings(updates);
                        }
                        return hasCert;
                    }
                    @Override
                    protected void onSuccess() {
                        JOptionPane.showMessageDialog(GitblitAuthority.this,
                        if (serveCertificate) {
                            JOptionPane.showMessageDialog(GitblitAuthority.this,
                                    MessageFormat.format(Translation.get("gb.sslCertificateGeneratedRestart"), hostname),
                                    Translation.get("gb.newSSLCertificate"), JOptionPane.INFORMATION_MESSAGE);
                        } else {
                            JOptionPane.showMessageDialog(GitblitAuthority.this,
                                MessageFormat.format(Translation.get("gb.sslCertificateGenerated"), hostname),
                                Translation.get("gb.newSSLCertificate"), JOptionPane.INFORMATION_MESSAGE);
                        }
                    }
                };
                
src/com/gitblit/authority/NewSSLCertificateDialog.java
@@ -24,6 +24,7 @@
import java.util.Date;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
@@ -41,6 +42,7 @@
    
    JDateChooser expirationDate;
    JTextField hostname;
    JCheckBox serveCertificate;
    boolean isCanceled = true;
    public NewSSLCertificateDialog(Frame owner, Date defaultExpiration) {
@@ -60,6 +62,7 @@
        
        expirationDate = new JDateChooser(defaultExpiration);
        hostname = new JTextField(20);
        serveCertificate = new JCheckBox(Translation.get("gb.serveCertificate"), true);
        
        JPanel panel = new JPanel(new GridLayout(0, 2, Utils.MARGIN, Utils.MARGIN));
        
@@ -68,6 +71,9 @@
        panel.add(new JLabel(Translation.get("gb.expires")));
        panel.add(expirationDate);
        panel.add(new JLabel(""));
        panel.add(serveCertificate);
        
        JButton ok = new JButton(Translation.get("gb.ok"));
        ok.addActionListener(new ActionListener() {
@@ -123,7 +129,11 @@
    public Date getExpiration() {
        return expirationDate.getDate();
    }
    public boolean isServeCertificate() {
        return serveCertificate.isSelected();
    }
    public boolean isCanceled() {
        return isCanceled;
    }
src/com/gitblit/wicket/GitBlitWebApp.properties
@@ -434,4 +434,6 @@
gb.maxActivityCommits = max activity commits
gb.maxActivityCommitsDescription = maximum number of commits to contribute to the Activity page
gb.noMaximum = no maximum
gb.attributes = attributes
gb.attributes = attributes
gb.serveCertificate = serve https with this certificate
gb.sslCertificateGeneratedRestart = Successfully generated new server SSL certificate for {0}.\nYou must restart Gitblit to use the new certificate.\n\nIf you are launching with the '--alias' parameter you will have to set that to ''--alias {0}''.