org.opends.server.util
Class PasswordReader

java.lang.Object
  extended by java.lang.Thread
      extended by org.opends.server.api.DirectoryThread
          extended by org.opends.server.util.PasswordReader
All Implemented Interfaces:
java.lang.Runnable

@PublicAPI(stability=UNCOMMITTED,
           mayInstantiate=false,
           mayExtend=false,
           mayInvoke=true)
public final class PasswordReader
extends DirectoryThread

This class provides a means of interactively reading a password from the command-line without echoing it to the console. If it is running on a Java 6 or higher VM, then it will use the System.console() method. If it is running on Java 5, then it will use an ugly hack in which one thread will be used to repeatedly send backspace characters to the console while another reads the password. Reflection is used to determine whether the Java 6 method is available and to invoke it if it is so that the code will still compile cleanly on Java 5 systems.


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 char[] readPassword()
          Reads a password from the console without echoing it to the client.
 void run()
          Operates in a loop, sending backspace characters to the console to attempt to prevent exposing what the user entered.
 
Methods inherited from class org.opends.server.api.DirectoryThread
getAssociatedTask, getCreationStackTrace, getDebugProperties, getParentThread, setAssociatedTask
 
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

run

@PublicAPI(stability=PRIVATE,
           mayInstantiate=false,
           mayExtend=false,
           mayInvoke=false)
public void run()
Operates in a loop, sending backspace characters to the console to attempt to prevent exposing what the user entered. It sets the priority to the maximum allowed value to reduce the chance of one or more characters being displayed temporarily before they can be erased.

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

readPassword

public static char[] readPassword()
Reads a password from the console without echoing it to the client.

Returns:
The password as an array of characters.