-// private void initI18n() {
-// Object defaultLocaleValue = KernelUtils.getFrameworkProp(CmsConstants.I18N_DEFAULT_LOCALE);
-// defaultLocale = defaultLocaleValue != null ? new Locale(defaultLocaleValue.toString())
-// : new Locale(ENGLISH.getLanguage());
-// locales = LocaleUtils.asLocaleList(KernelUtils.getFrameworkProp(CmsConstants.I18N_LOCALES));
-// }
-
- private void initServices() {
- // JTA
-// String tmType = KernelUtils.getFrameworkProp(CmsConstants.TRANSACTION_MANAGER,
-// CmsConstants.TRANSACTION_MANAGER_SIMPLE);
-// if (CmsConstants.TRANSACTION_MANAGER_SIMPLE.equals(tmType)) {
-// initSimpleTransactionManager();
-// } else if (CmsConstants.TRANSACTION_MANAGER_BITRONIX.equals(tmType)) {
-//// initBitronixTransactionManager();
-// throw new UnsupportedOperationException(
-// "Bitronix is not supported anymore, but could be again if there is enough interest.");
-// } else {
-// throw new IllegalArgumentException("Usupported transaction manager type " + tmType);
-// }
-
- // POI
-// POIXMLTypeLoader.setClassLoader(CTConnection.class.getClassLoader());
-
- // Tika
-// OpenDocumentParser odfParser = new OpenDocumentParser();
-// bc.registerService(Parser.class, odfParser, new Hashtable());
-// PDFParser pdfParser = new PDFParser();
-// bc.registerService(Parser.class, pdfParser, new Hashtable());
-// OOXMLParser ooxmlParser = new OOXMLParser();
-// bc.registerService(Parser.class, ooxmlParser, new Hashtable());
-// TesseractOCRParser ocrParser = new TesseractOCRParser();
-// ocrParser.setLanguage("ara");
-// bc.registerService(Parser.class, ocrParser, new Hashtable());
-
-// // JCR
-// RepositoryServiceFactory repositoryServiceFactory = new RepositoryServiceFactory();
-// stopHooks.add(() -> repositoryServiceFactory.shutdown());
-// Activator.registerService(ManagedServiceFactory.class, repositoryServiceFactory,
-// LangUtils.dict(Constants.SERVICE_PID, NodeConstants.NODE_REPOS_FACTORY_PID));
-//
-// NodeRepositoryFactory repositoryFactory = new NodeRepositoryFactory();
-// Activator.registerService(RepositoryFactory.class, repositoryFactory, null);
-
- // Security
-// NodeUserAdmin userAdmin = new NodeUserAdmin(CmsConstants.ROLES_BASEDN, CmsConstants.TOKENS_BASEDN);
-// stopHooks.add(() -> userAdmin.destroy());
-// Activator.registerService(ManagedServiceFactory.class, userAdmin,
-// LangUtils.dict(Constants.SERVICE_PID, CmsConstants.NODE_USER_ADMIN_PID));
-
- }
-
-// private void initSimpleTransactionManager() {
-// SimpleTransactionManager transactionManager = new SimpleTransactionManager();
-// Activator.registerService(WorkControl.class, transactionManager, null);
-// Activator.registerService(WorkTransaction.class, transactionManager, null);
-//// Activator.registerService(TransactionManager.class, transactionManager, null);
-//// Activator.registerService(UserTransaction.class, transactionManager, null);
-// // TODO TransactionSynchronizationRegistry
-// }
-
-// private void initBitronixTransactionManager() {
-// // TODO manage it in a managed service, as startup could be long
-// ServiceReference<TransactionManager> existingTm = bc.getServiceReference(TransactionManager.class);
-// if (existingTm != null) {
-// if (log.isDebugEnabled())
-// log.debug("Using provided transaction manager " + existingTm);
-// return;
-// }
-//
-// if (!TransactionManagerServices.isTransactionManagerRunning()) {
-// bitronix.tm.Configuration tmConf = TransactionManagerServices.getConfiguration();
-// tmConf.setServerId(UUID.randomUUID().toString());
-//
-// Bundle bitronixBundle = FrameworkUtil.getBundle(bitronix.tm.Configuration.class);
-// File tmBaseDir = bitronixBundle.getDataFile(KernelConstants.DIR_TRANSACTIONS);
-// File tmDir1 = new File(tmBaseDir, "btm1");
-// tmDir1.mkdirs();
-// tmConf.setLogPart1Filename(new File(tmDir1, tmDir1.getName() + ".tlog").getAbsolutePath());
-// File tmDir2 = new File(tmBaseDir, "btm2");
-// tmDir2.mkdirs();
-// tmConf.setLogPart2Filename(new File(tmDir2, tmDir2.getName() + ".tlog").getAbsolutePath());
-// }
-// BitronixTransactionManager transactionManager = getTransactionManager();
-// stopHooks.add(() -> transactionManager.shutdown());
-// BitronixTransactionSynchronizationRegistry transactionSynchronizationRegistry = getTransactionSynchronizationRegistry();
-// // register
-// bc.registerService(TransactionManager.class, transactionManager, null);
-// bc.registerService(UserTransaction.class, transactionManager, null);
-// bc.registerService(TransactionSynchronizationRegistry.class, transactionSynchronizationRegistry, null);
-// if (log.isDebugEnabled())
-// log.debug("Initialised default Bitronix transaction manager");
-// }
-
- public void destroy() {
- if (log.isDebugEnabled())
- log.debug("CMS stopping... (" + this.stateUuid + ")");
+ private void initCertificates() {
+ // server certificate
+ Path keyStorePath = Paths.get(getDeployProperty(CmsDeployProperty.SSL_KEYSTORE));
+ Path pemKeyPath = getDataPath(KernelConstants.DEFAULT_PEM_KEY_PATH);
+ Path pemCertPath = getDataPath(KernelConstants.DEFAULT_PEM_CERT_PATH);
+ char[] keyStorePassword = getDeployProperty(CmsDeployProperty.SSL_PASSWORD).toCharArray();
+
+ // Keystore
+ // if PEM files both exists, update the PKCS12 file
+ if (Files.exists(pemCertPath) && Files.exists(pemKeyPath)) {
+ // TODO check certificate update time? monitor changes?
+ KeyStore keyStore = PkiUtils.getKeyStore(keyStorePath, keyStorePassword,
+ getDeployProperty(CmsDeployProperty.SSL_KEYSTORETYPE));
+ try (Reader key = Files.newBufferedReader(pemKeyPath, StandardCharsets.US_ASCII);
+ BufferedInputStream cert = new BufferedInputStream(Files.newInputStream(pemCertPath));) {
+ PkiUtils.loadPrivateCertificatePem(keyStore, CmsConstants.NODE, key, keyStorePassword, cert);
+ Files.createDirectories(keyStorePath.getParent());
+ PkiUtils.saveKeyStore(keyStorePath, keyStorePassword, keyStore);
+ if (log.isDebugEnabled())
+ log.debug("PEM certificate stored in " + keyStorePath);
+ } catch (IOException e) {
+ log.error("Cannot read PEM files " + pemKeyPath + " and " + pemCertPath, e);
+ }
+ }