From 3bbdef33d74cc08903582a7aad746c5263ae4764 Mon Sep 17 00:00:00 2001 From: Michael Bayne Date: Wed, 15 Dec 2004 02:15:02 +0000 Subject: [PATCH] Do our privileged business in PrivilegedAction wrappers which allows Java's magical security system to do the right thing (or so I think). git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@3274 542714f4-19e9-0310-aa3c-eee0fc999fb1 --- .../threerings/resource/ResourceManager.java | 31 ++++++++++++++----- 1 file changed, 24 insertions(+), 7 deletions(-) diff --git a/src/java/com/threerings/resource/ResourceManager.java b/src/java/com/threerings/resource/ResourceManager.java index 8045c8e3b..b84534209 100644 --- a/src/java/com/threerings/resource/ResourceManager.java +++ b/src/java/com/threerings/resource/ResourceManager.java @@ -40,6 +40,9 @@ import java.util.List; import java.util.Properties; import java.util.StringTokenizer; +import java.security.AccessController; +import java.security.PrivilegedAction; + import javax.imageio.stream.FileImageInputStream; import javax.imageio.stream.ImageInputStream; import javax.imageio.stream.MemoryCacheImageInputStream; @@ -173,9 +176,14 @@ public class ResourceManager _rootPath = resourceRoot; _loader = loader; - // set up a URL handler so that things can be loaded via urls with - // the 'resource' protocol - Handler.registerHandler(this); + // set up a URL handler so that things can be loaded via urls + // with the 'resource' protocol + AccessController.doPrivileged(new PrivilegedAction() { + public Object run () { + Handler.registerHandler(ResourceManager.this); + return null; + } + }); } /** @@ -378,8 +386,12 @@ public class ResourceManager } // if we didn't find anything, try the classloader - String rpath = PathUtil.appendPath(_rootPath, path); - in = _loader.getResourceAsStream(rpath); + final String rpath = PathUtil.appendPath(_rootPath, path); + in = (InputStream)AccessController.doPrivileged(new PrivilegedAction() { + public Object run () { + return _loader.getResourceAsStream(rpath); + } + }); if (in != null) { return in; } @@ -412,8 +424,13 @@ public class ResourceManager } // if we didn't find anything, try the classloader - String rpath = PathUtil.appendPath(_rootPath, path); - InputStream in = _loader.getResourceAsStream(rpath); + final String rpath = PathUtil.appendPath(_rootPath, path); + InputStream in = (InputStream) + AccessController.doPrivileged(new PrivilegedAction() { + public Object run () { + return _loader.getResourceAsStream(rpath); + } + }); if (in != null) { return new MemoryCacheImageInputStream(new BufferedInputStream(in)); }