Database Reference
In-Depth Information
return;
OracleJavaSecure.setAppContext(applicationID, appClass,
twoFactCodeTextField.getText()
);
OracleJavaSecure.getAppConnections();
if (!
OracleJavaSecure.test2Factor()
) {
twoFactCodeTextField.setText("Bad two-factor code");
reEnterLabel.setVisible(true);
return;
}
this.setVisible(false)
;
return;
}
This time, after we return from the
getAppConnections()
method, we can test whether the two-factor
code that was entered was successful by calling
OracleJavaSecure.test2Factor()
. This is a new method
added in this chapter, the code for which is shown in Listing 12-8. We simply test the size of our list of
connection strings that was returned as a result of providing our two-factor authentication code to the
getAppConnections()
method. A size of 0 is okay, and any other value is okay—it means the two-factor
code was successful and
test2Factor()
returns a
true
. However, if the call to
consHash.size()
results in
an
Exception
being thrown, then the list of connection strings is null, and we determine that the two-
factor code was not acceptable, so we return a
false
.
Listing 12-8.
Test Success of two-factor Code from OracleJavaSecure
public static boolean test2Factor() {
try {
connsHash.size();
} catch( Exception x ) {
return false;
}
return true;
}
Back in our
Login
class, in Listing 12-7, if the two-factor code is not good, we set our message in
twoFactCodeTextField
to “Bad two-factor code” and we make the
reEnterLabel
text visible. We are
presenting user-feedback in the same text field used for user entry. Look back at the top of that method,
continueButton_actionPerformed()
. You can see how we handle messages in the field where we want the
user to enter the two-factor authentication code. If they have a blank or one of our error message strings
in that field, we do not try to submit it as a two-factor authentication code, but simply return.
A successful login event, where the two-factor code is acceptable and a list of connection strings has
been returned causes the last lines of
continueButton_actionPerformed()
to be run. In that case, we
basically set the Login screen to be invisible.
The Login Screen Closes
One final trick you might be interested in here: if the user exits the Login screen without completing the
intended activities, then we exit the entire JVM that is running the application. This is handled through
the
this_WindowClosing()
method with a call to
System.exit()
, which is shown in Listing 12-9. The
method,
this_WindowClosing()
gets called automatically whenever the user clicks the X in the upper
right-hand corner of the window to close it. In the normal process of entering an application, we will not
close the
Login
screen, but will simply make it invisible.