com.unboundid.util
Class PasswordReader

java.lang.Object
  extended by java.lang.Thread
      extended by com.unboundid.util.PasswordReader
All Implemented Interfaces:
java.lang.Runnable

@ThreadSafety(level=NOT_THREADSAFE)
public final class PasswordReader
extends java.lang.Thread

This class provides a mechanism for reading a password from the command line in a way that attempts to prevent it from being displayed. If it is available (i.e., Java SE 6 or later), the 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.


Nested Class Summary
 
Nested classes/interfaces inherited from class java.lang.Thread
java.lang.Thread.State, java.lang.Thread.UncaughtExceptionHandler
 
Field Summary
 
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
 
Method Summary
static byte[] readPassword()
          Reads a password from the console.
 void run()
          Repeatedly sends backspace and space characters to standard output in an attempt to try to hide what the user enters.
 
Methods inherited from class java.lang.Thread
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
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Method Detail

readPassword

public static byte[] readPassword()
                           throws LDAPException
Reads a password from the console.

Returns:
The characters that comprise the password that was read.
Throws:
LDAPException - If a problem is encountered while trying to read the password.

run

public void run()
Repeatedly sends backspace and space characters to standard output in an attempt to try to hide what the user enters.

Specified by:
run in interface java.lang.Runnable
Overrides:
run in class java.lang.Thread