Java: Add notes about the security manager
This commit is contained in:
parent
458170e759
commit
b871c9eec0
10 changed files with 555 additions and 0 deletions
|
@ -0,0 +1,40 @@
|
|||
<?xml version='1.0' encoding='utf-8' ?>
|
||||
<!DOCTYPE programlisting PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN" "http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd" [
|
||||
]>
|
||||
<!-- Automatically generated file. Do not edit. -->
|
||||
<programlisting language="Java">
|
||||
interface Callback<T> {
|
||||
T call(boolean flag);
|
||||
}
|
||||
|
||||
class CallbackInvoker<T> {
|
||||
private final AccessControlContext context;
|
||||
Callback<T> callback;
|
||||
|
||||
CallbackInvoker(Callback<T> callback) {
|
||||
context = AccessController.getContext();
|
||||
this.callback = callback;
|
||||
}
|
||||
|
||||
public T invoke() {
|
||||
// Obtain increased privileges.
|
||||
return AccessController.doPrivileged(new PrivilegedAction<T>() {
|
||||
@Override
|
||||
public T run() {
|
||||
// This operation would fail without
|
||||
// additional privileges.
|
||||
final boolean flag = Boolean.getBoolean("some.property");
|
||||
|
||||
// Restore the original privileges.
|
||||
return AccessController.doPrivileged(
|
||||
new PrivilegedAction<T>() {
|
||||
@Override
|
||||
public T run() {
|
||||
return callback.call(flag);
|
||||
}
|
||||
}, context);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
</programlisting>
|
Loading…
Add table
Add a link
Reference in a new issue