Make users properties file configurable (again) for AutoEncryptionSupport
@@ -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) {
