@ThreadSafety(level=NOT_THREADSAFE) public final class PasswordReader extends java.lang.Thread
java.io.Console.readPassword
method will be used to accomplish this.
For Java SE 5 clients, a more primitive approach must be taken, which
requires flooding standard output with backspace characters using a
high-priority thread. This has only a limited effectiveness, but it is the
best option available for older Java versions.Modifier and Type | Method and Description |
---|---|
static byte[] |
readPassword()
Reads a password from the console as a byte array.
|
static char[] |
readPasswordChars()
Reads a password from the console as a character array.
|
void |
run()
Repeatedly sends backspace and space characters to standard output in an
attempt to try to hide what the user enters.
|
static void |
setTestReader(java.io.BufferedReader reader)
Specifies the input stream from which to read the password.
|
static void |
setTestReaderLines(java.lang.String... lines)
Specifies the lines that should be used as input when reading the password.
|
activeCount, checkAccess, clone, countStackFrames, currentThread, destroy, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, start, stop, stop, suspend, toString, yield
public static char[] readPasswordChars() throws LDAPException
LDAPException
- If a problem is encountered while trying to read
the password.public static byte[] readPassword() throws LDAPException
LDAPException
- If a problem is encountered while trying to read
the password.public void run()
run
in interface java.lang.Runnable
run
in class java.lang.Thread
@InternalUseOnly public static void setTestReaderLines(java.lang.String... lines)
setTestReader(BufferedReader)
method should be called with a value
of null
before the end of the test to ensure that the password
reader is reverted back to its normal behavior.lines
- The lines of input that should be provided to the password
reader instead of actually obtaining them interactively.
It must not be null
but may be empty.@InternalUseOnly public static void setTestReader(java.io.BufferedReader reader)
null
before the end of the test to ensure
that the password reader is reverted back to its normal behavior.reader
- The input stream from which to read the password. It may
be null
to obtain the password from the normal
means.