Java Properties maskApplicationEnvProperties(Map environmentVariables, Set variablesToMask)

Here you can find the source of maskApplicationEnvProperties(Map environmentVariables, Set variablesToMask)

Description

mask Application Env Properties

License

Apache License

Declaration

static Map<String, String> maskApplicationEnvProperties(Map<String, String> environmentVariables,
            Set<String> variablesToMask) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.util.*;

public class Main {
    static Map<String, String> maskApplicationEnvProperties(Map<String, String> environmentVariables,
            Set<String> variablesToMask) {
        HashMap<String, String> masked = new HashMap<>();
        for (String variableKey : environmentVariables.keySet()) {
            if (variablesToMask.contains(variableKey)) {
                masked.put(variableKey, maskEnvironmentVariable(environmentVariables.get(variableKey)));
            } else {
                masked.put(variableKey, environmentVariables.get(variableKey));
            }/*from  ww  w .  ja  va  2s .c om*/
        }
        return masked;
    }

    private static String maskEnvironmentVariable(String variableValue) {
        if (variableValue == null || variableValue.length() < 5) {
            // We assume short variable values are not sensitive
            return variableValue;
        }
        return variableValue.substring(0, 2) + "..."
                + variableValue.substring(variableValue.length() - 2, variableValue.length());
    }
}

Related

  1. equalProps(Properties p1, Properties p2)
  2. extractFromPropertiesAsList(String prefix, Properties properties)
  3. extractFromPropertiesAsMap(String prefix, Properties properties)
  4. isKeySame(String key, Properties p1, Properties p2)
  5. isSupportedJVM(Map jdkProperties)
  6. mergePropertiesIntoMap(Properties props, Map map)
  7. mergePropertiesIntoMap(Properties props, Map map)
  8. mergeSystemProperties(Properties properties)
  9. propertiesToJson(Properties properties)