|
From: Elias N. <eli...@us...> - 2005-05-30 16:21:13
|
Update of /cvsroot/java-game-lib/LWJGL/src/java/org/lwjgl In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv10617/src/java/org/lwjgl Modified Files: LWJGLUtil.java LinuxSysImplementation.java MacOSXSysImplementation.java Sys.java Log Message: Added AccessController.doPrivileged where needed Index: LinuxSysImplementation.java =================================================================== RCS file: /cvsroot/java-game-lib/LWJGL/src/java/org/lwjgl/LinuxSysImplementation.java,v retrieving revision 1.4 retrieving revision 1.5 diff -u -d -r1.4 -r1.5 --- LinuxSysImplementation.java 23 Feb 2005 11:22:14 -0000 1.4 +++ LinuxSysImplementation.java 30 May 2005 16:21:03 -0000 1.5 @@ -33,6 +33,10 @@ import java.io.IOException; +import java.security.AccessController; +import java.security.PrivilegedExceptionAction; +import java.security.PrivilegedActionException; + /** * $Id$ * @@ -44,17 +48,23 @@ java.awt.Toolkit.getDefaultToolkit(); // This will make sure libjawt.so is loaded } - public boolean openURL(String url) { + public boolean openURL(final String url) { // Linux may as well resort to pure Java hackery, as there's no Linux native way of doing it // right anyway. String[] browsers = {"firefox", "mozilla", "opera", "konqueror", "nautilus", "galeon", "netscape"}; for (int i = 0; i < browsers.length; i ++) { + final String browser = browsers[i]; try { - Runtime.getRuntime().exec(new String[] { browsers[i], url }); + AccessController.doPrivileged(new PrivilegedExceptionAction() { + public Object run() throws Exception { + Runtime.getRuntime().exec(new String[] { browser, url }); + return null; + } + }); return true; - } catch (IOException e) { + } catch (PrivilegedActionException e) { // Ignore e.printStackTrace(System.err); } Index: MacOSXSysImplementation.java =================================================================== RCS file: /cvsroot/java-game-lib/LWJGL/src/java/org/lwjgl/MacOSXSysImplementation.java,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -r1.2 -r1.3 --- MacOSXSysImplementation.java 20 Jan 2005 22:51:26 -0000 1.2 +++ MacOSXSysImplementation.java 30 May 2005 16:21:03 -0000 1.3 @@ -33,6 +33,9 @@ import java.lang.reflect.Method; +import java.security.AccessController; +import java.security.PrivilegedExceptionAction; + /** * $Id$ * @@ -42,11 +45,21 @@ class MacOSXSysImplementation extends J2SESysImplementation { public boolean openURL(String url) { try { - Class com_apple_eio_FileManager = Class.forName("com.apple.eio.FileManager"); - Method openURL_method = com_apple_eio_FileManager.getMethod("openURL", new Class[]{String.class}); + Method openURL_method = (Method)AccessController.doPrivileged(new PrivilegedExceptionAction() { + public Object run() throws Exception { + try { + Class com_apple_eio_FileManager = Class.forName("com.apple.eio.FileManager"); + return com_apple_eio_FileManager.getMethod("openURL", new Class[]{String.class}); + } catch (Exception e) { + LWJGLUtil.log("Exception occurred while trying to invoke browser: " + e); + return null; + } + } + }); openURL_method.invoke(null, new Object[]{url}); return true; } catch (Exception e) { + LWJGLUtil.log("Exception occurred while trying to invoke browser: " + e); return false; } } Index: LWJGLUtil.java =================================================================== RCS file: /cvsroot/java-game-lib/LWJGL/src/java/org/lwjgl/LWJGLUtil.java,v retrieving revision 1.5 retrieving revision 1.6 diff -u -d -r1.5 -r1.6 --- LWJGLUtil.java 12 May 2005 07:47:06 -0000 1.5 +++ LWJGLUtil.java 30 May 2005 16:21:03 -0000 1.6 @@ -37,6 +37,11 @@ import java.util.List; import java.util.StringTokenizer; +import java.security.AccessController; +import java.security.PrivilegedAction; +import java.security.PrivilegedActionException; +import java.security.PrivilegedExceptionAction; + /** * $Id$ * <p> @@ -52,8 +57,8 @@ public static final int PLATFORM_WINDOWS = 3; /** Debug flag. */ - public static final boolean DEBUG = Boolean.getBoolean("org.lwjgl.util.Debug"); - + public static final boolean DEBUG = getPrivilegedBoolean("org.lwjgl.util.Debug"); + /** * Get the current platform */ @@ -102,15 +107,15 @@ throw new LWJGLException("Unknown platform: " + getPlatform()); } - String classloader_path = LWJGLUtil.getPathFromClassLoader(libname, classloader); + String classloader_path = getPathFromClassLoader(libname, classloader); if (classloader_path != null) { - LWJGLUtil.log("getPathFromClassLoader: Path found: " + classloader_path); + log("getPathFromClassLoader: Path found: " + classloader_path); possible_paths.add(classloader_path); } - String lwjgl_classloader_path = LWJGLUtil.getPathFromClassLoader("lwjgl", classloader); + String lwjgl_classloader_path = getPathFromClassLoader("lwjgl", classloader); if (lwjgl_classloader_path != null) { - LWJGLUtil.log("getPathFromClassLoader: Path found: " + lwjgl_classloader_path); + log("getPathFromClassLoader: Path found: " + lwjgl_classloader_path); possible_paths.add(lwjgl_classloader_path.substring(0, lwjgl_classloader_path.lastIndexOf(File.separator)) + File.separator + platform_lib_name); } @@ -119,7 +124,12 @@ possible_paths.add(platform_lib_name); // Add all possible paths from java.library.path - StringTokenizer st = new StringTokenizer(System.getProperty("java.library.path"), File.pathSeparator); + String java_library_path = (String)AccessController.doPrivileged(new PrivilegedAction() { + public Object run() { + return System.getProperty("java.library.path"); + } + }); + StringTokenizer st = new StringTokenizer(java_library_path, File.pathSeparator); while (st.hasMoreTokens()) { String path = st.nextToken(); possible_paths.add(path + File.separator + platform_lib_name); @@ -145,32 +155,51 @@ */ public static String getPathFromClassLoader(String libname, ClassLoader classloader) { try { - LWJGLUtil.log("getPathFromClassLoader: searching for: " + libname); + log("getPathFromClassLoader: searching for: " + libname); Object o = classloader; Class c = o.getClass(); while (c != null) { + final Class clazz = c; try { - Method findLibrary = c.getDeclaredMethod("findLibrary", new Class[] { String.class}); - findLibrary.setAccessible(true); + Method findLibrary = (Method)AccessController.doPrivileged(new PrivilegedExceptionAction() { + public Object run() throws Exception { + Method m = clazz.getDeclaredMethod("findLibrary", new Class[]{String.class}); + m.setAccessible(true); + return m; + } + }); Object[] arguments = new Object[] {libname}; - return (String) findLibrary.invoke(o, arguments); - } catch (NoSuchMethodException e) { + return (String)findLibrary.invoke(o, arguments); + } catch (PrivilegedActionException e) { c = c.getSuperclass(); } } } catch (Exception e) { - LWJGLUtil.log("Failure locating " + e + " using classloader:" + e); + log("Failure locating " + e + " using classloader:" + e); } return null; } /** + * Gets a boolean property as a privileged action. Helper method + * for native. + */ + private static boolean getPrivilegedBoolean(final String property_name) { + Boolean value = (Boolean)AccessController.doPrivileged(new PrivilegedAction() { + public Object run() { + return new Boolean(Boolean.getBoolean(property_name)); + } + }); + return value.booleanValue(); + } + + /** * Prints the given message to System.err if DEBUG is true. * * @param msg Message to print */ public static void log(String msg) { - if (LWJGLUtil.DEBUG) { + if (DEBUG) { System.err.println(msg); } } Index: Sys.java =================================================================== RCS file: /cvsroot/java-game-lib/LWJGL/src/java/org/lwjgl/Sys.java,v retrieving revision 1.86 retrieving revision 1.87 diff -u -d -r1.86 -r1.87 --- Sys.java 18 May 2005 21:01:15 -0000 1.86 +++ Sys.java 30 May 2005 16:21:03 -0000 1.87 @@ -37,6 +37,10 @@ import org.lwjgl.input.Mouse; +import java.security.AccessController; +import java.security.PrivilegedAction; +import java.security.PrivilegedExceptionAction; + /** * $Id$ * <p> @@ -58,7 +62,12 @@ static { implementation = createImplementation(); - System.loadLibrary(LIBRARY_NAME); + AccessController.doPrivileged(new PrivilegedAction() { + public Object run() { + System.loadLibrary(LIBRARY_NAME); + return null; + } + }); String native_version = implementation.getNativeLibraryVersion(); if (!native_version.equals(VERSION)) throw new LinkageError("Version mismatch: jar version is '" + VERSION + @@ -176,11 +185,19 @@ // Attempt to use Webstart if we have it available try { // Lookup the javax.jnlp.BasicService object - Class serviceManagerClass = Class.forName("javax.jnlp.ServiceManager"); - Method lookupMethod = serviceManagerClass.getMethod("lookup", new Class[] {String.class}); + final Class serviceManagerClass = Class.forName("javax.jnlp.ServiceManager"); + Method lookupMethod = (Method)AccessController.doPrivileged(new PrivilegedExceptionAction() { + public Object run() throws Exception { + return serviceManagerClass.getMethod("lookup", new Class[] {String.class}); + } + }); Object basicService = lookupMethod.invoke(serviceManagerClass, new Object[] {"javax.jnlp.BasicService"}); - Class basicServiceClass = Class.forName("javax.jnlp.BasicService"); - Method showDocumentMethod = basicServiceClass.getMethod("showDocument", new Class[] {URL.class}); + final Class basicServiceClass = Class.forName("javax.jnlp.BasicService"); + Method showDocumentMethod = (Method)AccessController.doPrivileged(new PrivilegedExceptionAction() { + public Object run() throws Exception { + return basicServiceClass.getMethod("showDocument", new Class[] {URL.class}); + } + }); try { Boolean ret = (Boolean) showDocumentMethod.invoke(basicService, new Object[] {new URL(url)}); return ret.booleanValue(); |