Document directory
- Ntroduction
- Quick Start
- Realm element attributes
- Example
- Additional Notes
Ntroduction
JaasrealmIs an implementation of the Tomcat 4Realm
Interface that authenticates users through the Java Authentication & Authorization Service (JAAS) framework, a Java package that is available as an optional package in Java 2 SDK 1.3 and is fully integrated as of SDK 1.4.
Using jaasrealm gives the developer the ability to combine practically any conceivable security realm with Tomcat's CMA.
Jaasrealm is prototype for Tomcat of the proposed JAAS-based J2EE Authentication Framework for J2EE v1.4, based on the JCP specification request 196 to enhance container-managed security and promote 'able gable' authentication mechanism whoisms whose implementations wocould be container-independent.
Based on the JAAS login module and principal (seejavax.security.auth.spi.LoginModule
Andjavax.security.Principal
), You can develop your own security mechanisms or wrap another third-party mechanisms for integration with the CMA as implemented by Tomcat.
Quick Start
To set up tomcat to use jaasrealm with your own JAAS login module, you will need to follow these steps:
- Write your own loginmodule, user and role classes based on JAAS (see the JAAS authentication tutorial and the JAAS login module developer's guide) to be managed by the JAAS login context (
javax.security.auth.login.LoginContext
). When developing your loginmodule, note that jaasrealm's built-inCallbackHandler
Only recognizesNameCallback
AndPasswordCallback
At present.
- Although not specified in JAAS, you shoshould create seperate classes to distinguish between users and roles, extending
javax.security.Principal
, So that Tomcat can tell which principals returned from your login module are users and which are roles (seeorg.apache.catalina.realm.JAASRealm
). Regardless, the first principal returned isAlwaysTreated as the user principal.
- Place the compiled classes on Tomcat's classpath
- Set up a login. config file for Java (see JAAS loginconfig file) and tell Tomcat where to find it by specifying its location to the JVM, for instance by setting the environment variable:
JAVA_OPTS=-DJAVA_OPTS=-Djava.security.auth.login.config==$CATALINA_HOME/conf/jaas.config
- Configure your security-constraints in your web. XML for the resources you want to protect
- Configure the jaasrealm module in your server. xml
- Restart Tomcat 4 if it is already running.
Realm element attributes
To configure jaasrealm as for Step 6 abve, you create<Realm>
Element and nest it in your$CATALINA_HOME/conf/server.xml
File within your<Engine>
Node. the following attributes are supported by this implementation:
Attribute |
Description |
className |
The fully qualified Java class name of this realm implementation. YouMustSpecify the value"org.apache.catalina.realm.MemoryRealm "Here. |
debug |
The level of debugging detail logged by this realm to the associated logger. Higher numbers generate more detailed output. If not specified, the default debugging detail level is zero (0 ). |
appName |
The name of the application as configured in your login configuration file (JAAS loginconfig ). |
userClassNames |
A comma-seperated List of the names of the classes that you have made for your userPrincipals . |
roleClassNames |
A comma-seperated List of the names of the classes that you have made for your rolePrincipals . |
useContextClassLoader |
Instructs jaasrealm to use the context class loader for loading the user-specifiedLoginModule Class and associatedPrincipal Classes. The default value istrue , Which is backwards-compatible with the way Tomcat 4 works. To load classes using the container's classloader, specifytrue . |
Example
Here is an example of how your server. xml snippet shocould look.
|
|
|
|
<Realm className="org.apache.catalina.realm.JAASRealm" appName="MyFooRealm" userClassNames="org.foobar.realm.FooUser" roleClassNames="org.foobar.realm.FooRole" debug="99"/> |
|
|
|
|
It is the responsibility of your login module to create and save user and role Objects representing principals for the user (javax.security.auth.Subject
). If your login module doesn't create a user object but also doesn't throw a login exception, then the Tomcat CMA will break and you will be left at the http: // localhost: 8080/MyApp/j_security_check URI or at some other unspecified location.
The flexibility of the JAAS approach is two-fold:
- You can carry out whatever processing you require behind the scenes in your own login module.
- You can plug in a completely different loginmodule by changing the configuration and restarting the server, without any code changes to your application.
Additional Notes
- When a user attempts to access a protected resource for the first time, Tomcat 4 will call
authenticate()
Method of thisRealm
. Thus, any changes you have made in the security mechanisms directly (new users, changed passwords or roles, etc.) will be immediately reflected.
- Once a user has been authenticated, the user (and his or her associated roles) are cached within Tomcat for the duration of the user's login. (For form-based authentication, that means until the session times out or is invalidated; for basic authentication, that means until the user closes their browser ). any changes to the security information for an already authenticated user willNotBe reflected until the next time that user logs on again.
- Debugging and exception messages logged by this
Realm
Will be recorded byLogger
That is associated with our surroundingContext
,Host
, OrEngine
. By default, the corresponding logger will create a log file in$CATALINA_HOME/logs
Directory.
- As with other
Realm
Implementations, digested passwords are supported if<Realm>
Element inserver.xml
Containsdigest
Attribute; jaasrealm'sCallbackHandler
Will digest the password prior to passing it back toLoginModule