1 | Here is what the usage of privileged code looks like. Note the use of Java's inner classes capability:(If you are using an anonymous inner class, any local variables you access must be final to make JAVA language looks like having closures.) |
2 | somemethod() { |
3 | <normal code> |
4 | AccessController.doPrivileged (new PrivilegedAction() |
5 | { |
6 | public Object run() |
7 | { <insert dangerous code here> return null; } |
8 | }); |
9 | <more normal code> |
10 | } |