}\r
\r
X509Metadata metadata = new X509Metadata("localhost", caKeystorePassword);\r
+ setMetadataDefaults(metadata);\r
X509Utils.prepareX509Infrastructure(metadata, folder, this);\r
return true;\r
}\r
}\r
\r
Date notAfter = metadata.notAfter;\r
- metadata.serverHostname = gitblitSettings.getString(Keys.web.siteName, Constants.NAME);\r
- if (StringUtils.isEmpty(metadata.serverHostname)) {\r
- metadata.serverHostname = Constants.NAME;\r
- }\r
- UserModel user = ucm.user; \r
- \r
- // set default values from config file\r
- File certificatesConfigFile = new File(folder, X509Utils.CA_CONFIG);\r
- FileBasedConfig config = new FileBasedConfig(certificatesConfigFile, FS.detect());\r
- if (certificatesConfigFile.exists()) {\r
- try {\r
- config.load();\r
- } catch (Exception e) {\r
- Utils.showException(GitblitAuthority.this, e);\r
- }\r
- NewCertificateConfig certificateConfig = NewCertificateConfig.KEY.parse(config);\r
- certificateConfig.update(metadata);\r
- }\r
- \r
- // restore expiration date\r
+ setMetadataDefaults(metadata);\r
metadata.notAfter = notAfter;\r
\r
// set user's specified OID values\r
+ UserModel user = ucm.user; \r
if (!StringUtils.isEmpty(user.organizationalUnit)) {\r
metadata.oids.put("OU", user.organizationalUnit);\r
}\r
if (ucm.expires == null || metadata.notAfter.before(ucm.expires)) {\r
ucm.expires = metadata.notAfter;\r
}\r
- ucm.update(config);\r
- try {\r
- config.save();\r
- } catch (Exception e) {\r
- Utils.showException(GitblitAuthority.this, e);\r
- }\r
+ \r
+ updateAuthorityConfig(ucm);\r
\r
// refresh user\r
ucm.certs = null;\r
}\r
return false;\r
}\r
+ \r
+ private void setMetadataDefaults(X509Metadata metadata) {\r
+ metadata.serverHostname = gitblitSettings.getString(Keys.web.siteName, Constants.NAME);\r
+ if (StringUtils.isEmpty(metadata.serverHostname)) {\r
+ metadata.serverHostname = Constants.NAME;\r
+ }\r
+ \r
+ // set default values from config file\r
+ File certificatesConfigFile = new File(folder, X509Utils.CA_CONFIG);\r
+ FileBasedConfig config = new FileBasedConfig(certificatesConfigFile, FS.detect());\r
+ if (certificatesConfigFile.exists()) {\r
+ try {\r
+ config.load();\r
+ } catch (Exception e) {\r
+ Utils.showException(GitblitAuthority.this, e);\r
+ }\r
+ NewCertificateConfig certificateConfig = NewCertificateConfig.KEY.parse(config);\r
+ certificateConfig.update(metadata);\r
+ }\r
+ }\r
+ \r
+ private void updateAuthorityConfig(UserCertificateModel ucm) {\r
+ File certificatesConfigFile = new File(folder, X509Utils.CA_CONFIG);\r
+ FileBasedConfig config = new FileBasedConfig(certificatesConfigFile, FS.detect());\r
+ if (certificatesConfigFile.exists()) {\r
+ try {\r
+ config.load();\r
+ } catch (Exception e) {\r
+ Utils.showException(GitblitAuthority.this, e);\r
+ }\r
+ }\r
+ ucm.update(config);\r
+ try {\r
+ config.save();\r
+ } catch (Exception e) {\r
+ Utils.showException(GitblitAuthority.this, e);\r
+ }\r
+ }\r
}\r