You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@groovy.apache.org by GitBox <gi...@apache.org> on 2019/01/06 10:14:53 UTC

[GitHub] asfgit closed pull request #848: Run dependency management call as privileged action

asfgit closed pull request #848: Run dependency management call as privileged action
URL: https://github.com/apache/groovy/pull/848
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/src/main/groovy/groovy/grape/Grape.java b/src/main/groovy/groovy/grape/Grape.java
index 0bbe9eeeae..cfa08ad5ef 100644
--- a/src/main/groovy/groovy/grape/Grape.java
+++ b/src/main/groovy/groovy/grape/Grape.java
@@ -19,6 +19,8 @@
 package groovy.grape;
 
 import java.net.URI;
+import java.security.AccessController;
+import java.security.PrivilegedAction;
 import java.util.Collections;
 import java.util.List;
 import java.util.Map;
@@ -152,18 +154,27 @@ public static void grab(Map<String, Object> dependency) {
         }
     }
 
-    public static void grab(Map<String, Object> args, Map... dependencies) {
+    public static void grab(final Map<String, Object> args, final Map... dependencies) {
         if (enableGrapes) {
-            GrapeEngine instance = getInstance();
-            if (instance != null) {
-                if (!args.containsKey(AUTO_DOWNLOAD_SETTING)) {
-                    args.put(AUTO_DOWNLOAD_SETTING, enableAutoDownload);
-                }
-                if (!args.containsKey(DISABLE_CHECKSUMS_SETTING)) {
-                    args.put(DISABLE_CHECKSUMS_SETTING, disableChecksums);
+            AccessController.doPrivileged(new PrivilegedAction<Void>() {
+                @Override
+                public Void run() {
+                    GrapeEngine instance = getInstance();
+                    if (instance != null) {
+                        if (!args.containsKey(AUTO_DOWNLOAD_SETTING)) {
+                            args.put(AUTO_DOWNLOAD_SETTING, enableAutoDownload);
+                        }
+                        if (!args.containsKey(DISABLE_CHECKSUMS_SETTING)) {
+                            args.put(DISABLE_CHECKSUMS_SETTING, disableChecksums);
+                        }
+                        if (!args.containsKey(GrapeEngine.CALLEE_DEPTH)) {
+                            args.put(GrapeEngine.CALLEE_DEPTH, GrapeEngine.DEFAULT_CALLEE_DEPTH + 2);
+                        }
+                        instance.grab(args, dependencies);
+                    }
+                    return null;
                 }
-                instance.grab(args, dependencies);
-            }
+            });
         }
     }
 
@@ -185,7 +196,7 @@ public static void grab(Map<String, Object> args, Map... dependencies) {
     public static URI[] resolve(Map<String, Object> args, Map... dependencies) {
         return resolve(args, null, dependencies);
     }
-    
+
     public static URI[] resolve(Map<String, Object> args, List depsInfo, Map... dependencies) {
         URI[] uris = null;
         if (enableGrapes) {
@@ -222,7 +233,7 @@ public static void grab(Map<String, Object> args, Map... dependencies) {
         }
 
     }
-    
+
     public static void addResolver(Map<String, Object> args) {
         if (enableGrapes) {
             GrapeEngine instance = getInstance();
diff --git a/src/main/groovy/groovy/grape/GrapeEngine.java b/src/main/groovy/groovy/grape/GrapeEngine.java
index d98882fb2e..4465e5abf6 100644
--- a/src/main/groovy/groovy/grape/GrapeEngine.java
+++ b/src/main/groovy/groovy/grape/GrapeEngine.java
@@ -27,6 +27,10 @@
  */
 public interface GrapeEngine {
 
+    String CALLEE_DEPTH = "calleeDepth";
+
+    int DEFAULT_CALLEE_DEPTH = 3 ;
+
     Object grab(String endorsedModule);
 
     Object grab(Map args);
diff --git a/src/main/groovy/groovy/grape/GrapeIvy.groovy b/src/main/groovy/groovy/grape/GrapeIvy.groovy
index 3912e54bf3..d9f21a25b8 100644
--- a/src/main/groovy/groovy/grape/GrapeIvy.groovy
+++ b/src/main/groovy/groovy/grape/GrapeIvy.groovy
@@ -64,8 +64,6 @@ import java.util.zip.ZipFile
  */
 class GrapeIvy implements GrapeEngine {
 
-    static final int DEFAULT_DEPTH = 3
-
     private static final String METAINF_PREFIX = 'META-INF/services/'
     private static final String RUNNER_PROVIDER_CONFIG = GroovyRunner.class.getName()
 
@@ -252,7 +250,7 @@ class GrapeIvy implements GrapeEngine {
     @Override
     @CompileStatic
     grab(Map args) {
-        args.calleeDepth = args.calleeDepth?:DEFAULT_DEPTH + 1
+        args.calleeDepth = args.calleeDepth?:DEFAULT_CALLEE_DEPTH + 1
         return grab(args, args)
     }
 
@@ -267,7 +265,7 @@ class GrapeIvy implements GrapeEngine {
             loader = chooseClassLoader(
                 classLoader:args.remove('classLoader'),
                 refObject:args.remove('refObject'),
-                calleeDepth:args.calleeDepth?:DEFAULT_DEPTH,
+                calleeDepth:args.calleeDepth?:DEFAULT_CALLEE_DEPTH,
             )
 
             // check for non-fail null.
@@ -660,7 +658,7 @@ class GrapeIvy implements GrapeEngine {
         ClassLoader loader = chooseClassLoader(
                 classLoader: args.remove('classLoader'),
                 refObject: args.remove('refObject'),
-                calleeDepth: args.calleeDepth ?: DEFAULT_DEPTH,
+                calleeDepth: args.calleeDepth ?: DEFAULT_CALLEE_DEPTH,
         )
 
         // check for non-fail null.


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services