Configure app.policy files

Java 2 security uses several policy files to determine the granted permissions for each Java program. See the Dynamic policy article for the list of available policy files supported by WAS. The app.policy file is a default policy file shared by all of the WAS enterprise applications. The union of the permissions contained in the app.policy file, the server.policy file, the app.policy file, the application was.policy file and the permission specification of the ra.xml file are applied to the WAS enterprise application. The app.policy files are managed by configuration and file replication services.

Note that The Signed By and the Java Authentication and Authorization Service (JAAS) principal keywords are not supported in the app.policy file. However, the Signed By keyword is supported in the following files: java.policy, server.policy, and the client.policy files. The JAAS principal keyword is supported in a JAAS policy file when it is specified by the JVM system property, java.security.auth.policy. You can statically set the authorization policy files in java.security.auth.policy with auth.policy.url.n=URL where URL is the location of the authorization policy. If the default permissions for enterprise applications (the union of the permissions defined in the app.policy file, the server.policy file and the app.policy file) are enough, no action is required. The default app.policy file is used automatically. If a specific change is required to all of the enterprise applications in the cell, update the app.policy file. Syntax errors in the policy files cause start failures in the appservers. Edit these policy files carefully.

  1. Modify the app.policy file with the Policy Tool. Changes to the app.policy file are local for the node.

The default Java 2 security policies have been changed for the enterprise application.

 

Usage Scenario

Symbol Meaning
file:${application} Permissions apply to all resources within the application
file:${jars} Permissions apply to all utility Java archive (JAR) files within the application
file:${ejbComponent} Permissions apply to enterprise bean resources within the application
file:${webComponent} Permissions apply to Web resources within the application
file:${connectorComponent} Permissions apply to connector resources both within the application and within stand-alone connector resources.

There are five embedded symbols provided to specify the path and name for java.io.FilePermission. These symbols enable flexible permission specifications. The absolute file path is fixed after the installation of the application.

Symbol Meaning
${app.installed.path} Path where the application is installed
${was.module.path} Path where the module is installed
${current.cell.name} Current cell name
${current.node.name} Current node name
${current.server.name} Current server name

You cannot use the ${was.module.path} in the ${application} entry.

The app.policy file supplied by WAS resides at $WAS_HOME/config/cells/cell/nodes/node/app.policy, which contains the following default permissions...

Note that In the following code sample, the first two lines related to permission java.io.FilePermission were split into two lines each due to the width of the printed page.

grant codeBase "file:${application}" {
  // The following are required by Java mail
  permission java.io.FilePermission "${was.install.root}${/}java${/}
  jre${/}lib${/}ext${/}mail.jar", "read";
  permission java.io.FilePermission "${was.install.root}${/}java${/}
  jre${/}lib${/}ext${/}activation.jar", "read";
};

grant codeBase "file:${jars}" {
  permission java.net.SocketPermission "*", "connect";
  permission java.util.PropertyPermission "*", "read";
};

grant codeBase "file:${connectorComponent}" {
  permission java.net.SocketPermission "*", "connect";
  permission java.util.PropertyPermission "*", "read";
};
grant codeBase "file:${webComponent}" {
  permission java.io.FilePermission "${was.module.path}${/}-", "read, write";
  permission java.lang.RuntimePermission "loadLibrary.*";
  permission java.lang.RuntimePermission "queuePrintJob";
  permission java.net.SocketPermission "*", "connect";
  permission java.util.PropertyPermission "*", "read";
};

grant codeBase "file:${ejbComponent}" {
 permission java.lang.RuntimePermission "queuePrintJob";
 permission java.net.SocketPermission "*", "connect";
 permission java.util.PropertyPermission "*", "read";
};

If all of the WAS enterprise applications in a cell require permissions that are not defined as defaults in the app.policy file, the server.policy file and the app.policyfile, then update the app.policy file. The symptom of a missing permission is the exception, java.security.AccessControlException. The missing permission is listed in the exception data, for example, java.security.AccessControlException... access denied java.io.FilePermission(C:\WebSphere\AppServer\java\jre\lib\ext\mail.jar read).

When a Java program receives this exception and adding this permission is justified, add a permission to the server.policy file, for example:

grant codeBase "file:<user client installed location>" {   
permission java.io.FilePermission 
"C:\WebSphere\AppServer\java\jre\lib\ext\mail.jar", "read"; };

To decide whether to add a permission, refer to the article AccessControlException.

Restart all WAS enterprise applications to ensure that the updated app.policy file takes effect.