/*
 * Copyright © 2013-2021, The SeedStack authors <http://seedstack.org>
 *
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 */
package org.seedstack.seed.core.internal.configuration;

import java.util.Locale;
import org.seedstack.coffig.TreeNode;
import org.seedstack.coffig.node.MapNode;
import org.seedstack.coffig.node.NamedNode;
import org.seedstack.coffig.spi.ConfigurationProcessor;

public class SecureConfigurationProcessor implements ConfigurationProcessor {
    @Override
    public void process(MapNode configuration) {
        configuration.get("env").ifPresent(TreeNode::hide);
        configuration.get("sys").ifPresent(TreeNode::hide);
        configuration.walk()
                .filter(node -> node.type() == TreeNode.Type.MAP_NODE)
                .forEach(node -> node.namedNodes()
                        .filter(this::isPotentialPassword)
                        .forEach(namedNode -> namedNode.node().hide())
                );
    }

    private boolean isPotentialPassword(NamedNode namedNode) {
        String key = namedNode.name().toUpperCase(Locale.ENGLISH);
        return key.contains("PASSWORD") || key.contains("PASSWD") || key.contains("PWD");
    }
}

@@ -337,33 +337,8 @@
 n;%0A%0A
-import java.util.Locale;%0A
 impo
@@ -367,24 +367,24 @@
 g.TreeNode;%0A
+
 import org.s
@@ -514,16 +514,42 @@
 essor;%0A%0A
+import java.util.Locale;%0A%0A
 public c
@@ -632,16 +632,16 @@
 verride%0A
+
     publ
@@ -685,128 +685,8 @@
 ) %7B%0A
-        configuration.get(%22env%22).ifPresent(TreeNode::hide);%0A        configuration.get(%22sys%22).ifPresent(TreeNode::hide);%0A
     
@@ -1206,16 +1206,42 @@
 s(%22PWD%22)
+ %7C%7C key.contains(%22SECRET%22)
 ;%0A    %7D%0A

Tweak hidden config nodes