Using Pluggable Authentication in Red Hat Web Application Framework

The intended audience for this document is developers who want to understand, configure, or extend the Red Hat Web Application Framework authentication system. Red Hat Web Application Framework is designed to support a variety of authentication technologies using Pluggable Authentication (PAM). Administrators can configure Red Hat Web Application Framework to use any of the provided login modules, or they can define and use new modules. Red Hat Web Application Framework uses the Java Authentication and Authorization (JAAS) API and supports new login modules that implement this API.

This tutorial describes the provided login modules and explains how to implement new modules. It assumes familiarity with PAM and the JAAS API.

Java API for Pluggable Authentication

All Red Hat Web Application Framework Java classes related to pluggable authentication are located in the com.arsdigita.kernel.security package.

The classes that make up the authentication system include:

Overview of the Authentication System

Red Hat Web Application Framework authenticates users at two times: upon each HTTP request and at the registration page. The Request login is automatic and uses information stored in the user's HTTP request, such as form variables, HTTP authentication parameters, URL parameters, and cookies. The Register login is interactive and uses a username and password provided by the user (although it can also access the HTTP request).

The configuration for both logins is defined in the loginConfig entry under the kernel.security.Initializer in enterprise.init. The syntax for this configuration is described in the LoginConfig constructor documentation.

The default Request configuration requires that AdminLoginModule, RecoveryLoginModule, or CookieLoginModule succeed. If all fail, the user is not logged in, but the request continues. If any succeed, the user is logged in and the user's authentication cookie is refreshed, if needed.

The default Register configuration first runs LocalLoginModule, which succeeds if the user enters a valid username and password. UserIDLoginModule then translates the given username into a Red Hat Web Application Framework user ID. Finally, CookieLoginModule sets a new cookie for the user, if needed.

If the user enters a bad password, LocalLoginModule throws a FailedLoginException, which causes the user to receive a "Bad Password" error. If the user does not exist, LocalLoginModule (or UserIDLoginModule) throws an AccountNotFoundException, which causes the user to be redirected to a "New User" page. Any login module can throw these exceptions to get the same results. If any other LoginException is thrown, the user registration form displays an error.

Configuring the Authentication System

Red Hat Web Application Framework provides alternate authentication technologies that can be configured by editing the login configuration in enterprise.init (see loginConfig above). To configure cookie-less login (needed for certain types of wireless clients), simply replace the instances of CookieLoginModule with URLLoginModule in the login configuration.

Session tracking is handled separately from authentication. Change the sessionTrackingMethod option from "cookie" to "url" for cookie-less session tracking. This automatically selects whether SessionCookieLoginModule or SessionURLLoginModule should be used for session tracking.

Extending the Authentication System

The main strength of Pluggable Authentication is that the system may be extended with new authentication technologies. This is done by implementing new LoginModules. For example, an LDAP server can be used to authenticate a user by username and password. To integrate this behavior into Red Hat Web Application Framework, a new login module (for example, LDAPLoginModule) must be defined.

LDAPLoginModule would replace LocalLoginModule in the login configuration. It needs its own configuration information to determine how to connect to the LDAP serve. This information can be hard-coded into the module, read from a file, provided by an Initializer, or passed as an option in the login configuration.

If the LDAP username does not match the Red Hat Web Application Framework username, another login module must be defined to map the LDAP username to a Red Hat Web Application Framework user ID. This module, (for example, LDAPUserLoginModule), would replace UserIDLoginModule and must implement MappingLoginModule.getUserID(username) appropriately.

Another way to change the way authentication works is to edit the sequence of login modules in the login configuration. By replacing, changing the order of, or changing the control flag of login modules in the login configuration, you can create a variety of authentication sequences (not all of which make sense or are secure, so be careful!). See the JAAS Configuration documentation for more information.