Permissions Utility
Tom Cellucci <[email protected]>
| Newsgroups | gmane.comp.java.sun.jini |
|---|---|
| Message-ID | <[email protected]> |
I've recently checked in a small utility that I thought could be useful
outside of my current project. The utility is designed to unobtrusively
sniff out the permissions required to run code under the Java security
model. It runs as a permissive security manager, but records all permission
checks it receives that are outside the normal policy (i.e., those that
would have thrown a SecurityException). When the JVM is terminated, the
utility generates a new policy file to the console, granting the permissions
that were recorded in the previous session.
The utility runs without making any changes to existing code, using the new
"agent" feature of Java 5. The required command line argument looks
something like:
"-javaagent:${ project.location}/components/bantam-tools/build/bantam-
tools.jar"
The output for a simple file read/write/delete program:
[java] Dec 17, 2006 9:56:16 AM
com.skillcorp.bantam.tools.security.permissions.SnifferSecurityManager<init>
[java] INFO: sniffing permissions for callers beginning with
com.skillcorp.bantam.tools.security.permissions.test.*
[java] Dec 17, 2006 9:56:16 AM
com.skillcorp.bantam.tools.security.permissions.test.PermissionsTestchangeFile
[java] INFO: opening file 'test.txt'
[java] Dec 17, 2006 9:56:16 AM
com.skillcorp.bantam.tools.security.permissions.test.PermissionsTestchangeFile
[java] INFO: deleting file 'test.txt'
[java] Dec 17, 2006 9:56:16 AM
com.skillcorp.bantam.tools.security.permissions.test.PermissionsTestchangeFile
[java] INFO: writing to file 'test.txt'
[java] Dec 17, 2006 9:56:16 AM
com.skillcorp.bantam.tools.security.permissions.test.PermissionsTestchangeFile
[java] INFO: test complete
[java] grant codebase
"file:/C:/workspaces/mayflowerClean/bantam.dev.java.net/components/bantam-tools/build/test/"
{
[java] permission java.io.FilePermission "test.txt", "delete";
[java] permission java.io.FilePermission "test.txt", "read";
[java] permission java.io.FilePermission "test.txt", "write";
[java] };
If you'd like to try it out, the agent is available at
bantam-tools.jar<http://bantam.dev.java.net/files/documents/5860/46485/bantam-tools.jar>,
and the source is available in bantam's CVS repository under
/components/bantam-tools. The source tree has an ant script to compile the
agent and run the example program.
-Tom
--------------------------------------------------------------------------
Getting Started: http://www.jini.org/wiki/Category:Getting_Started
Community Web Site: http://jini.org
jini-users Archive: http://archives.java.sun.com/archives/jini-users.html
Unsubscribing: email "signoff JINI-USERS" to [email protected]