Commit 8bf8d5cb authored by Philip Roberts's avatar Philip Roberts

Add automated setup support on first run

If <setup>true</setup> does not exist in openfire.xml (i.e. setup is not complete, and a block does exist called <autosetup> with a <run>true</run> property inside it, that looks like this:

```
    <autosetup>
        <run>true</run>

        <locale>en</locale>
        <xmpp>
            <domain>localhost</domain>
            <fqdn>localhost</fqdn>
        </xmpp>
        <encryption>
            <algorithm>AES</algorithm>
            <key>some-key</key>
        </encryption>
        <database>
            <mode>standard</mode>
            <defaultProvider>
                <driver>org.postgresql.Driver</driver>
                <serverURL>jdbc:postgresql://localhost:5432/a-database</serverURL>
                <username>a-database</username>
                <password>a-password</password>
            </defaultProvider>
        </database>
        <admin>
            <email>admin@example.com</email>
            <password>admin</password>
        </admin>
    </autosetup>
```

Then setup will be run on first launch, and the `<autosetup />` section will be deleted from openfire.xml
parent 9217686a
...@@ -50,6 +50,7 @@ import org.jivesoftware.openfire.session.RemoteSessionLocator; ...@@ -50,6 +50,7 @@ import org.jivesoftware.openfire.session.RemoteSessionLocator;
import org.jivesoftware.openfire.spi.*; import org.jivesoftware.openfire.spi.*;
import org.jivesoftware.openfire.transport.TransportHandler; import org.jivesoftware.openfire.transport.TransportHandler;
import org.jivesoftware.openfire.update.UpdateManager; import org.jivesoftware.openfire.update.UpdateManager;
import org.jivesoftware.openfire.user.User;
import org.jivesoftware.openfire.user.UserManager; import org.jivesoftware.openfire.user.UserManager;
import org.jivesoftware.openfire.vcard.VCardManager; import org.jivesoftware.openfire.vcard.VCardManager;
import org.jivesoftware.util.*; import org.jivesoftware.util.*;
...@@ -323,21 +324,123 @@ public class XMPPServer { ...@@ -323,21 +324,123 @@ public class XMPPServer {
xmppServerInfo = new XMPPServerInfoImpl(new Date()); xmppServerInfo = new XMPPServerInfoImpl(new Date());
initialized = true; initialized = true;
if (setupMode && "true".equals(JiveGlobals.getXMLProperty("autosetup.run"))) {
this.runAutoSetup();
JiveGlobals.deleteXMLProperty("autosetup");
JiveGlobals.deleteProperty("autosetup");
}
} }
/** void runAutoSetup() {
* Finish the setup process. Because this method is meant to be called from inside // steps from setup-datasource-standard.jsp
* the Admin console plugin, it spawns its own thread to do the work so that the // do this first so that other changes persist
* class loader is correct. if ("standard".equals(JiveGlobals.getXMLProperty("autosetup.database.mode"))) {
*/ JiveGlobals.setXMLProperty("database.defaultProvider.driver", JiveGlobals.getXMLProperty("autosetup.database.defaultProvider.driver"));
public void finishSetup() { JiveGlobals.setXMLProperty("database.defaultProvider.serverURL", JiveGlobals.getXMLProperty("autosetup.database.defaultProvider.serverURL"));
if (!setupMode) { JiveGlobals.setXMLProperty("database.defaultProvider.username", JiveGlobals.getXMLProperty("autosetup.database.defaultProvider.username"));
return; JiveGlobals.setXMLProperty("database.defaultProvider.password", JiveGlobals.getXMLProperty("autosetup.database.defaultProvider.password"));
int minConnections;
int maxConnections;
double connectionTimeout;
try {
minConnections = Integer.parseInt(
JiveGlobals.getXMLProperty("database.defaultProvider.minConnections"));
} }
// Make sure that setup finished correctly. catch (Exception e) {
if ("true".equals(JiveGlobals.getXMLProperty("setup"))) { minConnections = 5;
// Iterate through all the provided XML properties and set the ones that haven't }
// already been touched by setup prior to this method being called. try {
maxConnections = Integer.parseInt(
JiveGlobals.getXMLProperty("database.defaultProvider.maxConnections"));
}
catch (Exception e) {
maxConnections = 25;
}
try {
connectionTimeout = Double.parseDouble(
JiveGlobals.getXMLProperty("database.defaultProvider.connectionTimeout"));
}
catch (Exception e) {
connectionTimeout = 1.0;
}
JiveGlobals.setXMLProperty("database.defaultProvider.minConnections",
Integer.toString(minConnections));
JiveGlobals.setXMLProperty("database.defaultProvider.maxConnections",
Integer.toString(maxConnections));
JiveGlobals.setXMLProperty("database.defaultProvider.connectionTimeout",
Double.toString(connectionTimeout));
}
// mark setup as done, so that other things can be written to the DB
JiveGlobals.setXMLProperty("setup","true");
// steps from index.jsp
String localeCode = JiveGlobals.getXMLProperty("autosetup.locale");
logger.warn("Setting locale to" + localeCode);
JiveGlobals.setLocale(LocaleUtils.localeCodeToLocale(localeCode.trim()));
// steps from setup-host-settings.jsp
JiveGlobals.setXMLProperty("xmpp.domain", JiveGlobals.getXMLProperty("autosetup.xmpp.domain"));
JiveGlobals.setXMLProperty("xmpp.fqdn", JiveGlobals.getXMLProperty("autosetup.xmpp.fqdn"));
JiveGlobals.migrateProperty("xmpp.domain");
JiveGlobals.migrateProperty("xmpp.fqdn");
JiveGlobals.setProperty("xmpp.socket.ssl.active", JiveGlobals.getXMLProperty("autosetup.xmpp.socket.ssl.active", "true"));
JiveGlobals.setProperty("xmpp.auth.anonymous", JiveGlobals.getXMLProperty("autosetup.xmpp.auth.anonymous", "false"));
JiveGlobals.setupPropertyEncryptionAlgorithm(JiveGlobals.getXMLProperty("autosetup.encryption.algorithm", "Blowfish")); // or AES
JiveGlobals.setupPropertyEncryptionKey(JiveGlobals.getXMLProperty("autosetup.encryption.key", null));
// steps from setup-profile-settings.jsp
if ("default".equals(JiveGlobals.getXMLProperty("autosetup.authprovider.mode", "default"))) {
JiveGlobals.setXMLProperty("connectionProvider.className",
"org.jivesoftware.database.DefaultConnectionProvider");
JiveGlobals.setProperty("provider.auth.className", JiveGlobals.getXMLProperty("provider.auth.className",
org.jivesoftware.openfire.auth.DefaultAuthProvider.class.getName()));
JiveGlobals.setProperty("provider.user.className", JiveGlobals.getXMLProperty("provider.user.className",
org.jivesoftware.openfire.user.DefaultUserProvider.class.getName()));
JiveGlobals.setProperty("provider.group.className", JiveGlobals.getXMLProperty("provider.group.className",
org.jivesoftware.openfire.group.DefaultGroupProvider.class.getName()));
JiveGlobals.setProperty("provider.vcard.className", JiveGlobals.getXMLProperty("provider.vcard.className",
org.jivesoftware.openfire.vcard.DefaultVCardProvider.class.getName()));
JiveGlobals.setProperty("provider.lockout.className", JiveGlobals.getXMLProperty("provider.lockout.className",
org.jivesoftware.openfire.lockout.DefaultLockOutProvider.class.getName()));
JiveGlobals.setProperty("provider.securityAudit.className", JiveGlobals.getXMLProperty("provider.securityAudit.className",
org.jivesoftware.openfire.security.DefaultSecurityAuditProvider.class.getName()));
JiveGlobals.setProperty("provider.admin.className", JiveGlobals.getXMLProperty("provider.admin.className",
org.jivesoftware.openfire.admin.DefaultAdminProvider.class.getName()));
// make configurable?
JiveGlobals.setProperty("user.scramHashedPasswordOnly", "true");
}
// steps from setup-admin-settings.jsp
try {
User adminUser = UserManager.getInstance().getUser("admin");
adminUser.setPassword(JiveGlobals.getXMLProperty("autosetup.admin.password"));
adminUser.setEmail(JiveGlobals.getXMLProperty("autosetup.admin.email"));
Date now = new Date();
adminUser.setCreationDate(now);
adminUser.setModificationDate(now);
} catch (Exception e) {
e.printStackTrace();
logger.warn("There was an unexpected error encountered when "
+ "setting the new admin information. Please check your error "
+ "logs and try to remedy the problem.");
}
// finish setup
this.finalSetupSteps();
setupMode = false;
}
private void finalSetupSteps() {
for (String propName : JiveGlobals.getXMLPropertyNames()) { for (String propName : JiveGlobals.getXMLPropertyNames()) {
if (JiveGlobals.getProperty(propName) == null) { if (JiveGlobals.getProperty(propName) == null) {
JiveGlobals.setProperty(propName, JiveGlobals.getXMLProperty(propName)); JiveGlobals.setProperty(propName, JiveGlobals.getXMLProperty(propName));
...@@ -367,6 +470,24 @@ public class XMPPServer { ...@@ -367,6 +470,24 @@ public class XMPPServer {
// Initialize list of admins now (before we restart Jetty) // Initialize list of admins now (before we restart Jetty)
AdminManager.getInstance().getAdminAccounts(); AdminManager.getInstance().getAdminAccounts();
}
/**
* Finish the setup process. Because this method is meant to be called from inside
* the Admin console plugin, it spawns its own thread to do the work so that the
* class loader is correct.
*/
public void finishSetup() {
if (!setupMode) {
return;
}
this.finalSetupSteps();
// Make sure that setup finished correctly.
if ("true".equals(JiveGlobals.getXMLProperty("setup"))) {
// Iterate through all the provided XML properties and set the ones that haven't
// already been touched by setup prior to this method being called.
Thread finishSetup = new Thread() { Thread finishSetup = new Thread() {
@Override @Override
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment