[ Team LiB ] |
![]() ![]() |
Recipe 15.7 Creating the JAAS Configuration FileProblemYou want to create the JAAS configuration file. SolutionCreate the configuration file, then specify the configuration's location on your filesystem in the ${java.home}/jre/lib/security/java.security file. DiscussionUsing 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 fileWebLogin { 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 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.
How does the JAAS implementation find the configuration file? The directory ${java.home}/jre/lib/security contains a file named java.security. 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: login.config.url.1=file:h:/home/.java.login.config 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 java.security file.
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 AlsoSun Microsystems' JAAS developer's guide: http://java.sun.com/j2se/1.4.2/docs/guide/security/jaas/JAASLMDevGuide.html; a list of JAAS tutorials and sample programs: http://java.sun.com/j2se/1.4.2/docs/guide/security/jaas/JAASRefGuide.html; the Javadoc relating to JAAS configuration files: http://java.sun.com/j2se/1.4.1/docs/api/javax/security/auth/login/Configuration.html; Recipe 15.8 on using JAAS with a servlet; Recipe 15.9 on using JAAS with a JSP. |
[ Team LiB ] |
![]() ![]() |