You don't need to write your own JAAS login module. I guess the missing piece which i did not tell you when i showed the code was that you have to set the following JVM option before you can run that code successfully :
-Djava.security.auth.login.config="<path.to.glassfish.home>/lib/appclient/appclientlogin.conf"
[Message sent by forum member 'kumarjayanti' (kumarjayanti)]
http://forums.java.net/jive/thread.jspa?messageID=351625