Step 6: Prepare for Testing
- Step 6a: Place Your
LoginModuleand Application Code in JAR Files -
Place your
LoginModuleand 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
LoginModulecan also be placed anywhere you (and other clients) like. If theLoginModuleis fully trusted, it can be placed in the runtime environment'slib/ext(standard extension) directory.You will need to test the
LoginModulebeing located both in thelib/extdirectory and elsewhere because in one situation yourLoginModulewill 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
LoginModuleis placed in the runtime environment'slib/extdirectory, 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
LoginModuleis placed anywhere else, the permissions need to be granted, for example bygrantstatements in a policy file.Decide where you will store the
LoginModuleJAR 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
LoginModuleand Application JAR File Permissions -
If your
LoginModuleand/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
LoginModules usually associatePrincipals and credentials with an authenticated Subject, some types of permissions aLoginModulewill typically require are AuthPermissions with target names "modifyPrincipals", "modifyPublicCredentials", and "modifyPrivateCredentials".Here is a sample statement granting permissions to aLoginModulewhose code is inMyLM.jar. Such a statement could appear in a policy file. In this example, theMyLM.jarfile is assumed to be in the/localWorkdirectory.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
LoginModuleis always invoked within anAccessController.doPrivilegedcall, it should not have to calldoPrivilegeditself. If it does, it may inadvertently open up a security hole. For example, aLoginModulethat invokes the application-providedCallbackHandlerinside adoPrivilegedcall opens up a security hole by permitting the application'sCallbackHandlerto 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
LoginModulecan be used without requiring modifications to existing applications. Only the loginConfigurationneeds to be updated to indicate use of a newLoginModule.The default
Configurationimplementation 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
LoginModulefor an application, the configuration file might look like this:
whereAppName { com.ibm.auth.Module REQUIRED debug=true; };AppNameshould 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 theLoginContextconstructor.