hide passwords in logs

This commit is contained in:
Peter Hormanns 2018-03-07 15:10:47 +01:00
parent 9c7202f358
commit 240c391abd
2 changed files with 8 additions and 3 deletions

View File

@ -9,6 +9,8 @@ import java.io.PrintWriter;
import java.util.logging.Level;
import java.util.logging.Logger;
import de.hsadmin.core.util.TextUtil;
public class CommandShell {
private static final Logger logger = Logger.getLogger("de.hsadmin.core.qserv");
@ -28,7 +30,10 @@ public class CommandShell {
if (logCommand != null && (logCommand.startsWith("newusers") || logCommand.startsWith("chpasswd"))) {
// escape new password !
final String[] strings = stdInput.split("\\:", 3);
logCommand += "<<EOF\n" + strings[0] + ":***:";
logCommand += "<<EOF\n" + strings[0];
if (strings.length > 1) {
logCommand += ":" + TextUtil.hidePassword(strings[1]) + ":";
}
if (strings.length > 2) {
logCommand += strings[2] + "EOF";
}

View File

@ -77,8 +77,8 @@ public class TextUtil {
}
public static synchronized String hidePassword(String passwd) {
StringBuffer val = new StringBuffer(passwd.substring(0, 2));
for (int i = 2; i < passwd.length(); i++) {
final StringBuffer val = new StringBuffer(passwd.substring(0, 2));
for (int i = 2; i < 6; i++) {
val.append('*');
}
return val.toString();