The following is from my LoginAction class:
try
{
SecurityAssociationHandler handler = new
SecurityAssociationHandler();
SimplePrincipal user = new SimplePrincipal(username);
handler.setSecurityInfo(user, password.toCharArray());
LoginContext loginContext = new LoginContext("MySqlDBRealm", (CallbackHandler)handler);
loginContext.login();
Subject subject = loginContext.getSubject();
Set principals = subject.getPrincipals();
principals.add(user);
InitialContext ctx = new InitialContext();
Logon logon = (Logon) ctx.lookup(Logon.class.getName());
System.out.println("Addition: "+logon.add(2, 2));
System.out.println("Subtract: "+logon.subtract(4, 2));
}catch(Exception e)
{
System.out.println("Incorrect password or username");
}