Patch: PrivilegedAction helper classes
Bryce McKinlay
mckinlay@redhat.com
Sun Jul 25 11:58:00 GMT 2004
This patch adds two classes which are implementations of
PrivilagedAction to be used for AccessController.doPrivilagedCalls:
GetPropertyAction and SetAccessibleAction, and updates some callers to
use them.
The idea is that these give us a) much cleaner syntax to make privileged
called, compared with anonymous class instantiations; and b) allow us to
reuse a single PrivilegedAction implementation across multiple
privileged calls, which reduces overhead.
For example, where we previously had something like:
String prop = (String) AccessController.doPrivileged(new
PrivilegedAction()
{
public Object run()
{
return System.getProperty("foo.bar");
}
};
Can now be written as:
String prop = (String) AccessController.doPrivileged(new
GetPropertyAction("foo.bar"));
Please use these new classes when adding new doPrivileged() calls, and
consider adding new ones for security-checked calls that are likely to
be frequently used within the runtime. We also need to be prudent when
adding such calls to ensure that the overhead added by implementing the
security model remains low. For example, System.getProperty() calls
should be moved to static initializers wherever possible, and where
doPrivilaged() calls are likely to be made frequently, consider caching
PrivilegedAction objects in local or static variables where it is safe
to do so (eg: in a synchronized block or where instances of the object
are not expected to be thread-safe).
Regards
Bryce
-------------- next part --------------
A non-text attachment was scrubbed...
Name: libjava-privilegedaction.patch
Type: text/x-patch
Size: 13634 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/java-patches/attachments/20040725/f23b1b0c/attachment.bin>
More information about the Java-patches
mailing list