Source:
public SimpleCertificateResponseMessageType importToTruststore(ImportToTruststoreRequestMessageType request) { if (StringUtils.isBlank(request.getAlias()) || CollectionUtils.isEmpty(request.getIntermediateList()) || null == request.getRootCert()) { return buildSimpleResponse(false, "Alias, Root and Intermediate are required."); } if(!copyFile(FILE_JKS_CACERTS, FILE_JKS_CACERTS_NEW)){ return buildSimpleResponse(false, "unable to create the temporary Truststore."); } try{ String alias = request.getAlias(); Certificate certRoot = CertificateUtil.createCertificate(request.getRootCert()); Map<String, Certificate> mapCerts = new HashMap<>(); int indexInt = 0; for (DataHandler cert : request.getIntermediateList()) { mapCerts.put(MessageFormat.format("{0}_intermediate_{1}", alias, indexInt++), CertificateUtil.createCertificate(cert)); } if (MapUtils.isEmpty(mapCerts) || null == certRoot) { return buildSimpleResponse(false, "Error creating certificate chain for truststore."); } tempTruststore = null; Certificate certAlias = CertificateManagerImpl.getInstance().getCertificateBy(alias); List<ListCertificateType> certChain = buildChain(certAlias, getTempTruststore()); for(ListCertificateType item: certChain){ getTempTruststore().deleteEntry(item.getAlias()); } getTempTruststore().setCertificateEntry(MessageFormat.format("{0}_root",alias), certRoot); for (Entry<String, Certificate> entryCert : mapCerts.entrySet()) { getTempTruststore().setCertificateEntry(entryCert.getKey(), entryCert.getValue()); } CoreHelpUtils.saveJksTo(getTempTruststore(), System.getProperty(CertificateManagerImpl.TRUST_STORE_PASSWORD_KEY), FILE_JKS_CACERTS_NEW); }catch(CertificateManagerException | KeyStoreException | UtilException | CertificateEncodingException e){ LOG.error("error while importing to the temporary truststore: {}",e.getLocalizedMessage(), e); return buildSimpleResponse(false, "error while importing to the temporary truststore."); } return buildSimpleResponse(true, "import temporary truststore successful."); }

Target:
public SimpleCertificateResponseMessageType importToTruststore(ImportToTruststoreRequestMessageType request) { if (StringUtils.isBlank(request.getAlias()) || CollectionUtils.isEmpty(request.getIntermediateList()) || null == request.getRootCert()) { return buildSimpleResponse(false, "Alias, CA Root and CA Intermediate are required."); } if(!copyFile(FILE_JKS_CACERTS, FILE_JKS_CACERTS_NEW)){ return buildSimpleResponse(false, "unable to create the temporary Truststore."); } try{ String alias = request.getAlias(); Certificate certRoot = CertificateUtil.createCertificate(request.getRootCert()); Map<String, Certificate> mapCerts = new HashMap<>(); int indexInt = 0; for (DataHandler cert : request.getIntermediateList()) { mapCerts.put(MessageFormat.format("{0}_intermediate_{1}", alias, indexInt++), CertificateUtil.createCertificate(cert)); } if (MapUtils.isEmpty(mapCerts) || null == certRoot) { return buildSimpleResponse(false, "Error creating certificate chain for truststore."); } tempTruststore = null; Certificate certAlias = CertificateManagerImpl.getInstance().getCertificateBy(alias); List<ListCertificateType> certChain = buildChain(certAlias, getTempTruststore()); for(ListCertificateType item: certChain){ getTempTruststore().deleteEntry(item.getAlias()); } getTempTruststore().setCertificateEntry(MessageFormat.format("{0}_root",alias), certRoot); for (Entry<String, Certificate> entryCert : mapCerts.entrySet()) { getTempTruststore().setCertificateEntry(entryCert.getKey(), entryCert.getValue()); } CoreHelpUtils.saveJksTo(getTempTruststore(), System.getProperty(CertificateManagerImpl.TRUST_STORE_PASSWORD_KEY), FILE_JKS_CACERTS_NEW); }catch(CertificateManagerException | KeyStoreException | UtilException | CertificateEncodingException e){ LOG.error("error while importing to the temporary truststore: {}",e.getLocalizedMessage(), e); return buildSimpleResponse(false, "error while importing to the temporary truststore."); } return buildSimpleResponse(true, "Import is successful into the temporary truststore."); }