Recipe 15.7 Creating the JAAS Configuration File


You want to create the JAAS configuration file.


Create the configuration file, then specify the configuration's location on your filesystem in the ${java.home}/jre/lib/security / file.


Using JAAS also involves writing a configuration file to identify the LoginModule (s) that a particular application will use. The configuration file in Example 15-11 specifies an application named "WebLogin."

Example 15-11. A JAAS configuration file
 WebLogin {    com.jspservletcookbook.DataSourceLoginModule requisite; }; 

Although only one module is specified in this recipe, one of the powerful features of the JAAS security design is to use multiple LoginModules or layers in order to authenticate users. A user might have to be authenticated in several ways before she gains access to web components and data (e.g., first her irises are scanned, then she must specify a username and password).

The configuration file specifies:

  • The fully qualified class name of the LoginModule (s).

  • A "Flag" value, which is just a constant expression such as "required" or "requisite." The example uses "requisite." Table 15-1 describes the different Flag values.

  • One or more "options" (Example 15-11 does not identify any options). The options represent a space-separated list of name/value pairs, such as debug="true" (you can use any name/value pairing you want). The options allow the configuration file to pass properties and values to the underlying LoginModule .

Table 15-1. Flag values for JAAS configuration files

Flag name



The LoginModule is required to succeed, and overall authentication fails if a LoginModule marked "required" fails. However, if a failure occurs, authentication still continues down the LoginModule list.


The LoginModule is required to succeed, and runtime control returns to the application (rather than continuing with any other listed LoginModule s) if authentication failure occurs.


If the LoginModule succeeds, control returns to the application and does not continue with any other listed LoginModule s. If an authentication failure occurs, authentication continues with any other LoginModule . In other words, the failure of this LoginModule does not automatically lead to the failure of overall authentication, as in "required" or "requisite."


Success is not required with this LoginModule . If authentication success or failure occurs, authentication continues with any other listed LoginModule s.

The basic structure of the configuration file looks like this:

 ApplicationName{     ModuleName Flag Options;     ModuleName Flag Options;     ModuleName Flag Options; }; AnotherApplication{     ModuleName Flag Options;     ModuleName Flag Options; }; 

Again, you do not have to use multiple LoginModules .

See this Javadoc page for more details on configuration:

How does the JAAS implementation find the configuration file? The directory ${java.home}/jre/lib/security contains a file named . This is a "properties" or "policy" file in Java security parlance ”a text file containing name/value pairs. The following line of text provides the location of the JAAS configuration file for the authentication servlet of Example 15-11:


If you have other JAAS configuration files that you want to combine with this one, use syntax similar to login.config.url.2=file:h:/home/.my.config (note the incremented number 2 ), placed within the file.

You can use any filenaming convention; the configuration filename does not have to begin with a period.

A single JAAS configuration file can specify the LoginModule (s) for multiple application names . Recipe 15.8 shows a servlet that uses the LoginModule described in Recipe 15.5.

See Also

Sun Microsystems' JAAS developer's guide:; a list of JAAS tutorials and sample programs:; the Javadoc relating to JAAS configuration files:; Recipe 15.8 on using JAAS with a servlet; Recipe 15.9 on using JAAS with a JSP.

Java Servlet & JSP Cookbook
Java Servlet & JSP Cookbook
ISBN: 0596005725
EAN: 2147483647
Year: 2004
Pages: 326

Similar book on Amazon © 2008-2017.
If you may any questions please contact us: