Skip to content

Commit

Permalink
0005213: Allow to save startup parameters in local keystore or in Azure
Browse files Browse the repository at this point in the history
Key Vault
  • Loading branch information
Philip Marzullo committed Feb 10, 2022
1 parent 51b261e commit 053cf73
Show file tree
Hide file tree
Showing 25 changed files with 922 additions and 238 deletions.
Expand Up @@ -70,7 +70,23 @@ public TypedProperties reload() {
return properties;
}

@Override
public TypedProperties reload(File propFile) {
TypedProperties typedProperties = new TypedProperties(propFile);
return typedProperties;
}

@Override
public TypedProperties reload(Properties properties) {
TypedProperties typedProperties = new TypedProperties(properties);
return typedProperties;
}

@Override
public void init(File propertiesFile, Properties properties) {
}

@Override
public void save(Properties props, File propFile, String comments) throws IOException {
}
}
Expand Up @@ -30,9 +30,6 @@
import java.security.Provider;
import java.security.Security;
import java.sql.Connection;
import java.util.ArrayList;
import java.util.List;
import java.util.Properties;

import org.apache.commons.cli.CommandLine;
import org.apache.commons.cli.DefaultParser;
Expand All @@ -51,6 +48,7 @@
import org.jumpmind.symmetric.common.ServerConstants;
import org.jumpmind.symmetric.common.SystemConstants;
import org.jumpmind.symmetric.transport.TransportManagerFactory;
import org.jumpmind.symmetric.util.PropertiesUtil;
import org.jumpmind.symmetric.util.LogSummaryAppenderUtils;
import org.jumpmind.util.AppUtils;
import org.slf4j.Logger;
Expand Down Expand Up @@ -205,7 +203,7 @@ protected void configurePropertiesFile(CommandLine line) throws ParseException {
line.getOptionValue(OPTION_PROPERTIES_FILE));
}
} else if (line.hasOption(OPTION_ENGINE)) {
propertiesFile = findPropertiesFileForEngineWithName(line.getOptionValue(OPTION_ENGINE));
propertiesFile = PropertiesUtil.findPropertiesFileForEngineWithName(line.getOptionValue(OPTION_ENGINE));
if (propertiesFile == null || (propertiesFile != null && !propertiesFile.exists())) {
throw new SymmetricException(
"Could not find the properties file for the engine specified: %s",
Expand All @@ -220,45 +218,8 @@ protected void configurePropertiesFile(CommandLine line) throws ParseException {
}
}

public static String getEnginesDir() {
String enginesDir = System.getProperty(SystemConstants.SYSPROP_ENGINES_DIR, AppUtils.getSymHome() + "/engines");
new File(enginesDir).mkdirs();
return enginesDir;
}

public static File findPropertiesFileForEngineWithName(String engineName) {
File[] files = findEnginePropertiesFiles();
for (int i = 0; i < files.length; i++) {
File file = files[i];
Properties properties = new Properties();
try (FileInputStream is = new FileInputStream(file)) {
properties.load(is);
if (engineName.equals(properties.getProperty(ParameterConstants.ENGINE_NAME))) {
return file;
}
} catch (IOException ex) {
}
}
return null;
}

public static File[] findEnginePropertiesFiles() {
List<File> propFiles = new ArrayList<>();
File enginesDir = new File(getEnginesDir());
File[] files = enginesDir.listFiles();
if (files != null) {
for (int i = 0; i < files.length; i++) {
File file = files[i];
if (file.getName().endsWith(".properties")) {
propFiles.add(file);
}
}
}
return propFiles.toArray(new File[propFiles.size()]);
}

public File findSingleEnginesPropertiesFile() {
File[] files = findEnginePropertiesFiles();
File[] files = PropertiesUtil.findEnginePropertiesFiles();
if (files.length == 1) {
return files[0];
} else {
Expand Down Expand Up @@ -314,7 +275,8 @@ protected IDatabasePlatform getDatabasePlatform(boolean testConnection) {
if (testConnection) {
testConnection();
}
TypedProperties properties = new TypedProperties(propertiesFile);
ITypedPropertiesFactory factory = PropertiesUtil.createTypedPropertiesFactory(propertiesFile, null);
TypedProperties properties = factory.reload(propertiesFile);
if (properties.is(ParameterConstants.NODE_LOAD_ONLY, false)) {
TypedProperties copiedProperties = new TypedProperties();
String prefix = ParameterConstants.LOAD_ONLY_PROPERTY_PREFIX;
Expand All @@ -335,7 +297,8 @@ private void copyProperties(TypedProperties sourceProperties, TypedProperties ta
}

protected TypedProperties getTypedProperties() {
return new TypedProperties(propertiesFile);
ITypedPropertiesFactory factory = PropertiesUtil.createTypedPropertiesFactory(propertiesFile, null);
return factory.reload(propertiesFile);
}

protected void buildOptions(Options options) {
Expand Down
Expand Up @@ -74,9 +74,9 @@
import org.jumpmind.symmetric.statistic.IStatisticManager;
import org.jumpmind.symmetric.statistic.StatisticManager;
import org.jumpmind.symmetric.util.LogSummaryAppenderUtils;
import org.jumpmind.symmetric.util.PropertiesUtil;
import org.jumpmind.symmetric.util.SnapshotUtil;
import org.jumpmind.symmetric.util.SymmetricUtils;
import org.jumpmind.symmetric.util.TypedPropertiesFactory;
import org.jumpmind.util.AppUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand All @@ -93,7 +93,6 @@
public class ClientSymmetricEngine extends AbstractSymmetricEngine {
private static final Logger log = LoggerFactory.getLogger(ClientSymmetricEngine.class);
public static final String DEPLOYMENT_TYPE_CLIENT = "client";
public static final String PROPERTIES_FACTORY_CLASS_NAME = "properties.factory.class.name";
protected File propertiesFile;
protected Properties properties;
protected DataSource dataSource;
Expand Down Expand Up @@ -285,7 +284,7 @@ public synchronized void stop() {
}

public static BasicDataSource createBasicDataSource(File propsFile) {
TypedProperties properties = createTypedPropertiesFactory(propsFile, null).reload();
TypedProperties properties = PropertiesUtil.createTypedPropertiesFactory(propsFile, null).reload();
return BasicDataSourceFactory.create(properties, SecurityServiceFactory.create(SecurityServiceType.CLIENT, properties));
}

Expand Down Expand Up @@ -472,23 +471,7 @@ protected static void waitForAvailableDatabase(DataSource dataSource) {

@Override
protected ITypedPropertiesFactory createTypedPropertiesFactory() {
return createTypedPropertiesFactory(propertiesFile, properties);
}

protected static ITypedPropertiesFactory createTypedPropertiesFactory(File propFile, Properties prop) {
String propFactoryClassName = System.getProperties().getProperty(PROPERTIES_FACTORY_CLASS_NAME);
ITypedPropertiesFactory factory = null;
if (propFactoryClassName != null) {
try {
factory = (ITypedPropertiesFactory) Class.forName(propFactoryClassName).getDeclaredConstructor().newInstance();
} catch (Exception e) {
throw new RuntimeException(e);
}
} else {
factory = new TypedPropertiesFactory();
}
factory.init(propFile, prop);
return factory;
return PropertiesUtil.createTypedPropertiesFactory(propertiesFile, properties);
}

@Override
Expand Down
Expand Up @@ -70,6 +70,7 @@
import org.jumpmind.symmetric.service.IPurgeService;
import org.jumpmind.symmetric.service.IRegistrationService;
import org.jumpmind.symmetric.service.ITriggerRouterService;
import org.jumpmind.symmetric.util.PropertiesUtil;
import org.jumpmind.symmetric.util.ModuleException;
import org.jumpmind.symmetric.util.ModuleManager;
import org.jumpmind.util.AppUtils;
Expand Down Expand Up @@ -383,10 +384,10 @@ private String popArg(List<String> args, String argName) {
}

private void listEngines(CommandLine line, List<String> args) {
System.out.println("Engines directory is " + new File(getEnginesDir()).getAbsolutePath());
System.out.println("Engines directory is " + new File(PropertiesUtil.getEnginesDir()).getAbsolutePath());
System.out.println("The following engines and properties files are available:");
int count = 0;
File[] files = findEnginePropertiesFiles();
File[] files = PropertiesUtil.findEnginePropertiesFiles();
for (File file : files) {
Properties properties = new Properties();
try (FileInputStream is = new FileInputStream(file)) {
Expand Down Expand Up @@ -469,7 +470,7 @@ private void encryptText(CommandLine line, List<String> args) {
}

private ISecurityService createSecurityService() {
TypedProperties properties = ClientSymmetricEngine.createTypedPropertiesFactory(propertiesFile, new Properties()).reload();
TypedProperties properties = PropertiesUtil.createTypedPropertiesFactory(propertiesFile, new Properties()).reload();
return SecurityServiceFactory.create(SecurityServiceType.SERVER, properties);
}

Expand Down Expand Up @@ -522,7 +523,7 @@ private void backup(CommandLine line, List<String> args) throws IOException {
}
}
List<String> listOfDirs = new ArrayList<String>();
listOfDirs.add(AbstractCommandLauncher.getEnginesDir());
listOfDirs.add(PropertiesUtil.getEnginesDir());
listOfDirs.add(AppUtils.getSymHome() + "/conf");
listOfDirs.add(AppUtils.getSymHome() + "/patches");
listOfDirs.add(AppUtils.getSymHome() + "/security");
Expand Down
1 change: 1 addition & 0 deletions symmetric-core/build.gradle
Expand Up @@ -8,6 +8,7 @@ apply from: symAssembleDir + '/common.gradle'
compile "com.sun.mail:javax.mail:$javaMailVersion"
compile "com.google.code.gson:gson:$gsonVersion"
compile "org.springframework:spring-core:$springVersion"
compile "org.springframework:spring-beans:$springVersion"

compileOnly "org.eclipse.jetty:jetty-alpn-conscrypt-server:$jettyVersion"
// force okhttp3 to use newer version of kotlin
Expand Down
Expand Up @@ -21,6 +21,7 @@
package org.jumpmind.symmetric;

import java.io.File;
import java.io.IOException;
import java.util.Properties;

import org.jumpmind.properties.TypedProperties;
Expand All @@ -29,4 +30,10 @@ public interface ITypedPropertiesFactory {
public void init(File propertiesFile, Properties properties);

public TypedProperties reload();

public TypedProperties reload(File propFile);

public TypedProperties reload(Properties properties);

public void save(Properties props, File propFile, String comments) throws IOException;
}
Expand Up @@ -40,4 +40,5 @@ public class SystemConstants {
public static final String SYSPROP_REST_PROPERTIES_FILE = "sym.rest.properties.file";
public static final String SYSPROP_KEYSTORE_TYPE = SecurityConstants.SYSPROP_KEYSTORE_TYPE;
public static final String SYSPROP_KEYSTORE_CERT_ALIAS = SecurityConstants.SYSPROP_KEYSTORE_CERT_ALIAS;
public static final String SYSPROP_KEYSTORE_PARAMETERS = "symmetric.parameters.saved.in.keystore";
}
Expand Up @@ -483,9 +483,9 @@ protected String replaceTemplateVariables(DataEventType dml, Trigger trigger,
trigger).toString() : "null", ddl);
String oldddl = null;
for (oldddl = null; ddl != null && !ddl.equals(oldddl); ddl = this
.eval(columnString.isBlobClob && !trigger.isUseStreamLobs(), "containsBlobClobColumns", ddl)) {
oldddl = ddl;
}
.eval(columnString.isBlobClob && !trigger.isUseStreamLobs(), "containsBlobClobColumns", ddl)) {
oldddl = ddl;
}
oldddl = null;
// some column templates need tableName and schemaName
ddl = FormatUtils.replace("tableName", SymmetricUtils.quote(symmetricDialect, table.getName()), ddl);
Expand Down
Expand Up @@ -138,11 +138,12 @@ protected OutputStream getSqlDiffOutputStream(DbCompareTables tables) {
protected TableReport compareTables(DbCompareTables tables, OutputStream sqlDiffOutput) {
String sourceSelect = getSourceComparisonSQL(tables, sourceEngine.getTargetDialect().getTargetPlatform());
String targetSelect = getTargetComparisonSQL(tables, targetEngine.getTargetDialect().getTargetPlatform());
//String targetSelect = getTargetComparisonSQL(tables, targetEngine.getDatabasePlatform());

CountingSqlReadCursor sourceCursor = new CountingSqlReadCursor(sourceEngine.getTargetDialect().getTargetPlatform().getSqlTemplateDirty().queryForCursor(sourceSelect,
// String targetSelect = getTargetComparisonSQL(tables, targetEngine.getDatabasePlatform());
CountingSqlReadCursor sourceCursor = new CountingSqlReadCursor(sourceEngine.getTargetDialect().getTargetPlatform().getSqlTemplateDirty().queryForCursor(
sourceSelect,
defaultRowMapper));
CountingSqlReadCursor targetCursor = new CountingSqlReadCursor(targetEngine.getTargetDialect().getTargetPlatform().getSqlTemplateDirty().queryForCursor(targetSelect,
CountingSqlReadCursor targetCursor = new CountingSqlReadCursor(targetEngine.getTargetDialect().getTargetPlatform().getSqlTemplateDirty().queryForCursor(
targetSelect,
defaultRowMapper));
TableReport tableReport = new TableReport();
tableReport.setSourceTable(tables.getSourceTable().getName());
Expand Down Expand Up @@ -351,10 +352,12 @@ protected List<DbCompareTables> loadTables(List<String> tableNames, List<String>
if (tableNameParts.size() == 1) {
sourceTable = sourceEngine.getTargetDialect().getTargetPlatform().getTableFromCache(tableName, true);
} else {
sourceTable = sourceEngine.getTargetDialect().getTargetPlatform().getTableFromCache(tableNameParts.get("catalog"), tableNameParts.get("schema"), tableNameParts
.get("table"), true);
sourceTable = sourceEngine.getTargetDialect().getTargetPlatform().getTableFromCache(tableNameParts.get("catalog"), tableNameParts.get("schema"),
tableNameParts
.get("table"), true);
if (sourceTable == null) {
sourceTable = sourceEngine.getTargetDialect().getTargetPlatform().getTableFromCache(tableNameParts.get("schema"), tableNameParts.get("catalog"),
sourceTable = sourceEngine.getTargetDialect().getTargetPlatform().getTableFromCache(tableNameParts.get("schema"), tableNameParts.get(
"catalog"),
tableNameParts.get("table"), true);
}
}
Expand Down Expand Up @@ -460,10 +463,12 @@ protected Table loadTargetTable(DbCompareTables tables, String targetTableName)
if (tableNameParts.size() == 1) {
targetTable = targetEngine.getTargetDialect().getTargetPlatform().getTableFromCache(targetTableName, true);
} else {
targetTable = targetEngine.getTargetDialect().getTargetPlatform().getTableFromCache(tableNameParts.get("catalog"), tableNameParts.get("schema"), tableNameParts
.get("table"), true);
targetTable = targetEngine.getTargetDialect().getTargetPlatform().getTableFromCache(tableNameParts.get("catalog"), tableNameParts.get("schema"),
tableNameParts
.get("table"), true);
if (targetTable == null) {
targetTable = targetEngine.getTargetDialect().getTargetPlatform().getTableFromCache(tableNameParts.get("schema"), tableNameParts.get("catalog"),
targetTable = targetEngine.getTargetDialect().getTargetPlatform().getTableFromCache(tableNameParts.get("schema"), tableNameParts.get(
"catalog"),
tableNameParts.get("table"), true);
}
}
Expand Down Expand Up @@ -507,8 +512,9 @@ protected TransformTableNodeGroupLink getTransformFor(Table sourceTable) {
}

protected Table loadTargetTableUsingTransform(TransformTableNodeGroupLink transform) {
Table targetTable = targetEngine.getTargetDialect().getTargetPlatform().getTableFromCache(transform.getTargetCatalogName(), transform.getTargetSchemaName(), transform
.getTargetTableName(), true);
Table targetTable = targetEngine.getTargetDialect().getTargetPlatform().getTableFromCache(transform.getTargetCatalogName(), transform
.getTargetSchemaName(), transform
.getTargetTableName(), true);
return targetTable;
}

Expand Down

0 comments on commit 053cf73

Please sign in to comment.