doPrivileged...
methods on
AccessController
.
This interface must remain non-exported
from org.postgresql.pljava.internal
.
The reason, of course, is that the real methods on AccessController
end up getting called from these wrappers, and will therefore apply the
permissions granted to this module. As long as these methods are only
accessible within this module, that isn't a problem.
It would be great to develop this into an exportable API so user code
could benefit, but that would be a much trickier undertaking, with editing of
AccessControlContext
s to snag the correct caller's context, and
not for the faint of heart.
Each method here comes in a flavor accepting a
Checked.Supplier
, matching any lambda that returns a
reference type, and a flavor accepting a
Checked.Runnable
for void
lambdas, because
the compiler will not match those up with Supplier<Void>
.
Fuss no more with PrivilegedExceptionAction
and catching
PrivilegedActionException
: just pass any of these methods a lambda.
If the lambda throws a checked exception, so does the method. If the lambda
throws some checked exceptions, the method throws their least common
supertype, which is not as nice as throwing their union, and climbs all the
way up to Exception
if they are unrelated. But even so, you can now
simply catch it, rather than catching a PrivilegedActionException
and
having to unwrap it first.
-
Method Summary
Modifier and TypeMethodDescriptionstatic <E extends Exception>
voiddoPrivileged
(Checked.Runnable<E> op) static <E extends Exception>
voiddoPrivileged
(Checked.Runnable<E> op, AccessControlContext acc) static <E extends Exception>
voiddoPrivileged
(Checked.Runnable<E> op, AccessControlContext acc, Permission... perms) static <T,
E extends Exception>
TdoPrivileged
(Checked.Supplier<T, E> op) static <T,
E extends Exception>
TdoPrivileged
(Checked.Supplier<T, E> op, AccessControlContext acc) static <T,
E extends Exception>
TdoPrivileged
(Checked.Supplier<T, E> op, AccessControlContext acc, Permission... perms) static <E extends Exception>
voidstatic <E extends Exception>
voiddoPrivilegedWithCombiner
(Checked.Runnable<E> op, AccessControlContext acc, Permission... perms) static <T,
E extends Exception>
TdoPrivilegedWithCombiner
(Checked.Supplier<T, E> op) static <T,
E extends Exception>
TdoPrivilegedWithCombiner
(Checked.Supplier<T, E> op, AccessControlContext acc, Permission... perms)
-
Method Details
-
doPrivileged
- Throws:
E
-
doPrivileged
static <T,E extends Exception> T doPrivileged(Checked.Supplier<T, E> op, AccessControlContext acc) throws E- Throws:
E
-
doPrivileged
static <T,E extends Exception> T doPrivileged(Checked.Supplier<T, E> op, AccessControlContext acc, Permission... perms) throws E- Throws:
E
-
doPrivilegedWithCombiner
- Throws:
E
-
doPrivilegedWithCombiner
static <T,E extends Exception> T doPrivilegedWithCombiner(Checked.Supplier<T, E> op, AccessControlContext acc, Permission... perms) throws E- Throws:
E
-
doPrivileged
- Throws:
E
-
doPrivileged
static <E extends Exception> void doPrivileged(Checked.Runnable<E> op, AccessControlContext acc) throws E - Throws:
E
-
doPrivileged
static <E extends Exception> void doPrivileged(Checked.Runnable<E> op, AccessControlContext acc, Permission... perms) throws E - Throws:
E
-
doPrivilegedWithCombiner
- Throws:
E
-
doPrivilegedWithCombiner
static <E extends Exception> void doPrivilegedWithCombiner(Checked.Runnable<E> op, AccessControlContext acc, Permission... perms) throws E - Throws:
E
-