cox.jmatt.java.MathTools.util
Class SimpleAuthenticator

java.lang.Object
  extended by cox.jmatt.java.MathTools.util.SimpleAuthenticator
All Implemented Interfaces:
MAuthenticator

public class SimpleAuthenticator
extends java.lang.Object
implements MAuthenticator

This class provides a fully-functional MAuthenticator implementation. It can be used as-is for authentication code generation or it can serve as an example of how an implementation should work. To function properly SimpleAuthenticator must be initialized with a prime number. There is a default value but another can be used if desired. The number should be at least three digits but no more than five and it must be prime otherwise duplicate codes may be generated.

Three levels of codes are generated: Student, Proctor, and Instructor. ADMIN and NONE automatically authenticate to false. The code formats are:

The same basic mechanism is used to generate all codes but since the formats are different cross-authentication will not work!

All necessary information is contained within the authentication code itself. Nothing outside this class is required to generate or use the codes. More complex or secure implementations might look up information from a database or a dedicated server; but such is beyond the scope of this class.

IMPORTANT NOTE: Although this implementation is self-contained, codes will not work if the authenticator is initialized with a value different from the one used to generate them!


Field Summary
static java.lang.String MYSELF
          String constant holding the fully-qualified class name.
 
Fields inherited from interface cox.jmatt.java.MathTools.util.MAuthenticator
AUTH_ADMIN, AUTH_INSTRUCTOR, AUTH_NONE, AUTH_PROCTOR, AUTH_STUDENT
 
Constructor Summary
SimpleAuthenticator()
          Zero-argument constructor required for CapCom use.
 
Method Summary
 java.lang.String[] generateCodes(byte pLevel, int pNumberOf, java.lang.Object... pIgnored)
          Generate codes.
 void initMAuthenticator(java.lang.Object pPrimeInt)
          All authentication codes operate around a non-negative prime integer.
 boolean mAuthenticate(byte pLevel, java.lang.String pCode)
          Authenticate a code.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

MYSELF

public static final java.lang.String MYSELF
String constant holding the fully-qualified class name.

See Also:
Constant Field Values
Constructor Detail

SimpleAuthenticator

public SimpleAuthenticator()
Zero-argument constructor required for CapCom use.

Method Detail

initMAuthenticator

public final void initMAuthenticator(java.lang.Object pPrimeInt)
All authentication codes operate around a non-negative prime integer. It should be at least 2 digits, more is better. To change the default value pass a String containing the new value. Any errors are reported at Debug level. Passing null resets the default value.

Specified by:
initMAuthenticator in interface MAuthenticator
Parameters:
pPrimeInt - A non-negative prime integer (int or long), sent in as a String.

mAuthenticate

public final boolean mAuthenticate(byte pLevel,
                                   java.lang.String pCode)
Authenticate a code. Each level has a specific format so the pLevel argument is critical! No code will cross-authenticate at a different level, even if it is fundamentally identical to another at a different level. (I.e. the base numbers used to generate them were identical.)

Specified by:
mAuthenticate in interface MAuthenticator
Parameters:
pLevel - The AUTH_ constant for the desired authentication level.
pCode - The authentication code to check at the specified level.
Returns:
true if the code is valid, false otherwise.

generateCodes

public final java.lang.String[] generateCodes(byte pLevel,
                                              int pNumberOf,
                                              java.lang.Object... pIgnored)
Generate codes. The only parameters used are pLevel and pNumberOf. This class neither requires nor uses the Object params.

Specified by:
generateCodes in interface MAuthenticator
Parameters:
pLevel - The level of authentication codes to generate.
pNumberOf - The number of codes to generate. If less than one, one is generated.
pIgnored - Not used.