You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by am...@apache.org on 2019/05/30 16:57:36 UTC

[cxf] branch master updated: DoPriv around File.exists()

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

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


The following commit(s) were added to refs/heads/master by this push:
     new 3a1f54d  DoPriv around File.exists()
3a1f54d is described below

commit 3a1f54d82c94f0b5527f8a0f164bf602227bd437
Author: Andy McCright <j....@gmail.com>
AuthorDate: Thu May 30 11:56:03 2019 -0500

    DoPriv around File.exists()
---
 .../org/apache/cxf/configuration/jsse/SSLUtils.java |  5 +++--
 .../main/java/org/apache/cxf/helpers/FileUtils.java | 21 ++++++++++++++++-----
 2 files changed, 19 insertions(+), 7 deletions(-)

diff --git a/core/src/main/java/org/apache/cxf/configuration/jsse/SSLUtils.java b/core/src/main/java/org/apache/cxf/configuration/jsse/SSLUtils.java
index 2e21448..86fcae1 100644
--- a/core/src/main/java/org/apache/cxf/configuration/jsse/SSLUtils.java
+++ b/core/src/main/java/org/apache/cxf/configuration/jsse/SSLUtils.java
@@ -50,6 +50,7 @@ import org.apache.cxf.common.classloader.ClassLoaderUtils;
 import org.apache.cxf.common.logging.LogUtils;
 import org.apache.cxf.common.util.SystemPropertyAction;
 import org.apache.cxf.configuration.security.FiltersType;
+import org.apache.cxf.helpers.FileUtils;
 import org.apache.cxf.resource.ResourceManager;
 
 
@@ -107,7 +108,7 @@ public final class SSLUtils {
         try {
             if (location != null) {
                 File file = new File(location);
-                if (file.exists()) {
+                if (FileUtils.exists(file)) {
                     is = Files.newInputStream(file.toPath());
                 } else {
                     is = getResourceAsStream(location);
@@ -152,7 +153,7 @@ public final class SSLUtils {
         try {
             if (location != null) {
                 File file = new File(location);
-                if (file.exists()) {
+                if (FileUtils.exists(file)) {
                     is = Files.newInputStream(file.toPath());
                 } else {
                     is = getResourceAsStream(location);
diff --git a/core/src/main/java/org/apache/cxf/helpers/FileUtils.java b/core/src/main/java/org/apache/cxf/helpers/FileUtils.java
index afef529..c203750 100644
--- a/core/src/main/java/org/apache/cxf/helpers/FileUtils.java
+++ b/core/src/main/java/org/apache/cxf/helpers/FileUtils.java
@@ -26,6 +26,8 @@ import java.io.InputStream;
 import java.io.InputStreamReader;
 import java.nio.file.Files;
 import java.nio.file.Path;
+import java.security.AccessController;
+import java.security.PrivilegedAction;
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.List;
@@ -59,7 +61,7 @@ public final class FileUtils {
         File file = new File(getDefaultTempDir(), name);
         boolean isValid = true;
         try {
-            if (file.exists()) {
+            if (exists(file)) {
                 return true;
             }
             if (file.createNewFile()) {
@@ -73,7 +75,7 @@ public final class FileUtils {
 
     public static synchronized File getDefaultTempDir() {
         if (defaultTempDir != null
-            && defaultTempDir.exists()) {
+            && exists(defaultTempDir)) {
             return defaultTempDir;
         }
 
@@ -137,7 +139,7 @@ public final class FileUtils {
     public static File createTmpDir(boolean addHook) {
         String s = SystemPropertyAction.getProperty("java.io.tmpdir");
         File checkExists = new File(s);
-        if (!checkExists.exists() || !checkExists.isDirectory()) {
+        if (!exists(checkExists) || !checkExists.isDirectory()) {
             throw new RuntimeException("The directory "
                                    + checkExists.getAbsolutePath()
                                    + " does not exist, please set java.io.tempdir"
@@ -197,7 +199,7 @@ public final class FileUtils {
                                     + "already exists with that name: " + dir.getAbsolutePath());
         }
 
-        if (!dir.exists()) {
+        if (!exists(dir)) {
             boolean result = doMkDirs(dir);
             if (!result) {
                 String msg = "Directory " + dir.getAbsolutePath()
@@ -389,9 +391,18 @@ public final class FileUtils {
     }
 
     public static List<String> readLines(File file) throws Exception {
-        if (!file.exists()) {
+        if (!exists(file)) {
             return Collections.emptyList();
         }
         return Files.readAllLines(file.toPath());
     }
+
+    public static boolean exists(File file) {
+        if (System.getSecurityManager() != null) {
+            return file.exists();
+        }
+        return AccessController.doPrivileged((PrivilegedAction<Boolean>) () -> {
+            return file.exists();
+        });
+    }
 }