Author: pauls
Date: Fri Apr 13 21:07:49 2018
New Revision: 1829103

URL: http://svn.apache.org/viewvc?rev=1829103&view=rev
Log:
Add a method for getCanonicalPath and generic PrivilegedActivions to the 
SecureAction

Modified:
    
felix/trunk/osgi-r7/framework/src/main/java/org/apache/felix/framework/util/SecureAction.java

Modified: 
felix/trunk/osgi-r7/framework/src/main/java/org/apache/felix/framework/util/SecureAction.java
URL: 
http://svn.apache.org/viewvc/felix/trunk/osgi-r7/framework/src/main/java/org/apache/felix/framework/util/SecureAction.java?rev=1829103&r1=1829102&r2=1829103&view=diff
==============================================================================
--- 
felix/trunk/osgi-r7/framework/src/main/java/org/apache/felix/framework/util/SecureAction.java
 (original)
+++ 
felix/trunk/osgi-r7/framework/src/main/java/org/apache/felix/framework/util/SecureAction.java
 Fri Apr 13 21:07:49 2018
@@ -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;


Reply via email to