Skip to content

Commit

Permalink
Merge pull request #3453 from MisterZurk0n/hotfix/SSL-enable-for-back…
Browse files Browse the repository at this point in the history
…up-restore

Fix: enabling SSL via commandline arguments, when doing a backup/restore
  • Loading branch information
dizzzz committed Jun 24, 2020
2 parents febe3e5 + 6258072 commit 7bcc765
Showing 1 changed file with 17 additions and 5 deletions.
22 changes: 17 additions & 5 deletions exist-core/src/main/java/org/exist/backup/Main.java
Expand Up @@ -63,6 +63,8 @@ public class Main {
private static final String CREATE_DATABASE_PROP = "create-database";
private static final String BACKUP_DIR_PROP = "backup-dir";

public static final String SSL_ENABLE = "ssl-enable";

private static final String DEFAULT_USER = "admin";
private static final String DEFAULT_PASSWORD = "";
private static final String DEFAULT_URI = "xmldb:exist://";
Expand All @@ -85,7 +87,7 @@ public class Main {
.build();


/* user/pass arguments */
/* database connection arguments */
private static final Argument<String> userArg = stringArgument("-u", "--user")
.description("set user.")
.defaultValue(DEFAULT_USER)
Expand All @@ -96,7 +98,10 @@ public class Main {
private static final Argument<String> dbaPasswordArg = stringArgument("-P", "--dba-password")
.description("if the backup specifies a different password for the admin user, use this option to specify the new password. Otherwise you will get a permission denied")
.build();

private static final Argument<Boolean> useSslArg = optionArgument("-S", "--use-ssl")
.description("Use SSL by default for remote connections")
.defaultValue(false)
.build();

/* backup arguments */
private static final Argument<String> backupCollectionArg = stringArgument("-b", "--backup")
Expand Down Expand Up @@ -151,12 +156,18 @@ public static void process(final ParsedArguments arguments) {

final boolean guiMode = getBool(arguments, guiArg);
final boolean quiet = getBool(arguments, quietArg);
Optional.ofNullable(arguments.get(optionArg)).ifPresent(options -> options.forEach(properties::setProperty));
Optional.ofNullable(arguments.get(optionArg)).ifPresent(options -> {
options.forEach(properties::setProperty);
});

properties.setProperty(USER_PROP, arguments.get(userArg));
final String optionPass = arguments.get(passwordArg);
properties.setProperty(PASSWORD_PROP, optionPass);
final Optional<String> optionDbaPass = getOpt(arguments, dbaPasswordArg);
final boolean useSsl = getBool(arguments, useSslArg);
if (useSsl) {
properties.setProperty(SSL_ENABLE, "TRUE");
}

final Optional<String> backupCollection = getOpt(arguments, backupCollectionArg);
getOpt(arguments, backupOutputDirArg).ifPresent(backupOutputDir -> properties.setProperty(BACKUP_DIR_PROP, backupOutputDir.getAbsolutePath()));
Expand All @@ -174,7 +185,8 @@ public static void process(final ParsedArguments arguments) {
final Class<?> cl = Class.forName(properties.getProperty(DRIVER_PROP, DEFAULT_DRIVER));
database = (Database) cl.newInstance();
database.setProperty(CREATE_DATABASE_PROP, "true");

database.setProperty(SSL_ENABLE, properties.getProperty(SSL_ENABLE, "FALSE"));

if (properties.containsKey(CONFIGURATION_PROP)) {
database.setProperty(CONFIGURATION_PROP, properties.getProperty(CONFIGURATION_PROP));
}
Expand Down Expand Up @@ -439,7 +451,7 @@ private static void shutdown(final Collection root) {
public static void main(final String[] args) {
try {
final ParsedArguments arguments = CommandLineParser
.withArguments(userArg, passwordArg, dbaPasswordArg)
.withArguments(userArg, passwordArg, dbaPasswordArg, useSslArg)
.andArguments(backupCollectionArg, backupOutputDirArg, backupDeduplicateBlobs)
.andArguments(restoreArg, rebuildExpathRepoArg, overwriteAppsArg)
.andArguments(helpArg, guiArg, quietArg, optionArg)
Expand Down

0 comments on commit 7bcc765

Please sign in to comment.