org.marketcetera.util.auth
Class StandardAuthentication

java.lang.Object
  extended by org.marketcetera.util.auth.StandardAuthentication

public class StandardAuthentication
extends Object

A standard authentication system. A standard system comprises a string holder for a username, and a character array holder for a password; both are required. The contexts employed to retrieve the username and password are, in order, a spring context, a command-line context (which is an override context), and lastly a console context (which is non-override). This class sets up all holders and contexts with default prompts, usage instructions, etc., and provides shorthands to perform operations on the underlying holders and contexts.

Since:
0.5.0
Version:
$Id: StandardAuthentication.java 16154 2012-07-14 16:34:05Z colin $
Author:
tlerios@marketcetera.com

Field Summary
static String PASSWORD_LONG
          The default long form of the command-line option for the password (command-line context).
static String PASSWORD_PROP
          The default property name for the password (Spring context).
static String PASSWORD_SHORT
          The default short form of the command-line option for the password (command-line context).
static String PROPERTIES_FILE_BEAN
          The default name of the properties file bean (Spring context).
static String USER_LONG
          The default long form of the command-line option for the username (command-line context).
static String USER_PROP
          The default property name for the username (Spring context).
static String USER_SHORT
          The default short form of the command-line option for the username (command-line context).
 
Constructor Summary
StandardAuthentication(String configLocation, String[] cliArgs)
          Creates a new standard authentication system with the given options, and using default values for all options not specified in this constructor.
StandardAuthentication(String configLocation, String propertiesFilesBean, String userPropertyName, String passwordPropertyName, String userShort, String userLong, String passwordShort, String passwordLong, String[] cliArgs)
          Creates a new standard authentication system with the given options.
 
Method Summary
 void clearPassword()
          Clears the receiver's password by first overwriting all prior characters with the nul ('\0') character (if the receiver had a non-null password), and then setting the password to null.
 CliContext getCliContext()
          Returns the receiver's command-line context.
 String[] getOtherArgs()
          Returns the command-line arguments which the receiver was unable to parse.
 char[] getPassword()
          Returns the receiver's password.
 String getPasswordAsString()
          Returns the receiver's password as a string.
 String getUser()
          Returns the receiver's username.
 void printUsage(PrintStream stream)
          Prints the receiver's usage instructions onto the given stream.
 boolean setValues()
          Sets the data of the receiver's username and password holders.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

PROPERTIES_FILE_BEAN

public static final String PROPERTIES_FILE_BEAN
The default name of the properties file bean (Spring context).

See Also:
Constant Field Values

USER_PROP

public static final String USER_PROP
The default property name for the username (Spring context).

See Also:
Constant Field Values

PASSWORD_PROP

public static final String PASSWORD_PROP
The default property name for the password (Spring context).

See Also:
Constant Field Values

USER_SHORT

public static final String USER_SHORT
The default short form of the command-line option for the username (command-line context).

See Also:
Constant Field Values

USER_LONG

public static final String USER_LONG
The default long form of the command-line option for the username (command-line context).

See Also:
Constant Field Values

PASSWORD_SHORT

public static final String PASSWORD_SHORT
The default short form of the command-line option for the password (command-line context).

See Also:
Constant Field Values

PASSWORD_LONG

public static final String PASSWORD_LONG
The default long form of the command-line option for the password (command-line context).

See Also:
Constant Field Values
Constructor Detail

StandardAuthentication

public StandardAuthentication(String configLocation,
                              String propertiesFilesBean,
                              String userPropertyName,
                              String passwordPropertyName,
                              String userShort,
                              String userLong,
                              String passwordShort,
                              String passwordLong,
                              String[] cliArgs)
Creates a new standard authentication system with the given options.

Parameters:
configLocation - The location of the Spring configuration file (Spring context).
propertiesFilesBean - The name of the properties file bean (Spring context).
userPropertyName - The property name for the username (Spring context).
passwordPropertyName - The property name for the password (Spring context).
userShort - The short form of the command-line option for the username (command-line context).
userLong - The long form of the command-line option for the username (command-line context).
passwordShort - The short form of the command-line option for the password (command-line context).
passwordLong - The long form of the command-line option for the password (command-line context).
cliArgs - The command-line arguments (command-line context).

StandardAuthentication

public StandardAuthentication(String configLocation,
                              String[] cliArgs)
Creates a new standard authentication system with the given options, and using default values for all options not specified in this constructor.

Parameters:
configLocation - The location of the Spring configuration file (Spring context).
cliArgs - The command-line arguments (command-line context).
Method Detail

setValues

public boolean setValues()
Sets the data of the receiver's username and password holders. Once done, it checks whether both holders have had their data set.

Returns:
True if so.

getCliContext

public CliContext getCliContext()
Returns the receiver's command-line context.

Returns:
The context.

printUsage

public void printUsage(PrintStream stream)
Prints the receiver's usage instructions onto the given stream.

Parameters:
stream - The stream.

getOtherArgs

public String[] getOtherArgs()
Returns the command-line arguments which the receiver was unable to parse.

Returns:
The arguments.

getUser

public String getUser()
Returns the receiver's username.

Returns:
The username, which is null if the username is not set.

getPassword

public char[] getPassword()
Returns the receiver's password.

Returns:
The password, which is null if the password is not set.

getPasswordAsString

public String getPasswordAsString()
Returns the receiver's password as a string. This method should not be called if it is important to ensure that the password can be completely removed from memory using clearPassword(); this is because the string created and returned by this method cannot be zeroed out..

Returns:
The password, which is null if the password is not set.

clearPassword

public void clearPassword()
Clears the receiver's password by first overwriting all prior characters with the nul ('\0') character (if the receiver had a non-null password), and then setting the password to null.



Copyright © 2012. All Rights Reserved.