Step 6: Prepare for Testing
- Step 6a: Place Your
LoginModule
and Application Code in JAR Files -
Place your
LoginModule
and application code in separate JAR files, in preparation for referencing the JAR files in the policy in Step 6c. Here is a sample command for creating a JAR file:jar cvf <JAR file name> <list of classes, separated by spaces>
This command creates a JAR file with the specified name containing the specified classes.
For more information on the jar tool, see jar (for Solaris) (for Microsoft Windows).
- Step 6b: Decide Where to Store the JAR Files
-
The application can be stored essentially anywhere you like.
Your
LoginModule
can also be placed anywhere you (and other clients) like. If theLoginModule
is fully trusted, it can be placed in the runtime environment'slib/ext
(standard extension) directory.You will need to test the
LoginModule
being located both in thelib/ext
directory and elsewhere because in one situation yourLoginModule
will need to explicitly be granted permissions required for any security-sensitive operations it does, while in the other case such permissions are not needed.If your
LoginModule
is placed in the runtime environment'slib/ext
directory, it will be treated as an installed extension and no permissions need to be granted, since the default system policy file grants all permissions to installed extensions.If your
LoginModule
is placed anywhere else, the permissions need to be granted, for example bygrant
statements in a policy file.Decide where you will store the
LoginModule
JAR file for testing the case where it is not an installed extension. In the next step, you grant permissions to the JAR file, in the specified location. - Step 6c: Set
LoginModule
and Application JAR File Permissions -
If your
LoginModule
and/or application performs security-sensitive tasks that will trigger security checks (making network connections, reading or writing files on a local disk, etc), it will need to be granted the required permissions if it is not an installed extension (see Step 6b) and it is run while a security manager is installed.Since
LoginModule
s usually associatePrincipal
s and credentials with an authenticated Subject, some types of permissions aLoginModule
will typically require are AuthPermissions with target names "modifyPrincipals", "modifyPublicCredentials", and "modifyPrivateCredentials".Here is a sample statement granting permissions to aLoginModule
whose code is inMyLM.jar
. Such a statement could appear in a policy file. In this example, theMyLM.jar
file is assumed to be in the/localWork
directory.grant codeBase "file:/localWork/MyLM.jar" { permission javax.security.auth.AuthPermission "modifyPrincipals"; permission javax.security.auth.AuthPermission "modifyPublicCredentials"; permission javax.security.auth.AuthPermission "modifyPrivateCredentials"; };
Note: Since a
LoginModule
is always invoked within anAccessController.doPrivileged
call, it should not have to calldoPrivileged
itself. If it does, it may inadvertently open up a security hole. For example, aLoginModule
that invokes the application-providedCallbackHandler
inside adoPrivileged
call opens up a security hole by permitting the application'sCallbackHandler
to gain access to resources it would otherwise not have been able to access. - Step 6d: Create a Configuration Referencing the LoginModule
-
Because JAAS supports a pluggable authentication architecture, your new
LoginModule
can be used without requiring modifications to existing applications. Only the loginConfiguration
needs to be updated to indicate use of a newLoginModule
.The default
Configuration
implementation from Sun Microsystems reads configuration information from configuration files, as described in com.ibm.security.auth.login.ConfigFile.html.Create a configuration file to be used for testing. For example, to configure the previously-mentioned hypothetical IBM
LoginModule
for an application, the configuration file might look like this:
whereAppName { com.ibm.auth.Module REQUIRED debug=true; };
AppName
should be whatever name the application uses to refer to this entry in the login configuration file. The application specifies this name as the first argument to theLoginContext
constructor.