Add a method for getCanonicalPath and generic PrivilegedActivions to the SecureAction
@@ -1473,6 +1473,58 @@ public class SecureAction
}
}
+ public <T> T run(PrivilegedAction<T> action)
+ {
+ if (System.getSecurityManager() != null)
+ {
+ return AccessController.doPrivileged(action);
+ }
+ else
+ {
+ return action.run();
+ }
+ }
+
+ public <T> T run(PrivilegedExceptionAction<T> action) throws Exception
+ {
+ if (System.getSecurityManager() != null)
+ {
+ try
+ {
+ return AccessController.doPrivileged(action);
+ }
+ catch (PrivilegedActionException e)
+ {
+ throw e.getException();
+ }
+ }
+ else
+ {
+ return action.run();
+ }
+ }
+
+ public String getCanonicalPath(File dataFile) throws IOException
+ {
+ if (System.getSecurityManager() != null)
+ {
+ Actions actions = (Actions) m_actions.get();
+ actions.set(Actions.GET_CANONICAL_PATH, dataFile);
+ try
+ {
+ return (String) AccessController.doPrivileged(actions, m_acc);
+ }
+ catch (PrivilegedActionException e)
+ {
+ throw (IOException) e.getException();
+ }
+ }
+ else
+ {
+ return dataFile.getCanonicalPath();
+ }
+ }
+
private static class Actions implements PrivilegedExceptionAction
{
public static final int INITIALIZE_CONTEXT_ACTION = 0;
@@ -1532,6 +1584,7 @@ public class SecureAction
public static final int OPEN_JARFILE_ACTION = 54;
public static final int DELETE_FILEONEXIT_ACTION = 55;
public static final int INVOKE_WOVEN_CLASS_LISTENER = 56;
+ public static final int GET_CANONICAL_PATH = 57;
private int m_action = -1;
private Object m_arg1 = null;
@@ -1790,6 +1843,8 @@ public class SecureAction
((org.osgi.framework.hooks.weaving.WovenClassListener) arg1).modified(
(org.osgi.framework.hooks.weaving.WovenClass) arg2);
return null;
+ case GET_CANONICAL_PATH:
+ return ((File) arg1).getCanonicalPath();
}
return null;
