47 |
* And provides a <code>getContext()</code> method which gives the access |
* And provides a <code>getContext()</code> method which gives the access |
48 |
* control context of the current thread that can be used for checking |
* control context of the current thread that can be used for checking |
49 |
* permissions at a later time and/or in another thread. |
* permissions at a later time and/or in another thread. |
|
* <p> |
|
|
* XXX - Mostly a stub implementation at the moment. Needs native support |
|
|
* from the VM to function correctly. XXX - Do not forget to think about |
|
|
* how to handle <code>java.lang.reflect.Method.invoke()</code> on the |
|
|
* <code>doPrivileged()</code> methods. |
|
50 |
* |
* |
51 |
* @author Mark Wielaard (mark@klomp.org) |
* @author Mark Wielaard (mark@klomp.org) |
52 |
* @since 1.2 |
* @since 1.2 |
90 |
*/ |
*/ |
91 |
public static Object doPrivileged(PrivilegedAction action) |
public static Object doPrivileged(PrivilegedAction action) |
92 |
{ |
{ |
93 |
return action.run(); |
VMAccessController.pushContext(null); |
94 |
|
try |
95 |
|
{ |
96 |
|
return action.run(); |
97 |
|
} |
98 |
|
finally |
99 |
|
{ |
100 |
|
VMAccessController.popContext(); |
101 |
|
} |
102 |
} |
} |
103 |
|
|
104 |
/** |
/** |
116 |
* @return the result of the <code>action.run()</code> method. |
* @return the result of the <code>action.run()</code> method. |
117 |
*/ |
*/ |
118 |
public static Object doPrivileged(PrivilegedAction action, |
public static Object doPrivileged(PrivilegedAction action, |
119 |
AccessControlContext context) |
AccessControlContext context) |
120 |
{ |
{ |
121 |
VMAccessController.pushContext (context, action.getClass()); |
VMAccessController.pushContext(context); |
122 |
try |
try |
123 |
{ |
{ |
124 |
return action.run(); |
return action.run(); |
125 |
} |
} |
126 |
finally |
finally |
127 |
{ |
{ |
128 |
VMAccessController.popContext (action.getClass()); |
VMAccessController.popContext(); |
129 |
} |
} |
130 |
} |
} |
131 |
|
|
148 |
public static Object doPrivileged(PrivilegedExceptionAction action) |
public static Object doPrivileged(PrivilegedExceptionAction action) |
149 |
throws PrivilegedActionException |
throws PrivilegedActionException |
150 |
{ |
{ |
151 |
|
VMAccessController.pushContext(null); |
152 |
try |
try |
153 |
{ |
{ |
154 |
return action.run(); |
return action.run(); |
155 |
} |
} |
156 |
catch (Exception e) |
catch (Exception e) |
157 |
{ |
{ |
158 |
throw new PrivilegedActionException(e); |
throw new PrivilegedActionException(e); |
159 |
|
} |
160 |
|
finally |
161 |
|
{ |
162 |
|
VMAccessController.popContext(); |
163 |
} |
} |
164 |
} |
} |
165 |
|
|
182 |
* is thrown in the <code>run()</code> method. |
* is thrown in the <code>run()</code> method. |
183 |
*/ |
*/ |
184 |
public static Object doPrivileged(PrivilegedExceptionAction action, |
public static Object doPrivileged(PrivilegedExceptionAction action, |
185 |
AccessControlContext context) |
AccessControlContext context) |
186 |
throws PrivilegedActionException |
throws PrivilegedActionException |
187 |
{ |
{ |
188 |
VMAccessController.pushContext (context, action.getClass()); |
VMAccessController.pushContext(context); |
|
|
|
189 |
try |
try |
190 |
{ |
{ |
191 |
return action.run(); |
return action.run(); |
192 |
} |
} |
193 |
catch (Exception e) |
catch (Exception e) |
194 |
{ |
{ |
195 |
throw new PrivilegedActionException(e); |
throw new PrivilegedActionException(e); |
196 |
} |
} |
197 |
finally |
finally |
198 |
{ |
{ |
199 |
VMAccessController.popContext (action.getClass()); |
VMAccessController.popContext(); |
200 |
} |
} |
201 |
} |
} |
202 |
|
|