uk.ac.starlink.table.jdbc
Class TerminalAuthenticator

java.lang.Object
  |
  +--uk.ac.starlink.table.jdbc.TerminalAuthenticator
All Implemented Interfaces:
JDBCAuthenticator

public class TerminalAuthenticator
extends Object
implements JDBCAuthenticator

Provides JDBC authentication using the terminal; assumes that someone is sitting at System.in.


Constructor Summary
TerminalAuthenticator()
          Constructs a new authenticator which uses System.err for prompting.
TerminalAuthenticator(PrintStream promptStrm)
          Constructs a new authenticator with a given stream to use for writing prompts.
 
Method Summary
 String[] authenticate()
          Obtains username and password.
static String readMaskedString(String prompt, PrintStream outStrm)
          Reads a line of text from the user without it being visible to onlookers.
 String readPassword()
          Prompts to the prompt stream and reads the password from standard input.
static String readString(String prompt, PrintStream outStrm)
          Reads a line of text from the user.
 String readUser()
          Prompts to the prompt stream and reads the user name from standard input.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

TerminalAuthenticator

public TerminalAuthenticator(PrintStream promptStrm)
Constructs a new authenticator with a given stream to use for writing prompts.

Parameters:
promptStrm - output stream for prompting

TerminalAuthenticator

public TerminalAuthenticator()
Constructs a new authenticator which uses System.err for prompting.

Method Detail

authenticate

public String[] authenticate()
                      throws IOException
Description copied from interface: JDBCAuthenticator
Obtains username and password. The return value is a two-element array containing the username and password to be used, in that order. Either or both of these may be null.

Specified by:
authenticate in interface JDBCAuthenticator
Returns:
String[]{username,password}
Throws:
IOException - if there is some error

readUser

public String readUser()
                throws IOException
Prompts to the prompt stream and reads the user name from standard input.

Returns:
user name obtained from user
IOException

readPassword

public String readPassword()
                    throws IOException
Prompts to the prompt stream and reads the password from standard input.

Returns:
password obtained from user
IOException

readString

public static String readString(String prompt,
                                PrintStream outStrm)
                         throws IOException
Reads a line of text from the user.

Parameters:
prompt - short line of text to act as a prompt
outStrm - print stream to use for prompt output - typically System.err
IOException

readMaskedString

public static String readMaskedString(String prompt,
                                      PrintStream outStrm)
                               throws IOException
Reads a line of text from the user without it being visible to onlookers. Suitable utility method for soliciting passwords.

Parameters:
prompt - short line of text to act as a prompt
outStrm - print stream to use for output - typically System.err
Returns:
string entered by user
IOException

Copyright © 2004 CLRC: Central Laboratory of the Research Councils. All rights reserved.