1 /*============LICENSE_START=======================================================
2 * oom-truststore-merger
3 * ================================================================================
4 * Copyright (C) 2020 Nokia. All rights reserved.
5 * ================================================================================
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 * ============LICENSE_END=========================================================
20 package org.onap.oom.truststoremerger;
22 import java.util.List;
23 import org.onap.oom.truststoremerger.api.ExitableException;
24 import org.onap.oom.truststoremerger.configuration.MergerConfigurationProvider;
25 import org.onap.oom.truststoremerger.configuration.model.MergerConfiguration;
26 import org.onap.oom.truststoremerger.configuration.path.DelimitedPathsReader;
27 import org.onap.oom.truststoremerger.configuration.path.DelimitedPathsReaderFactory;
28 import org.onap.oom.truststoremerger.configuration.path.env.EnvProvider;
29 import org.onap.oom.truststoremerger.merger.TruststoreFilesProvider;
30 import org.onap.oom.truststoremerger.merger.model.Truststore;
31 import org.onap.oom.truststoremerger.merger.model.certificate.CertificateWithAlias;
33 class CertificatePostProcessor implements Runnable {
35 private static final int FIRST_TRUSTSTORE_INDEX = 0;
36 private static final int SECOND_TRUSTSTORE_INDEX = 1;
38 public void run() throws ExitableException {
42 private void mergeTruststores() throws ExitableException {
43 MergerConfiguration configuration = loadConfiguration();
44 List<Truststore> truststoreFilesList = getTruststoreFiles(configuration);
46 Truststore baseFile = truststoreFilesList.get(FIRST_TRUSTSTORE_INDEX);
47 baseFile.createBackup();
49 for (int i = SECOND_TRUSTSTORE_INDEX; i < truststoreFilesList.size(); i++) {
50 Truststore truststore = truststoreFilesList.get(i);
51 List<CertificateWithAlias> certificateWrappers = truststore.getCertificates();
52 baseFile.addCertificates(certificateWrappers);
58 private MergerConfiguration loadConfiguration() throws ExitableException {
59 DelimitedPathsReaderFactory readerFactory = new DelimitedPathsReaderFactory(new EnvProvider());
60 DelimitedPathsReader certificatesPathsReader = readerFactory.createCertificatePathsReader();
61 DelimitedPathsReader passwordsPathsReader = readerFactory.createPasswordPathsReader();
62 DelimitedPathsReader copierPathsReader = readerFactory.createKeystoreCopierPathsReader();
63 MergerConfigurationProvider factory = new MergerConfigurationProvider(certificatesPathsReader,
66 return factory.createConfiguration();
69 private static List<Truststore> getTruststoreFiles(MergerConfiguration configuration) throws ExitableException {
70 return TruststoreFilesProvider
72 configuration.getTruststoreFilePaths(),
73 configuration.getTruststoreFilePasswordPaths()