mirror of
https://github.com/openhab/openhab-addons.git
synced 2025-01-10 15:11:59 +01:00
Fix exec transformation service whitelisting (#14884)
Reported on the german openHAB forum. Signed-off-by: Jan N. Klug <github@klug.nrw>
This commit is contained in:
parent
d7b94b6bd3
commit
dba7fcc697
@ -41,12 +41,14 @@ public class ExecTransformationWhitelistWatchService implements WatchService.Wat
|
|||||||
private final Logger logger = LoggerFactory.getLogger(ExecTransformationWhitelistWatchService.class);
|
private final Logger logger = LoggerFactory.getLogger(ExecTransformationWhitelistWatchService.class);
|
||||||
private final Set<String> commandWhitelist = new HashSet<>();
|
private final Set<String> commandWhitelist = new HashSet<>();
|
||||||
private final WatchService watchService;
|
private final WatchService watchService;
|
||||||
|
private final Path watchFile;
|
||||||
|
|
||||||
@Activate
|
@Activate
|
||||||
public ExecTransformationWhitelistWatchService(
|
public ExecTransformationWhitelistWatchService(
|
||||||
final @Reference(target = WatchService.CONFIG_WATCHER_FILTER) WatchService watchService) {
|
final @Reference(target = WatchService.CONFIG_WATCHER_FILTER) WatchService watchService) {
|
||||||
this.watchService = watchService;
|
this.watchService = watchService;
|
||||||
watchService.registerListener(this, COMMAND_WHITELIST_FILE);
|
this.watchFile = watchService.getWatchPath().resolve(COMMAND_WHITELIST_FILE);
|
||||||
|
watchService.registerListener(this, COMMAND_WHITELIST_FILE, false);
|
||||||
|
|
||||||
// read initial content
|
// read initial content
|
||||||
processWatchEvent(WatchService.Kind.CREATE, COMMAND_WHITELIST_FILE);
|
processWatchEvent(WatchService.Kind.CREATE, COMMAND_WHITELIST_FILE);
|
||||||
@ -59,9 +61,9 @@ public class ExecTransformationWhitelistWatchService implements WatchService.Wat
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void processWatchEvent(WatchService.Kind kind, Path path) {
|
public void processWatchEvent(WatchService.Kind kind, Path path) {
|
||||||
if (path.endsWith(COMMAND_WHITELIST_FILE)) {
|
commandWhitelist.clear();
|
||||||
commandWhitelist.clear();
|
if (kind != WatchService.Kind.DELETE) {
|
||||||
try (Stream<String> lines = Files.lines(path)) {
|
try (Stream<String> lines = Files.lines(watchFile)) {
|
||||||
lines.filter(line -> !line.trim().startsWith("#")).forEach(commandWhitelist::add);
|
lines.filter(line -> !line.trim().startsWith("#")).forEach(commandWhitelist::add);
|
||||||
logger.debug("Updated command whitelist: {}", commandWhitelist);
|
logger.debug("Updated command whitelist: {}", commandWhitelist);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
|
Loading…
Reference in New Issue
Block a user