aboutsummaryrefslogtreecommitdiffstats
path: root/trustStoreMerger/src/main
diff options
context:
space:
mode:
authorJan Malkiewicz <jan.malkiewicz@nokia.com>2020-09-10 08:58:30 +0200
committerJan Malkiewicz <jan.malkiewicz@nokia.com>2020-09-10 15:02:26 +0200
commit4ad0fafc796a7b65b9d653863d0f57a62eca5fa9 (patch)
tree8de50b3c73a9454dcdfa94070c12870ae1c134d6 /trustStoreMerger/src/main
parentc22f36d5847b75e436a0acbe370a9e1c96008b1d (diff)
[OOM-CMPv2] Create KeystoreCopier
- implement logic to copy keystores - moved logic of truststore merger to decicated class TruststoreMerger Issue-ID: DCAEGEN2-2253 Signed-off-by: Jan Malkiewicz <jan.malkiewicz@nokia.com> Change-Id: I730d10b9bb72da55d9e4641b79cf98e0e100a39d
Diffstat (limited to 'trustStoreMerger/src/main')
-rw-r--r--trustStoreMerger/src/main/java/org/onap/oom/truststoremerger/AppExitHandler.java2
-rw-r--r--trustStoreMerger/src/main/java/org/onap/oom/truststoremerger/CertificatePostProcessor.java66
-rw-r--r--trustStoreMerger/src/main/java/org/onap/oom/truststoremerger/api/ExitStatus.java2
-rw-r--r--trustStoreMerger/src/main/java/org/onap/oom/truststoremerger/common/FileTools.java (renamed from trustStoreMerger/src/main/java/org/onap/oom/truststoremerger/common/BackupCreator.java)32
-rw-r--r--trustStoreMerger/src/main/java/org/onap/oom/truststoremerger/configuration/AppConfigurationLoader.java42
-rw-r--r--trustStoreMerger/src/main/java/org/onap/oom/truststoremerger/configuration/AppConfigurationProvider.java (renamed from trustStoreMerger/src/main/java/org/onap/oom/truststoremerger/configuration/MergerConfigurationProvider.java)10
-rw-r--r--trustStoreMerger/src/main/java/org/onap/oom/truststoremerger/configuration/model/AppConfiguration.java (renamed from trustStoreMerger/src/main/java/org/onap/oom/truststoremerger/configuration/model/MergerConfiguration.java)4
-rw-r--r--trustStoreMerger/src/main/java/org/onap/oom/truststoremerger/copier/KeystoreCopier.java65
-rw-r--r--trustStoreMerger/src/main/java/org/onap/oom/truststoremerger/copier/exception/KeystoreFileCopyException.java31
-rw-r--r--trustStoreMerger/src/main/java/org/onap/oom/truststoremerger/copier/exception/KeystoreNotExistException.java31
-rw-r--r--trustStoreMerger/src/main/java/org/onap/oom/truststoremerger/merger/TruststoreMerger.java55
-rw-r--r--trustStoreMerger/src/main/java/org/onap/oom/truststoremerger/merger/model/JavaTruststore.java3
-rw-r--r--trustStoreMerger/src/main/java/org/onap/oom/truststoremerger/merger/model/PemTruststore.java3
-rw-r--r--trustStoreMerger/src/main/java/org/onap/oom/truststoremerger/merger/model/Truststore.java9
14 files changed, 282 insertions, 73 deletions
diff --git a/trustStoreMerger/src/main/java/org/onap/oom/truststoremerger/AppExitHandler.java b/trustStoreMerger/src/main/java/org/onap/oom/truststoremerger/AppExitHandler.java
index c257756a..e4c26b14 100644
--- a/trustStoreMerger/src/main/java/org/onap/oom/truststoremerger/AppExitHandler.java
+++ b/trustStoreMerger/src/main/java/org/onap/oom/truststoremerger/AppExitHandler.java
@@ -27,7 +27,7 @@ public class AppExitHandler {
private static final Logger LOGGER = LoggerFactory.getLogger(AppExitHandler.class);
public void exit(ExitStatus exitStatus) {
- LOGGER.info("Application exits with following exit code: {} and message: {}",
+ LOGGER.info("Application exits with code [{}] and message: {}",
exitStatus.getExitCodeValue(), exitStatus.getMessage());
System.exit(exitStatus.getExitCodeValue());
}
diff --git a/trustStoreMerger/src/main/java/org/onap/oom/truststoremerger/CertificatePostProcessor.java b/trustStoreMerger/src/main/java/org/onap/oom/truststoremerger/CertificatePostProcessor.java
index 7eab6401..0045b2f0 100644
--- a/trustStoreMerger/src/main/java/org/onap/oom/truststoremerger/CertificatePostProcessor.java
+++ b/trustStoreMerger/src/main/java/org/onap/oom/truststoremerger/CertificatePostProcessor.java
@@ -19,58 +19,30 @@
package org.onap.oom.truststoremerger;
-import java.util.List;
import org.onap.oom.truststoremerger.api.ExitableException;
-import org.onap.oom.truststoremerger.configuration.MergerConfigurationProvider;
-import org.onap.oom.truststoremerger.configuration.model.MergerConfiguration;
-import org.onap.oom.truststoremerger.configuration.path.DelimitedPathsReader;
-import org.onap.oom.truststoremerger.configuration.path.DelimitedPathsReaderFactory;
-import org.onap.oom.truststoremerger.configuration.path.env.EnvProvider;
-import org.onap.oom.truststoremerger.merger.TruststoreFilesProvider;
-import org.onap.oom.truststoremerger.merger.model.Truststore;
-import org.onap.oom.truststoremerger.merger.model.certificate.CertificateWithAlias;
+import org.onap.oom.truststoremerger.common.FileTools;
+import org.onap.oom.truststoremerger.configuration.AppConfigurationLoader;
+import org.onap.oom.truststoremerger.configuration.model.AppConfiguration;
+import org.onap.oom.truststoremerger.copier.KeystoreCopier;
+import org.onap.oom.truststoremerger.merger.TruststoreMerger;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
class CertificatePostProcessor implements Runnable {
- private static final int FIRST_TRUSTSTORE_INDEX = 0;
- private static final int SECOND_TRUSTSTORE_INDEX = 1;
+ private static final Logger LOGGER = LoggerFactory.getLogger(CertificatePostProcessor.class);
- public void run() throws ExitableException {
- mergeTruststores();
- }
-
- private void mergeTruststores() throws ExitableException {
- MergerConfiguration configuration = loadConfiguration();
- List<Truststore> truststoreFilesList = getTruststoreFiles(configuration);
-
- Truststore baseFile = truststoreFilesList.get(FIRST_TRUSTSTORE_INDEX);
- baseFile.createBackup();
-
- for (int i = SECOND_TRUSTSTORE_INDEX; i < truststoreFilesList.size(); i++) {
- Truststore truststore = truststoreFilesList.get(i);
- List<CertificateWithAlias> certificateWrappers = truststore.getCertificates();
- baseFile.addCertificates(certificateWrappers);
- }
+ private AppConfigurationLoader config = new AppConfigurationLoader();
+ private TruststoreMerger merger = new TruststoreMerger();
+ private KeystoreCopier copier = new KeystoreCopier(new FileTools());
- baseFile.saveFile();
- }
-
- private MergerConfiguration loadConfiguration() throws ExitableException {
- DelimitedPathsReaderFactory readerFactory = new DelimitedPathsReaderFactory(new EnvProvider());
- DelimitedPathsReader certificatesPathsReader = readerFactory.createCertificatePathsReader();
- DelimitedPathsReader passwordsPathsReader = readerFactory.createPasswordPathsReader();
- DelimitedPathsReader copierPathsReader = readerFactory.createKeystoreCopierPathsReader();
- MergerConfigurationProvider factory = new MergerConfigurationProvider(certificatesPathsReader,
- passwordsPathsReader,
- copierPathsReader);
- return factory.createConfiguration();
- }
-
- private static List<Truststore> getTruststoreFiles(MergerConfiguration configuration) throws ExitableException {
- return TruststoreFilesProvider
- .getTruststoreFiles(
- configuration.getTruststoreFilePaths(),
- configuration.getTruststoreFilePasswordPaths()
- );
+ public void run() throws ExitableException {
+ LOGGER.debug("Loading configuration...");
+ AppConfiguration configuration = config.loadConfiguration();
+ LOGGER.debug("Starting TruststoreMerger...");
+ merger.mergeTruststores(configuration);
+ LOGGER.debug("Starting KeystoreCopier...");
+ copier.copyKeystores(configuration);
+ LOGGER.debug("Certificate post processing finished successfully.");
}
}
diff --git a/trustStoreMerger/src/main/java/org/onap/oom/truststoremerger/api/ExitStatus.java b/trustStoreMerger/src/main/java/org/onap/oom/truststoremerger/api/ExitStatus.java
index d3e246ae..01f440cc 100644
--- a/trustStoreMerger/src/main/java/org/onap/oom/truststoremerger/api/ExitStatus.java
+++ b/trustStoreMerger/src/main/java/org/onap/oom/truststoremerger/api/ExitStatus.java
@@ -33,6 +33,8 @@ public enum ExitStatus {
MISSING_TRUSTSTORE_EXCEPTION(9, "Missing truststore certificates in provided file"),
ALIAS_CONFLICT_EXCEPTION(10, "Alias conflict detected"),
WRITE_TRUSTSTORE_FILE_EXCEPTION(11, "Cannot save truststore file"),
+ KEYSTORE_FILE_COPY_EXCEPTION(12, "Cannot copy keystore file"),
+ KEYSTORE_NOT_EXIST_EXCEPTION(13, "Keystore file does not exist"),
UNEXPECTED_EXCEPTION(99, "Application exited abnormally");
diff --git a/trustStoreMerger/src/main/java/org/onap/oom/truststoremerger/common/BackupCreator.java b/trustStoreMerger/src/main/java/org/onap/oom/truststoremerger/common/FileTools.java
index 9187393e..87b0e83d 100644
--- a/trustStoreMerger/src/main/java/org/onap/oom/truststoremerger/common/BackupCreator.java
+++ b/trustStoreMerger/src/main/java/org/onap/oom/truststoremerger/common/FileTools.java
@@ -21,28 +21,34 @@ package org.onap.oom.truststoremerger.common;
import java.io.File;
import java.io.FileOutputStream;
+import java.io.IOException;
import java.nio.file.Files;
+import org.apache.commons.io.FileUtils;
import org.onap.oom.truststoremerger.merger.exception.CreateBackupException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-public final class BackupCreator {
+public final class FileTools {
- private static final Logger LOGGER = LoggerFactory.getLogger(BackupCreator.class);
+ private static final Logger LOGGER = LoggerFactory.getLogger(FileTools.class);
private static final String BACKUP_EXTENSION = ".bak";
- private BackupCreator() {
- }
-
- public static void createBackup(File file) throws CreateBackupException {
- LOGGER.debug("Create backup of file: {}", file.getPath());
- String backupFilePath = file.getAbsolutePath() + BACKUP_EXTENSION;
- try (FileOutputStream fileOutputStream = new FileOutputStream(backupFilePath)) {
- Files.copy(file.toPath(), fileOutputStream);
- } catch (Exception e) {
- LOGGER.error("Cannot create backup of file: {} ", file.getPath());
+ public void createBackup(File file) throws CreateBackupException {
+ LOGGER.debug("Try to create a backup of the file: {}", file.getPath());
+ File backupFile = new File(file.getAbsolutePath() + BACKUP_EXTENSION);
+ try {
+ copy(file, backupFile);
+ } catch (IOException e) {
+ LOGGER.error("Could not create backup of the file: '{}'", file.getPath());
throw new CreateBackupException(e);
}
- LOGGER.debug("Backup was successfully created in: {}", backupFilePath);
+ LOGGER.debug("Backup file created: '{}'", backupFile.getAbsolutePath());
+ }
+
+ public void copy(File source, File destination) throws IOException {
+ LOGGER.debug("Try to copy from '{}' to '{}'.", source.getAbsolutePath(), destination.getAbsolutePath());
+ FileUtils.copyFile(source, destination);
+ LOGGER.debug("File copied from '{}' to '{}'.", source.getAbsolutePath(),
+ destination.getAbsolutePath());
}
}
diff --git a/trustStoreMerger/src/main/java/org/onap/oom/truststoremerger/configuration/AppConfigurationLoader.java b/trustStoreMerger/src/main/java/org/onap/oom/truststoremerger/configuration/AppConfigurationLoader.java
new file mode 100644
index 00000000..7660ff7b
--- /dev/null
+++ b/trustStoreMerger/src/main/java/org/onap/oom/truststoremerger/configuration/AppConfigurationLoader.java
@@ -0,0 +1,42 @@
+/*============LICENSE_START=======================================================
+ * oom-truststore-merger
+ * ================================================================================
+ * Copyright (C) 2020 Nokia. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.oom.truststoremerger.configuration;
+
+import org.onap.oom.truststoremerger.api.ExitableException;
+import org.onap.oom.truststoremerger.configuration.model.AppConfiguration;
+import org.onap.oom.truststoremerger.configuration.path.DelimitedPathsReader;
+import org.onap.oom.truststoremerger.configuration.path.DelimitedPathsReaderFactory;
+import org.onap.oom.truststoremerger.configuration.path.env.EnvProvider;
+
+public class AppConfigurationLoader {
+
+ public AppConfiguration loadConfiguration() throws ExitableException {
+ DelimitedPathsReaderFactory readerFactory = new DelimitedPathsReaderFactory(new EnvProvider());
+ DelimitedPathsReader certificatesPathsReader = readerFactory.createCertificatePathsReader();
+ DelimitedPathsReader passwordsPathsReader = readerFactory.createPasswordPathsReader();
+ DelimitedPathsReader copierPathsReader = readerFactory.createKeystoreCopierPathsReader();
+ AppConfigurationProvider factory = new AppConfigurationProvider(certificatesPathsReader,
+ passwordsPathsReader,
+ copierPathsReader);
+ return factory.createConfiguration();
+ }
+
+
+}
diff --git a/trustStoreMerger/src/main/java/org/onap/oom/truststoremerger/configuration/MergerConfigurationProvider.java b/trustStoreMerger/src/main/java/org/onap/oom/truststoremerger/configuration/AppConfigurationProvider.java
index 5cbf8b20..e1bdbfa3 100644
--- a/trustStoreMerger/src/main/java/org/onap/oom/truststoremerger/configuration/MergerConfigurationProvider.java
+++ b/trustStoreMerger/src/main/java/org/onap/oom/truststoremerger/configuration/AppConfigurationProvider.java
@@ -27,23 +27,23 @@ import static org.onap.oom.truststoremerger.configuration.ConfigurationEnvs.TRUS
import java.util.List;
import org.onap.oom.truststoremerger.configuration.exception.MergerConfigurationException;
import org.onap.oom.truststoremerger.configuration.exception.TruststoresPathsProviderException;
-import org.onap.oom.truststoremerger.configuration.model.MergerConfiguration;
+import org.onap.oom.truststoremerger.configuration.model.AppConfiguration;
import org.onap.oom.truststoremerger.configuration.path.DelimitedPathsReader;
-public class MergerConfigurationProvider {
+public class AppConfigurationProvider {
private final DelimitedPathsReader truststoresPathsReader;
private final DelimitedPathsReader truststoresPasswordsPathsReader;
private final DelimitedPathsReader copierPathsReader;
- public MergerConfigurationProvider(DelimitedPathsReader truststoresPathsReader,
+ public AppConfigurationProvider(DelimitedPathsReader truststoresPathsReader,
DelimitedPathsReader truststoresPasswordsPathsReader, DelimitedPathsReader copierPathsReader) {
this.truststoresPathsReader = truststoresPathsReader;
this.truststoresPasswordsPathsReader = truststoresPasswordsPathsReader;
this.copierPathsReader = copierPathsReader;
}
- public MergerConfiguration createConfiguration()
+ public AppConfiguration createConfiguration()
throws MergerConfigurationException, TruststoresPathsProviderException {
List<String> truststoresPaths = truststoresPathsReader.get(TRUSTSTORES_PATHS_ENV);
List<String> truststoresPasswordsPaths = truststoresPasswordsPathsReader.get(TRUSTSTORES_PASSWORDS_PATHS_ENV);
@@ -55,7 +55,7 @@ public class MergerConfigurationProvider {
ensureSameSize(sourceKeystorePaths, destinationKeystorePaths, KEYSTORE_SOURCE_PATHS_ENV,
KEYSTORE_DESTINATION_PATHS_ENV);
- return new MergerConfiguration(truststoresPaths, truststoresPasswordsPaths, sourceKeystorePaths,
+ return new AppConfiguration(truststoresPaths, truststoresPasswordsPaths, sourceKeystorePaths,
destinationKeystorePaths);
}
diff --git a/trustStoreMerger/src/main/java/org/onap/oom/truststoremerger/configuration/model/MergerConfiguration.java b/trustStoreMerger/src/main/java/org/onap/oom/truststoremerger/configuration/model/AppConfiguration.java
index 0809ab5a..9da7c6a7 100644
--- a/trustStoreMerger/src/main/java/org/onap/oom/truststoremerger/configuration/model/MergerConfiguration.java
+++ b/trustStoreMerger/src/main/java/org/onap/oom/truststoremerger/configuration/model/AppConfiguration.java
@@ -22,13 +22,13 @@ package org.onap.oom.truststoremerger.configuration.model;
import java.util.Collections;
import java.util.List;
-public final class MergerConfiguration {
+public final class AppConfiguration {
private final List<String> truststoreFilePaths;
private final List<String> truststoreFilePasswordPaths;
private final List<String> sourceKeystorePaths;
private final List<String> destinationKeystorePaths;
- public MergerConfiguration(List<String> truststoreFilePaths,
+ public AppConfiguration(List<String> truststoreFilePaths,
List<String> truststoreFilePasswordPaths, List<String> sourceKeystorePaths,
List<String> destinationKeystorePaths) {
this.truststoreFilePaths = List.copyOf(truststoreFilePaths);
diff --git a/trustStoreMerger/src/main/java/org/onap/oom/truststoremerger/copier/KeystoreCopier.java b/trustStoreMerger/src/main/java/org/onap/oom/truststoremerger/copier/KeystoreCopier.java
new file mode 100644
index 00000000..822979c1
--- /dev/null
+++ b/trustStoreMerger/src/main/java/org/onap/oom/truststoremerger/copier/KeystoreCopier.java
@@ -0,0 +1,65 @@
+/*============LICENSE_START=======================================================
+ * oom-truststore-merger
+ * ================================================================================
+ * Copyright (C) 2020 Nokia. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.oom.truststoremerger.copier;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.List;
+import org.onap.oom.truststoremerger.common.FileTools;
+import org.onap.oom.truststoremerger.configuration.model.AppConfiguration;
+import org.onap.oom.truststoremerger.copier.exception.KeystoreFileCopyException;
+import org.onap.oom.truststoremerger.copier.exception.KeystoreNotExistException;
+
+public class KeystoreCopier {
+
+ final private FileTools fileTools;
+
+ public KeystoreCopier(FileTools fileTools) {
+ this.fileTools = fileTools;
+ }
+
+ public void copyKeystores(AppConfiguration configuration) {
+ try {
+ final List<String> sources = configuration.getSourceKeystorePaths();
+ final List<String> destinations = configuration.getDestinationKeystorePaths();
+
+ for (int i = 0; i < sources.size(); i++) {
+ copy(sources.get(i), destinations.get(i));
+ }
+ } catch (IOException e) {
+ throw new KeystoreFileCopyException(e);
+ }
+ }
+
+ private void copy(String sourcePath, String destinationPath) throws IOException {
+ final File source = new File(sourcePath);
+ final File destination = new File(destinationPath);
+
+ if (!source.exists()) {
+ throw new KeystoreNotExistException("Keystore file does not exist '" + source.getAbsolutePath() + "'!");
+ }
+
+ if (destination.exists()) {
+ fileTools.createBackup(destination);
+ }
+ fileTools.copy(source, destination);
+ }
+
+}
diff --git a/trustStoreMerger/src/main/java/org/onap/oom/truststoremerger/copier/exception/KeystoreFileCopyException.java b/trustStoreMerger/src/main/java/org/onap/oom/truststoremerger/copier/exception/KeystoreFileCopyException.java
new file mode 100644
index 00000000..80d3c67d
--- /dev/null
+++ b/trustStoreMerger/src/main/java/org/onap/oom/truststoremerger/copier/exception/KeystoreFileCopyException.java
@@ -0,0 +1,31 @@
+/*============LICENSE_START=======================================================
+ * oom-truststore-merger
+ * ================================================================================
+ * Copyright (C) 2020 Nokia. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.oom.truststoremerger.copier.exception;
+
+import org.onap.oom.truststoremerger.api.ExitStatus;
+import org.onap.oom.truststoremerger.api.ExitableException;
+
+public class KeystoreFileCopyException extends ExitableException {
+
+ public KeystoreFileCopyException(Exception e) {
+ super(e, ExitStatus.KEYSTORE_FILE_COPY_EXCEPTION);
+ }
+
+}
diff --git a/trustStoreMerger/src/main/java/org/onap/oom/truststoremerger/copier/exception/KeystoreNotExistException.java b/trustStoreMerger/src/main/java/org/onap/oom/truststoremerger/copier/exception/KeystoreNotExistException.java
new file mode 100644
index 00000000..ef2d7761
--- /dev/null
+++ b/trustStoreMerger/src/main/java/org/onap/oom/truststoremerger/copier/exception/KeystoreNotExistException.java
@@ -0,0 +1,31 @@
+/*============LICENSE_START=======================================================
+ * oom-truststore-merger
+ * ================================================================================
+ * Copyright (C) 2020 Nokia. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.oom.truststoremerger.copier.exception;
+
+import org.onap.oom.truststoremerger.api.ExitStatus;
+import org.onap.oom.truststoremerger.api.ExitableException;
+
+public class KeystoreNotExistException extends ExitableException {
+
+ public KeystoreNotExistException(String message) {
+ super(message, ExitStatus.KEYSTORE_NOT_EXIST_EXCEPTION);
+ }
+
+}
diff --git a/trustStoreMerger/src/main/java/org/onap/oom/truststoremerger/merger/TruststoreMerger.java b/trustStoreMerger/src/main/java/org/onap/oom/truststoremerger/merger/TruststoreMerger.java
new file mode 100644
index 00000000..ad8cff9d
--- /dev/null
+++ b/trustStoreMerger/src/main/java/org/onap/oom/truststoremerger/merger/TruststoreMerger.java
@@ -0,0 +1,55 @@
+/*============LICENSE_START=======================================================
+ * oom-truststore-merger
+ * ================================================================================
+ * Copyright (C) 2020 Nokia. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.oom.truststoremerger.merger;
+
+import java.util.List;
+import org.onap.oom.truststoremerger.api.ExitableException;
+import org.onap.oom.truststoremerger.configuration.model.AppConfiguration;
+import org.onap.oom.truststoremerger.merger.model.Truststore;
+import org.onap.oom.truststoremerger.merger.model.certificate.CertificateWithAlias;
+
+public class TruststoreMerger {
+
+ private static final int FIRST_TRUSTSTORE_INDEX = 0;
+ private static final int SECOND_TRUSTSTORE_INDEX = 1;
+
+ public void mergeTruststores(AppConfiguration configuration) throws ExitableException {
+ List<Truststore> truststoreFilesList = getTruststoreFiles(configuration);
+
+ Truststore baseFile = truststoreFilesList.get(FIRST_TRUSTSTORE_INDEX);
+ baseFile.createBackup();
+
+ for (int i = SECOND_TRUSTSTORE_INDEX; i < truststoreFilesList.size(); i++) {
+ Truststore truststore = truststoreFilesList.get(i);
+ List<CertificateWithAlias> certificateWrappers = truststore.getCertificates();
+ baseFile.addCertificates(certificateWrappers);
+ }
+
+ baseFile.saveFile();
+ }
+
+ private List<Truststore> getTruststoreFiles(AppConfiguration configuration) throws ExitableException {
+ return TruststoreFilesProvider
+ .getTruststoreFiles(
+ configuration.getTruststoreFilePaths(),
+ configuration.getTruststoreFilePasswordPaths()
+ );
+ }
+}
diff --git a/trustStoreMerger/src/main/java/org/onap/oom/truststoremerger/merger/model/JavaTruststore.java b/trustStoreMerger/src/main/java/org/onap/oom/truststoremerger/merger/model/JavaTruststore.java
index e3a03996..6aa8b569 100644
--- a/trustStoreMerger/src/main/java/org/onap/oom/truststoremerger/merger/model/JavaTruststore.java
+++ b/trustStoreMerger/src/main/java/org/onap/oom/truststoremerger/merger/model/JavaTruststore.java
@@ -28,6 +28,7 @@ import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import org.onap.oom.truststoremerger.api.ExitableException;
+import org.onap.oom.truststoremerger.common.FileTools;
import org.onap.oom.truststoremerger.merger.exception.AliasConflictException;
import org.onap.oom.truststoremerger.merger.exception.LoadTruststoreException;
import org.onap.oom.truststoremerger.merger.exception.MissingTruststoreException;
@@ -48,7 +49,7 @@ public final class JavaTruststore extends Truststore {
private JavaTruststore(KeyStore keyStore, File storeFile, String password) {
- super(storeFile);
+ super(storeFile, new FileTools());
this.keyStore = keyStore;
this.password = password;
}
diff --git a/trustStoreMerger/src/main/java/org/onap/oom/truststoremerger/merger/model/PemTruststore.java b/trustStoreMerger/src/main/java/org/onap/oom/truststoremerger/merger/model/PemTruststore.java
index d04a01b1..4617142a 100644
--- a/trustStoreMerger/src/main/java/org/onap/oom/truststoremerger/merger/model/PemTruststore.java
+++ b/trustStoreMerger/src/main/java/org/onap/oom/truststoremerger/merger/model/PemTruststore.java
@@ -37,6 +37,7 @@ import org.bouncycastle.jce.provider.BouncyCastleProvider;
import org.bouncycastle.openssl.jcajce.JcaMiscPEMGenerator;
import org.bouncycastle.util.io.pem.PemObjectGenerator;
import org.bouncycastle.util.io.pem.PemWriter;
+import org.onap.oom.truststoremerger.common.FileTools;
import org.onap.oom.truststoremerger.merger.exception.MissingTruststoreException;
import org.onap.oom.truststoremerger.merger.exception.TruststoreDataOperationException;
import org.onap.oom.truststoremerger.merger.exception.WriteTruststoreFileException;
@@ -55,7 +56,7 @@ public class PemTruststore extends Truststore {
private final List<CertificateWithAlias> certificatesToBeSaved = new ArrayList<>();
public PemTruststore(File storeFile) {
- super(storeFile);
+ super(storeFile, new FileTools());
}
public List<CertificateWithAlias> getCertificates()
diff --git a/trustStoreMerger/src/main/java/org/onap/oom/truststoremerger/merger/model/Truststore.java b/trustStoreMerger/src/main/java/org/onap/oom/truststoremerger/merger/model/Truststore.java
index 2c3acf49..84239875 100644
--- a/trustStoreMerger/src/main/java/org/onap/oom/truststoremerger/merger/model/Truststore.java
+++ b/trustStoreMerger/src/main/java/org/onap/oom/truststoremerger/merger/model/Truststore.java
@@ -22,20 +22,23 @@ package org.onap.oom.truststoremerger.merger.model;
import java.io.File;
import java.util.List;
import org.onap.oom.truststoremerger.api.ExitableException;
+import org.onap.oom.truststoremerger.common.FileTools;
import org.onap.oom.truststoremerger.merger.exception.CreateBackupException;
import org.onap.oom.truststoremerger.merger.model.certificate.CertificateWithAlias;
-import org.onap.oom.truststoremerger.common.BackupCreator;
public abstract class Truststore {
final File storeFile;
- public Truststore(File storeFile) {
+ private final FileTools fileTools;
+
+ public Truststore(File storeFile, FileTools fileTools) {
this.storeFile = storeFile;
+ this.fileTools = fileTools;
}
public void createBackup() throws CreateBackupException {
- BackupCreator.createBackup(storeFile);
+ fileTools.createBackup(storeFile);
}
public abstract List<CertificateWithAlias> getCertificates() throws ExitableException;