This is an automated email from the ASF dual-hosted git repository.

sunlan pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/groovy.git


The following commit(s) were added to refs/heads/master by this push:
     new 9018229  GROOVY-8949: Run dependency management call as privileged 
action(closes #848)
9018229 is described below

commit 9018229f2adf703e9ac51423b8934aafe62413de
Author: Dimitry Polivaev <dpoliv...@gmx.de>
AuthorDate: Tue Jan 1 15:48:14 2019 +0100

    GROOVY-8949: Run dependency management call as privileged action(closes 
#848)
---
 src/main/groovy/groovy/grape/Grape.java       | 35 ++++++++++++++++++---------
 src/main/groovy/groovy/grape/GrapeEngine.java |  4 +++
 src/main/groovy/groovy/grape/GrapeIvy.groovy  |  8 +++---
 3 files changed, 30 insertions(+), 17 deletions(-)

diff --git a/src/main/groovy/groovy/grape/Grape.java 
b/src/main/groovy/groovy/grape/Grape.java
index 0bbe9ee..cfa08ad 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 class Grape {
         }
     }
 
-    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 class Grape {
     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 class Grape {
         }
 
     }
-    
+
     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 d98882f..4465e5a 100644
--- a/src/main/groovy/groovy/grape/GrapeEngine.java
+++ b/src/main/groovy/groovy/grape/GrapeEngine.java
@@ -27,6 +27,10 @@ import java.util.Map;
  */
 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 efb8bf7..014bbdd 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.
@@ -610,7 +608,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.

Reply via email to