Skip to content

Commit

Permalink
Add a method for getCanonicalPath and generic PrivilegedActivions to …
Browse files Browse the repository at this point in the history
…the SecureAction

git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@1829103 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
karlpauls committed Apr 13, 2018
1 parent a51c356 commit 3b1e849
Showing 1 changed file with 55 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1473,6 +1473,58 @@ public void invokeWovenClassListener(
}
}

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;
Expand Down Expand Up @@ -1532,6 +1584,7 @@ private static class Actions implements PrivilegedExceptionAction
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;
Expand Down Expand Up @@ -1790,6 +1843,8 @@ public Object run() throws Exception
((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;
Expand Down

0 comments on commit 3b1e849

Please sign in to comment.