All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.nosqlbench.driver.jmx.SecureUtils Maven / Gradle / Ivy

Go to download

A JMX nosqlbench ActivityType (AT) driver module; This provides the ability to query system via JMX

There is a newer version: 4.15.102
Show newest version
package io.nosqlbench.driver.jmx;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;

public class SecureUtils {
    private final static Logger logger = LogManager.getLogger(SecureUtils.class);

    public static String readSecret(String description, String source) {
        if (source==null) {
            return null;
        }

        if (source.startsWith("file:")) {
            String sourceFile = source.substring("file:".length());
            try {
                return Files.readString(Path.of(sourceFile), StandardCharsets.UTF_8);
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        } else if (source.startsWith("console:")||source.equals("")) {
            System.out.print("Enter " + description+":");

            char[] chars = System.console().readPassword("%s:",description);
            return new String(chars);
        } else {
            logger.warn("Parameter for '" + description + "' was passed directly. This is less secure." +
                    " Consider using 'file:' or 'console:' for this value instead");
            return source;
        }
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy