]> source.dussan.org Git - gitblit.git/commitdiff
Checkbox to automatically set the new ssl certificate alias
authorJames Moger <james.moger@gitblit.com>
Wed, 5 Dec 2012 22:36:16 +0000 (17:36 -0500)
committerJames Moger <james.moger@gitblit.com>
Wed, 5 Dec 2012 22:36:16 +0000 (17:36 -0500)
src/com/gitblit/authority/GitblitAuthority.java
src/com/gitblit/authority/NewSSLCertificateDialog.java
src/com/gitblit/wicket/GitBlitWebApp.properties

index d97a8e3938fd27edfdeefb370254cdba10e11629..59cd22e39492b7080e9bf3fd3a8a492522c265aa 100644 (file)
@@ -607,7 +607,8 @@ public class GitblitAuthority extends JFrame implements X509Log {
                                }\r
                                final Date expires = dialog.getExpiration();\r
                                final String hostname = dialog.getHostname();\r
-\r
+                               final boolean serveCertificate = dialog.isServeCertificate();\r
+                               \r
                                AuthorityWorker worker = new AuthorityWorker(GitblitAuthority.this) {\r
 \r
                                        @Override\r
@@ -623,17 +624,31 @@ public class GitblitAuthority extends JFrame implements X509Log {
                                                \r
                                                // generate new SSL certificate\r
                                                X509Metadata metadata = new X509Metadata(hostname, caKeystorePassword);\r
+                                               setMetadataDefaults(metadata);\r
                                                metadata.notAfter = expires;\r
                                                File serverKeystoreFile = new File(folder, X509Utils.SERVER_KEY_STORE);\r
                                                X509Certificate cert = X509Utils.newSSLCertificate(metadata, caPrivateKey, caCert, serverKeystoreFile, GitblitAuthority.this);\r
-                                               return cert != null;\r
+                                               boolean hasCert = cert != null;\r
+                                               if (hasCert && serveCertificate) {\r
+                                                       // update Gitblit https connector alias\r
+                                                       Map<String, String> updates = new HashMap<String, String>();\r
+                                                       updates.put(Keys.server.certificateAlias, metadata.commonName);\r
+                                                       gitblitSettings.saveSettings(updates);\r
+                                               }\r
+                                               return hasCert;\r
                                        }\r
 \r
                                        @Override\r
                                        protected void onSuccess() {\r
-                                               JOptionPane.showMessageDialog(GitblitAuthority.this, \r
+                                               if (serveCertificate) {\r
+                                                       JOptionPane.showMessageDialog(GitblitAuthority.this, \r
+                                                                       MessageFormat.format(Translation.get("gb.sslCertificateGeneratedRestart"), hostname),\r
+                                                                       Translation.get("gb.newSSLCertificate"), JOptionPane.INFORMATION_MESSAGE);\r
+                                               } else {\r
+                                                       JOptionPane.showMessageDialog(GitblitAuthority.this, \r
                                                                MessageFormat.format(Translation.get("gb.sslCertificateGenerated"), hostname),\r
                                                                Translation.get("gb.newSSLCertificate"), JOptionPane.INFORMATION_MESSAGE);\r
+                                               }\r
                                        }\r
                                };\r
                                \r
index 1ff542a201cd81956756f7ca9f60e0128a67dbbc..821e9e9fb51f2ef8e6b73fcc7ce991ee2adb510b 100644 (file)
@@ -24,6 +24,7 @@ import java.awt.event.ActionListener;
 import java.util.Date;\r
 \r
 import javax.swing.JButton;\r
+import javax.swing.JCheckBox;\r
 import javax.swing.JDialog;\r
 import javax.swing.JLabel;\r
 import javax.swing.JOptionPane;\r
@@ -41,6 +42,7 @@ public class NewSSLCertificateDialog extends JDialog {
        \r
        JDateChooser expirationDate;\r
        JTextField hostname;\r
+       JCheckBox serveCertificate;\r
        boolean isCanceled = true;\r
 \r
        public NewSSLCertificateDialog(Frame owner, Date defaultExpiration) {\r
@@ -60,6 +62,7 @@ public class NewSSLCertificateDialog extends JDialog {
                \r
                expirationDate = new JDateChooser(defaultExpiration);\r
                hostname = new JTextField(20);\r
+               serveCertificate = new JCheckBox(Translation.get("gb.serveCertificate"), true);\r
                \r
                JPanel panel = new JPanel(new GridLayout(0, 2, Utils.MARGIN, Utils.MARGIN));\r
                \r
@@ -69,6 +72,9 @@ public class NewSSLCertificateDialog extends JDialog {
                panel.add(new JLabel(Translation.get("gb.expires")));\r
                panel.add(expirationDate);\r
                \r
+               panel.add(new JLabel(""));\r
+               panel.add(serveCertificate);\r
+               \r
                JButton ok = new JButton(Translation.get("gb.ok"));\r
                ok.addActionListener(new ActionListener() {\r
                        public void actionPerformed(ActionEvent e) {\r
@@ -123,7 +129,11 @@ public class NewSSLCertificateDialog extends JDialog {
        public Date getExpiration() {\r
                return expirationDate.getDate();\r
        }\r
-       \r
+\r
+       public boolean isServeCertificate() {\r
+               return serveCertificate.isSelected();\r
+       }\r
+\r
        public boolean isCanceled() {\r
                return isCanceled;\r
        }\r
index 7ce752624d2037c519d24012c40dc46d27ffdc4f..4f4d60e026983c5f770627467727793f8c00f648 100644 (file)
@@ -434,4 +434,6 @@ gb.jceWarning = Your Java Runtime Environment does not have the \"JCE Unlimited
 gb.maxActivityCommits = max activity commits\r
 gb.maxActivityCommitsDescription = maximum number of commits to contribute to the Activity page\r
 gb.noMaximum = no maximum\r
-gb.attributes = attributes
\ No newline at end of file
+gb.attributes = attributes\r
+gb.serveCertificate = serve https with this certificate\r
+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}''.
\ No newline at end of file