Database Reference
In-Depth Information
Set Application Context
You will recall from our discussion in the previous section that we are gathering all our application-
specific elements in one place. We will store the
applicationID
,
appClass
, and
twoFactorAuth
code in
OracleJavaSecure
as static class members, so we needn't pass them around to all the methods where
they will be referenced.
When an application initially comes to
OracleJavaSecure
, the first thing it will likely do is identify
itself by calling the
setAppContext()
method, Listing 10-21.
setAppContext()
takes the
applicationID
,
inner class, and
twoFactorAuth
code as arguments. The first time we run a client application, the
twoFactorAuth
code is not provided. It will not be until the user has received the two-factor code on their
cell phone or other device that they will be able to return and redo this identification and proceed.
In order to request connection strings, we will have to pass muster with the application verification,
appver
security guard. That means we will have to present our inner class to the application
authorization procedures. In the
setAppContext()
method, we assure that the inner class we will be
presenting implements both the
RevLvlClassIntfc
interface, and the
Serializable
interface by calling
the
instanceof
operator.
Listing 10-21.
Set Application Context,
setAppContext()
private static String applicationID = null;
private static Object appClass = null;
private static String twoFactorAuth = null;
public static final void
setAppContext
( String applicationID,
Object appClass, String twoFactorAuth )
{
twoFactorAuth = checkFormat2Factor( twoFactorAuth );
if( null == applicationID || null == appClass ) {
System.out.println( "Must have an application ID and Class" );
return;
}
// Assure the app class has implemented our interface
if ( !( (
appClass instanceof RevLvlClassIntfc
) &&
(
appClass instanceof Serializable
) ) )
{
System.out.println(
"Application ID Class must implement RevLvlClassIntfc" );
return;
}
// Set class static member equal to what passed here at outset
OracleJavaSecure.applicationID = applicationID
;
OracleJavaSecure.appClass = appClass;
OracleJavaSecure.twoFactorAuth = twoFactorAuth;
}
As a side note, we have seen methods like this before where we pass in references that are the same
as class member names. We typically have set the class members with a statement like this:
this.varName = varName;