karaf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jbono...@apache.org
Subject [karaf] branch karaf-4.2.x updated: [KARAF-6417] Make users properties file configurable (again) for AutoEncryptionSupport
Date Mon, 16 Sep 2019 13:36:14 GMT
This is an automated email from the ASF dual-hosted git repository.

jbonofre pushed a commit to branch karaf-4.2.x
in repository https://gitbox.apache.org/repos/asf/karaf.git


The following commit(s) were added to refs/heads/karaf-4.2.x by this push:
     new 9d40657  [KARAF-6417] Make users properties file configurable (again) for AutoEncryptionSupport
     new c002f63  Merge pull request #936 from grgrzybek/KARAF-6417-42x
9d40657 is described below

commit 9d40657e6fcf2d8a94768148405d4fa1400ee0cf
Author: Grzegorz Grzybek <gr.grzybek@gmail.com>
AuthorDate: Mon Sep 16 09:27:36 2019 +0200

    [KARAF-6417] Make users properties file configurable (again) for AutoEncryptionSupport
---
 .../modules/properties/AutoEncryptionSupport.java    | 20 ++++++++++++++++++--
 1 file changed, 18 insertions(+), 2 deletions(-)

diff --git a/jaas/modules/src/main/java/org/apache/karaf/jaas/modules/properties/AutoEncryptionSupport.java
b/jaas/modules/src/main/java/org/apache/karaf/jaas/modules/properties/AutoEncryptionSupport.java
index 9339f21..4ac608c 100644
--- a/jaas/modules/src/main/java/org/apache/karaf/jaas/modules/properties/AutoEncryptionSupport.java
+++ b/jaas/modules/src/main/java/org/apache/karaf/jaas/modules/properties/AutoEncryptionSupport.java
@@ -19,6 +19,7 @@ package org.apache.karaf.jaas.modules.properties;
 import static java.nio.file.StandardWatchEventKinds.ENTRY_MODIFY;
 
 import java.io.Closeable;
+import java.io.File;
 import java.io.IOException;
 import java.nio.file.FileSystems;
 import java.nio.file.Path;
@@ -45,9 +46,17 @@ public class AutoEncryptionSupport implements Runnable, Closeable {
     private EncryptionSupport encryptionSupport;
     private ExecutorService executor;
 
+    private String usersFileName;
+
     public AutoEncryptionSupport(Map<String, Object> properties) {
         running = true;
         encryptionSupport = new EncryptionSupport(properties);
+        Object usersFile = properties.get(PropertiesLoginModule.USER_FILE);
+        if (usersFile instanceof File) {
+            usersFileName = ((File) usersFile).getAbsolutePath();
+        } else if (usersFile != null) {
+            usersFileName = usersFile.toString();
+        }
         executor = Executors.newSingleThreadExecutor(ThreadUtils.namedThreadFactory("encryption"));
         executor.execute(this);
     }
@@ -67,10 +76,17 @@ public class AutoEncryptionSupport implements Runnable, Closeable {
         WatchService watchService = null;
         try {
             watchService = FileSystems.getDefault().newWatchService();
-            Path dir = Paths.get(System.getProperty("karaf.etc"));
+            Path dir = null;
+            Path file = null;
+            if (usersFileName == null) {
+                dir = Paths.get(System.getProperty("karaf.etc"));
+                file = dir.resolve("users.properties");
+            } else {
+                file = new File(usersFileName).toPath();
+                dir = file.getParent();
+            }
             dir.register(watchService, ENTRY_MODIFY);
 
-            Path file = dir.resolve("users.properties");
             encryptedPassword(new Properties(file.toFile()));
 
             while (running) {


Mime
View raw message