How do I create a Login Module?
Author: Deron Eriksson
Description: This Java tutorial describes how to create a Login Module.
Tutorial created using: Windows XP || JDK 1.5.0_09 || Eclipse Web Tools Platform 2.0 (Eclipse 3.3.0)

Page: < 1 2

(Continued from page 1)

If we execute JaasAuthenticationTest, we see the following results in the Console view below. The LoginContext object is created and a TestCallbackHandler object is created. The lc.login() call creates a TestLoginModule object, and it is initialized via its initialize() method. Notice that the option value from jaas.config is displayed to the console. Next, the login() method of the TestLoginModule object is called, and the TestCallbackHandler's handle method is called to retrieve the name and password for the Login Module. Since the name and password are valid, TestLoginModule's login() method displays a "Success" method and returns true. Its commit() method is then called.

Execution of JaasAuthenticationTest

As a further test, I changed the password from "myPassword" to "myBadPassword". When executing JaasAuthenticationTest, we now see that a FailedLoginException is thrown by the Login Module's login() method since the password isn't valid.


JAAS is a fairly advanced JavaSW topic, but as you can see in this example, the basics of JAAS authentication are not too difficult to understand.

Page: < 1 2