📄 installaction.java
字号:
PropertyUtil.getPropertyUtil().setProperty(0, null, "webServer.protocol",
(String) seq.getAttribute(WebServerForm.ATTR_WEB_SERVER_PROTOCOL, "https"), seq.getSession());
PropertyList l = PropertyList.createFromTextFieldText((String) seq.getAttribute(
WebServerForm.ATTR_LISTENING_INTERFACES, ""));
PropertyUtil.getPropertyUtil().setProperty(0, null, "webServer.bindAddress", l.getAsPropertyText(), seq.getSession());
l = PropertyList.createFromTextFieldText((String) seq.getAttribute(WebServerForm.ATTR_VALID_EXTERNAL_HOSTS, ""));
PropertyUtil.getPropertyUtil().setProperty(0, null, "webServer.validExternalHostnames",
l.getAsPropertyText(), seq.getSession());
PropertyUtil.getPropertyUtil().setProperty(0, null, "webServer.invalidHostnameAction",
(String) seq.getAttribute(WebServerForm.ATTR_INVALID_HOSTNAME_ACTION, "none"), seq.getSession());
return new WizardActionStatus(WizardActionStatus.COMPLETED_OK, "installation.install.status.webServerConfigured");
} catch (Exception e) {
log.error("Failed to configure web server.", e);
return new WizardActionStatus(WizardActionStatus.COMPLETED_WITH_ERRORS,
"installation.install.status.failedToConfigureWebServer", e.getMessage());
}
}
List configureSuperUser(AbstractWizardSequence seq, HttpServletRequest request) {
List l = new ArrayList();
String superUser = (String) seq.getAttribute(ConfigureSuperUserForm.ATTR_SUPER_USER, null);
String udbName = (String) seq.getAttribute(SelectUserDatabaseForm.ATTR_USER_DATABASE, "builtIn");
String superUserPassword = (String) seq.getAttribute(ConfigureSuperUserForm.ATTR_SUPER_USER_PASSWORD, "");
String email = (String) seq.getAttribute(ConfigureSuperUserForm.ATTR_SUPER_USER_EMAIL, "");
// TODO implement as special policy instead of default administrator
try {
UserDatabase udb = UserDatabaseManager.getInstance().getUserDatabase(udbName);
if (!udb.isOpen()) {
udb.open(CoreServlet.getServlet());
}
/* If the new database supports account creation, then create
* the selected super user if it does not exist
*/
if(udb.supportsAccountCreation()) {
try {
User user = udb.getAccount(superUser);
boolean disabled = !PolicyUtil.isEnabled(user);
SessionInfo session = this.getSessionInfo();
if (disabled) {
if (log.isInfoEnabled())
log.info("Re-enabling user " + user.getPrincipalName());
PolicyUtil.setEnabled(user, true, null, session);
}
CoreServlet.getServlet().getLogonController().unlockUser(user.getPrincipalName());
// (Probably) Already exists, just update
CoreServlet.getServlet().getUserDatabase().updateAccount(user, email, user.getFullname(), user.getRoles(), user.getAttributes());
l.add(new WizardActionStatus(WizardActionStatus.COMPLETED_OK, "installation.install.status.superUserUpdated"));
}
catch(Exception e) {
//e.printStackTrace();
udb.createAccount(superUser, superUserPassword,
email, "Super User",
new Role[] {}, new Properties());
l.add(new WizardActionStatus(WizardActionStatus.COMPLETED_OK, "installation.install.status.superUserCreated"));
}
}
String oldSuperUserList = PropertyUtil.getPropertyUtil().setProperty(0, null, "security.administrators", superUser, seq.getSession());
/*
* If the database has changed and the old database supports
* account creation then remove the old super user
*/
if(!udbName.equals(oldDatabase)) {
PropertyList pl = new PropertyList(oldSuperUserList);
String oldSuperUser = pl.size() > 0 ? pl.get(0).toString() : null;
if(oldSuperUser != null && CoreServlet.getServlet().getUserDatabase().supportsAccountCreation() && !superUser.equals(oldSuperUser)) {
try {
CoreServlet.getServlet().getUserDatabase().deleteAccount(
CoreServlet.getServlet().getUserDatabase().getAccount(oldSuperUser));
l.add(new WizardActionStatus(WizardActionStatus.COMPLETED_OK, "installation.install.status.oldSuperUserDeleted"));
}
catch(Exception e) {
}
}
}
/*
* Set the super user password
*/
if (!superUserPassword.equals("")) {
udb.changePassword(superUser, superUserPassword, false);
l.add(new WizardActionStatus(WizardActionStatus.COMPLETED_OK, "installation.install.status.superUserPasswordSet"));
}
} catch (Exception e) {
log.error("Failed to configure super user.", e);
l.add(new WizardActionStatus(WizardActionStatus.COMPLETED_WITH_ERRORS,
"installation.install.status.failedToConfigureSuperUser", e.getMessage()));
}
return l;
}
WizardActionStatus configureCertificate(AbstractWizardSequence seq) {
String certSource = (String) seq.getAttribute(SelectCertificateSourceForm.ATTR_CERTIFICATE_SOURCE, "");
if (certSource.equals(SelectCertificateSourceForm.CREATE_NEW_CERTIFICATE)) {
return createNewCertificate(seq);
} else if (certSource.equals(SelectCertificateSourceForm.IMPORT_EXISTING_CERTIFICATE)) {
return importCertificate(seq);
} else {
return new WizardActionStatus(WizardActionStatus.COMPLETED_OK, "installation.install.status.usedCurrentCertificate");
}
}
WizardActionStatus createNewCertificate(AbstractWizardSequence seq) {
try {
KeyStoreManager mgr = KeyStoreManager.getInstance(KeyStoreManager.DEFAULT_KEY_STORE);
if (mgr.isKeyStoreExists()) {
mgr.deleteKeyStore();
}
String alias = InstallAction.SSLEXPLORER_SERVER;
String passphrase = (String) seq.getAttribute(SetKeyStorePasswordForm.ATTR_KEY_STORE_PASSWORD, null);
if (passphrase != null && !passphrase.equals("")) {
PropertyUtil.getPropertyUtil().setProperty(0, null, "webServer.keystore.sslCertificate.password",
passphrase, seq.getSession());
mgr.setStorePassword(passphrase);
}
mgr.createKeyStore();
String dname = "cn=" + Util.escapeForDNString((String)seq.getAttribute(CreateNewCertificateForm.ATTR_HOSTNAME, "")) + ", ou="
+ Util.escapeForDNString((String)seq.getAttribute(CreateNewCertificateForm.ATTR_ORGANISATIONAL_UNIT, "")) + ", o="
+ Util.escapeForDNString((String)seq.getAttribute(CreateNewCertificateForm.ATTR_COMPANY, "")) + ", l="
+ Util.escapeForDNString((String)seq.getAttribute(CreateNewCertificateForm.ATTR_CITY, "")) + ", st="
+ Util.escapeForDNString((String)seq.getAttribute(CreateNewCertificateForm.ATTR_STATE, "")) + ", c="
+ Util.escapeForDNString((String)seq.getAttribute(CreateNewCertificateForm.ATTR_COUNTRY_CODE, ""));
mgr.createKey(alias, dname);
CoreServlet.getServlet().getPropertyDatabase().setProperty(0, null, "webServer.keyStoreType", KeyStoreManager.TYPE_JKS.getName());
CoreServlet.getServlet().getPropertyDatabase().setProperty(0, null, "webServer.alias", alias);
CoreEvent coreEvent = new CoreEvent(this, CoreEventConstants.KEYSTORE_CERTIFICATE_CREATED, alias, null)
.addAttribute(CoreAttributeConstants.EVENT_ATTR_CERTIFICATE_ALIAS, alias)
.addAttribute(CreateNewCertificateForm.ATTR_HOSTNAME, (String)seq.getAttribute(CreateNewCertificateForm.ATTR_HOSTNAME, ""))
.addAttribute(CreateNewCertificateForm.ATTR_ORGANISATIONAL_UNIT, (String)seq.getAttribute(CreateNewCertificateForm.ATTR_ORGANISATIONAL_UNIT, ""))
.addAttribute(CreateNewCertificateForm.ATTR_COMPANY, (String)seq.getAttribute(CreateNewCertificateForm.ATTR_COMPANY, ""))
.addAttribute(CreateNewCertificateForm.ATTR_STATE, (String)seq.getAttribute(CreateNewCertificateForm.ATTR_STATE, ""))
.addAttribute(CreateNewCertificateForm.ATTR_CITY, (String)seq.getAttribute(CreateNewCertificateForm.ATTR_CITY, ""))
.addAttribute(CreateNewCertificateForm.ATTR_COUNTRY_CODE, (String)seq.getAttribute(CreateNewCertificateForm.ATTR_COUNTRY_CODE, ""));
CoreServlet.getServlet().fireCoreEvent(coreEvent);
} catch (Exception e) {
log.error("Failed to create keystore / certificate.", e);
return new WizardActionStatus(WizardActionStatus.COMPLETED_WITH_ERRORS,
"installation.install.status.failedToCreateNewCertificate", e.getMessage());
}
return new WizardActionStatus(WizardActionStatus.COMPLETED_OK, "installation.install.status.newCertificateCreated");
}
WizardActionStatus importCertificate(AbstractWizardSequence seq) {
try {
KeyStoreManager mgr = KeyStoreManager.getInstance(KeyStoreManager.DEFAULT_KEY_STORE);
if (mgr.isKeyStoreExists()) {
mgr.deleteKeyStore();
}
String alias = (String)seq.getAttribute(ImportExistingCertificateForm.ATTR_ALIAS, null);
String passphrase = (String) seq.getAttribute(ImportExistingCertificateForm.ATTR_PASSPHRASE, "");
KeyStoreType keyStoreType = mgr.getKeyStoreType((String) seq.getAttribute(ImportExistingCertificateForm.ATTR_KEY_STORE_TYPE, ""));
File uploadedFile = (File) seq.getAttribute(ImportExistingCertificateForm.ATTR_UPLOADED_FILE, null);
mgr.setStorePassword(passphrase);
if(keyStoreType.equals(KeyStoreManager.TYPE_PKCS12)) {
mgr.setKeyStoreType(KeyStoreManager.TYPE_JKS);
mgr.importPKCS12Key(uploadedFile, passphrase, alias);
} else {
FileOutputStream out = new FileOutputStream(mgr.getKeyStoreFile());
try {
FileInputStream in = new FileInputStream(uploadedFile);
try {
Util.copy(in, out);
} finally {
in.close();
}
} finally {
out.close();
}
}
CoreServlet.getServlet().getPropertyDatabase().setProperty(0, null, "webServer.alias", alias);
PropertyUtil.getPropertyUtil().setProperty(0, null, "webServer.keystore.sslCertificate.password",
passphrase, null);
CoreEvent coreEvent = new CoreEvent(this, CoreEventConstants.KEYSTORE_IMPORTED, null, null)
.addAttribute(CoreAttributeConstants.EVENT_ATTR_CERTIFICATE_ALIAS, alias)
.addAttribute(CreateNewCertificateForm.ATTR_HOSTNAME, (String)seq.getAttribute(CreateNewCertificateForm.ATTR_HOSTNAME, ""))
.addAttribute(CreateNewCertificateForm.ATTR_ORGANISATIONAL_UNIT, (String)seq.getAttribute(CreateNewCertificateForm.ATTR_ORGANISATIONAL_UNIT, ""))
.addAttribute(CreateNewCertificateForm.ATTR_COMPANY, (String)seq.getAttribute(CreateNewCertificateForm.ATTR_COMPANY, ""))
.addAttribute(CreateNewCertificateForm.ATTR_STATE, (String)seq.getAttribute(CreateNewCertificateForm.ATTR_STATE, ""))
.addAttribute(CreateNewCertificateForm.ATTR_CITY, (String)seq.getAttribute(CreateNewCertificateForm.ATTR_CITY, ""))
.addAttribute(CreateNewCertificateForm.ATTR_COUNTRY_CODE, (String)seq.getAttribute(CreateNewCertificateForm.ATTR_COUNTRY_CODE, ""));
CoreServlet.getServlet().fireCoreEvent(coreEvent);
} catch (Exception e) {
log.error("Failed to create keystore / certificate.");
return new WizardActionStatus(WizardActionStatus.COMPLETED_WITH_ERRORS,
"installation.install.status.failedToImportCertificate", e.getMessage());
} finally {
}
return new WizardActionStatus(WizardActionStatus.COMPLETED_OK, "installation.install.status.certificateImported");
}
class ExtensionLicenseAgreementCallback implements LicenseAgreementCallback {
private ExtensionBundle bundle;
private RepositoryStore repStore;
private List actionStatus;
public ExtensionLicenseAgreementCallback(RepositoryStore repStore, ExtensionBundle bundle, List actionStatus) {
this.bundle = bundle;
this.repStore = repStore;
this.actionStatus = actionStatus;
}
public void licenseAccepted(HttpServletRequest request) {
try {
ExtensionStore.getInstance().postInstallExtension(bundle, request);
actionStatus.add(new WizardActionStatus(WizardActionStatus.COMPLETED_OK,
"installation.install.status.installedExtension", bundle.getName(), bundle.getId()));
}
catch(Exception e) {
log.error("Failed to install extension " + bundle.getId() + ".", e);
actionStatus.add(new WizardActionStatus(WizardActionStatus.COMPLETED_WITH_ERRORS,
"installation.install.status.failedToInstallExtension", bundle.getId(), e.getMessage()));
}
}
public void licenseRejected(HttpServletRequest request) {
actionStatus.add(new WizardActionStatus(WizardActionStatus.COMPLETED_WITH_ERRORS,
"installation.install.status.licenseRejected", bundle.getId()));
// Remove the repository entry if it is in use
if(ExtensionStore.getInstance().isRepositoryBacked()) {
try {
repStore.removeEntry(bundle.getId() + ".zip");
} catch (IOException ex) {
}
}
// Remove the expanded bundle
if (bundle.getBaseDir().exists()) {
Util.delTree(bundle.getBaseDir());
}
// Reload the extension store
try {
ExtensionStore.getInstance().reload(bundle.getId());
}
catch(Exception e) {
log.error("Failed to reload extension store.");
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -