diff options
author | Sven Gothel <[email protected]> | 2023-01-14 21:29:29 +0100 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2023-01-14 21:29:29 +0100 |
commit | 1396c3ca6fc675dcf4bdea708c8a8c89d481e3b8 (patch) | |
tree | aab2100371d332f86ffe2b86a906565fdb2576e2 /src/java/com | |
parent | 8edb09f4851a713b0e9817b4d2f081e0de86eaf3 (diff) |
Replace AccessController.doPrivileged() w/ SecurityUtil.doPrivileged()
Diffstat (limited to 'src/java/com')
11 files changed, 45 insertions, 29 deletions
diff --git a/src/java/com/jogamp/common/jvm/JNILibLoaderBase.java b/src/java/com/jogamp/common/jvm/JNILibLoaderBase.java index eee65d8..7859d2e 100644 --- a/src/java/com/jogamp/common/jvm/JNILibLoaderBase.java +++ b/src/java/com/jogamp/common/jvm/JNILibLoaderBase.java @@ -44,7 +44,6 @@ import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.net.URISyntaxException; import java.net.URL; -import java.security.AccessController; import java.security.PrivilegedAction; import java.util.Arrays; import java.util.HashSet; @@ -56,6 +55,7 @@ import com.jogamp.common.net.Uri; import com.jogamp.common.os.NativeLibrary; import com.jogamp.common.util.JarUtil; import com.jogamp.common.util.PropertyAccess; +import com.jogamp.common.util.SecurityUtil; import com.jogamp.common.util.cache.TempJarCache; import jogamp.common.Debug; @@ -512,7 +512,7 @@ public class JNILibLoaderBase { final String sunAppletLauncherProperty = "sun.jnlp.applet.launcher"; final String sunAppletLauncherClassName = "org.jdesktop.applet.util.JNLPAppletLauncher"; - final Method loadLibraryMethod = AccessController.doPrivileged(new PrivilegedAction<Method>() { + final Method loadLibraryMethod = SecurityUtil.doPrivileged(new PrivilegedAction<Method>() { @Override public Method run() { // FIXME: remove diff --git a/src/java/com/jogamp/common/net/GenericURLStreamHandlerFactory.java b/src/java/com/jogamp/common/net/GenericURLStreamHandlerFactory.java index 185142f..9b39657 100644 --- a/src/java/com/jogamp/common/net/GenericURLStreamHandlerFactory.java +++ b/src/java/com/jogamp/common/net/GenericURLStreamHandlerFactory.java @@ -3,11 +3,12 @@ package com.jogamp.common.net; import java.net.URL; import java.net.URLStreamHandler; import java.net.URLStreamHandlerFactory; -import java.security.AccessController; import java.security.PrivilegedAction; import java.util.HashMap; import java.util.Map; +import com.jogamp.common.util.SecurityUtil; + public class GenericURLStreamHandlerFactory implements URLStreamHandlerFactory { private static GenericURLStreamHandlerFactory factory = null; @@ -48,7 +49,7 @@ public class GenericURLStreamHandlerFactory implements URLStreamHandlerFactory { */ public synchronized static GenericURLStreamHandlerFactory register() { if(null == factory) { - factory = AccessController.doPrivileged(new PrivilegedAction<GenericURLStreamHandlerFactory>() { + factory = SecurityUtil.doPrivileged(new PrivilegedAction<GenericURLStreamHandlerFactory>() { @Override public GenericURLStreamHandlerFactory run() { boolean ok = false; diff --git a/src/java/com/jogamp/common/nio/Buffers.java b/src/java/com/jogamp/common/nio/Buffers.java index 875163e..6510f34 100644 --- a/src/java/com/jogamp/common/nio/Buffers.java +++ b/src/java/com/jogamp/common/nio/Buffers.java @@ -50,11 +50,11 @@ import java.nio.FloatBuffer; import java.nio.IntBuffer; import java.nio.LongBuffer; import java.nio.ShortBuffer; -import java.security.AccessController; import java.security.PrivilegedAction; import com.jogamp.common.ExceptionUtils; import com.jogamp.common.util.ReflectionUtil; +import com.jogamp.common.util.SecurityUtil; import com.jogamp.common.util.UnsafeUtil; import com.jogamp.common.util.ValueConv; @@ -1177,7 +1177,7 @@ public class Buffers { final Method[] _mbbCleaner = { null }; final Method[] _cClean = { null }; final boolean hasCleaner; - if( AccessController.doPrivileged(new PrivilegedAction<Boolean>() { + if( SecurityUtil.doPrivileged(new PrivilegedAction<Boolean>() { @Override public Boolean run() { try { diff --git a/src/java/com/jogamp/common/os/NativeLibrary.java b/src/java/com/jogamp/common/os/NativeLibrary.java index 2a42bed..aa53502 100644 --- a/src/java/com/jogamp/common/os/NativeLibrary.java +++ b/src/java/com/jogamp/common/os/NativeLibrary.java @@ -43,7 +43,6 @@ package com.jogamp.common.os; import java.io.File; import java.lang.reflect.Method; import java.net.URISyntaxException; -import java.security.AccessController; import java.security.PrivilegedAction; import java.util.ArrayList; import java.util.Iterator; @@ -59,6 +58,7 @@ import jogamp.common.os.WindowsDynamicLinkerImpl; import com.jogamp.common.ExceptionUtils; import com.jogamp.common.util.IOUtil; +import com.jogamp.common.util.SecurityUtil; import com.jogamp.common.util.cache.TempJarCache; /** Provides low-level, relatively platform-independent access to @@ -453,7 +453,7 @@ public final class NativeLibrary implements DynamicLookupHelper { // Add entries from java.library.path final String[] javaLibraryPaths = - AccessController.doPrivileged(new PrivilegedAction<String[]>() { + SecurityUtil.doPrivileged(new PrivilegedAction<String[]>() { @Override public String[] run() { int count = 0; @@ -495,7 +495,7 @@ public final class NativeLibrary implements DynamicLookupHelper { // Add current working directory final String userDir = - AccessController.doPrivileged(new PrivilegedAction<String>() { + SecurityUtil.doPrivileged(new PrivilegedAction<String>() { @Override public String run() { return System.getProperty("user.dir"); @@ -616,7 +616,7 @@ public final class NativeLibrary implements DynamicLookupHelper { return null; } if (!initializedFindLibraryMethod) { - AccessController.doPrivileged(new PrivilegedAction<Object>() { + SecurityUtil.doPrivileged(new PrivilegedAction<Object>() { @Override public Object run() { try { @@ -633,7 +633,7 @@ public final class NativeLibrary implements DynamicLookupHelper { } if (findLibraryMethod != null) { try { - return AccessController.doPrivileged(new PrivilegedAction<String>() { + return SecurityUtil.doPrivileged(new PrivilegedAction<String>() { @Override public String run() { try { diff --git a/src/java/com/jogamp/common/os/Platform.java b/src/java/com/jogamp/common/os/Platform.java index ca3d60b..e6821ba 100644 --- a/src/java/com/jogamp/common/os/Platform.java +++ b/src/java/com/jogamp/common/os/Platform.java @@ -28,7 +28,6 @@ package com.jogamp.common.os; -import java.security.AccessController; import java.security.PrivilegedAction; import java.util.concurrent.TimeUnit; @@ -37,6 +36,7 @@ import com.jogamp.common.net.Uri; import com.jogamp.common.util.JarUtil; import com.jogamp.common.util.PropertyAccess; import com.jogamp.common.util.ReflectionUtil; +import com.jogamp.common.util.SecurityUtil; import com.jogamp.common.util.VersionNumber; import com.jogamp.common.util.cache.TempJarCache; @@ -287,7 +287,7 @@ public class Platform extends PlatformPropsImpl { final boolean[] _USE_TEMP_JAR_CACHE = new boolean[] { false }; final boolean[] _AWT_AVAILABLE = new boolean[] { false }; - AccessController.doPrivileged(new PrivilegedAction<Object>() { + SecurityUtil.doPrivileged(new PrivilegedAction<Object>() { @Override public Object run() { diff --git a/src/java/com/jogamp/common/util/IOUtil.java b/src/java/com/jogamp/common/util/IOUtil.java index 380cb00..045525c 100644 --- a/src/java/com/jogamp/common/util/IOUtil.java +++ b/src/java/com/jogamp/common/util/IOUtil.java @@ -48,7 +48,6 @@ import java.net.URISyntaxException; import java.net.URL; import java.net.URLConnection; import java.nio.ByteBuffer; -import java.security.AccessController; import java.security.PrivilegedAction; import java.util.ArrayList; import java.util.List; @@ -79,7 +78,7 @@ public class IOUtil { static { final boolean _props[] = { false, false, false, false, false, false }; - final Method[] res = AccessController.doPrivileged(new PrivilegedAction<Method[]>() { + final Method[] res = SecurityUtil.doPrivileged(new PrivilegedAction<Method[]>() { @Override public Method[] run() { final Method[] res = new Method[] { null, null }; diff --git a/src/java/com/jogamp/common/util/IntIntHashMap.java b/src/java/com/jogamp/common/util/IntIntHashMap.java index f78b1e0..d74b79c 100644 --- a/src/java/com/jogamp/common/util/IntIntHashMap.java +++ b/src/java/com/jogamp/common/util/IntIntHashMap.java @@ -34,7 +34,6 @@ package com.jogamp.common.util; import com.jogamp.common.JogampRuntimeException; import java.lang.reflect.Constructor; import java.lang.reflect.Method; -import java.security.AccessController; import java.security.PrivilegedAction; import java.util.ArrayList; import java.util.Arrays; @@ -84,7 +83,7 @@ public class /*name*/IntIntHashMap/*name*/ implements Cloneable, isPrimitive = valueClazz.isPrimitive(); if(!isPrimitive) { - final EntryCM cm = AccessController.doPrivileged(new PrivilegedAction<EntryCM>() { + final EntryCM cm = SecurityUtil.doPrivileged(new PrivilegedAction<EntryCM>() { @Override @SuppressWarnings("unchecked") public EntryCM run() { @@ -502,7 +501,7 @@ public class /*name*/IntIntHashMap/*name*/ implements Cloneable, private static Method getCloneMethod(final Object obj) { final Class<?> clazz = obj.getClass(); - return AccessController.doPrivileged(new PrivilegedAction<Method>() { + return SecurityUtil.doPrivileged(new PrivilegedAction<Method>() { @Override public Method run() { try { diff --git a/src/java/com/jogamp/common/util/PropertyAccess.java b/src/java/com/jogamp/common/util/PropertyAccess.java index b6e9bdd..6dd550b 100644 --- a/src/java/com/jogamp/common/util/PropertyAccess.java +++ b/src/java/com/jogamp/common/util/PropertyAccess.java @@ -175,7 +175,7 @@ public class PropertyAccess { } private static final String getTrustedPropKey(final String propertyKey) { - return AccessController.doPrivileged(new PrivilegedAction<String>() { + return SecurityUtil.doPrivileged(new PrivilegedAction<String>() { @Override public String run() { try { diff --git a/src/java/com/jogamp/common/util/SecurityUtil.java b/src/java/com/jogamp/common/util/SecurityUtil.java index 1b8b7c2..9591f70 100644 --- a/src/java/com/jogamp/common/util/SecurityUtil.java +++ b/src/java/com/jogamp/common/util/SecurityUtil.java @@ -27,7 +27,6 @@ */ package com.jogamp.common.util; -import java.security.AccessController; import java.security.AllPermission; import java.security.CodeSource; import java.security.Permission; @@ -36,18 +35,38 @@ import java.security.ProtectionDomain; import java.security.cert.Certificate; public class SecurityUtil { + @SuppressWarnings("removal") private static final SecurityManager securityManager; private static final Permission allPermissions; private static final boolean DEBUG = false; + /** + * Deprecated call to {@link System#getSecurityManager()} w/o warnings. + */ + @SuppressWarnings({ "deprecation", "removal" }) + public static final SecurityManager getSecurityManager() { + return System.getSecurityManager(); + } + + /** + * Deprecated call to {@link java.security.AccessController#doPrivileged(PrivilegedAction)} w/o warnings. + * @param <T> + * @param o + * @return + */ + @SuppressWarnings({ "deprecation", "removal" }) + public static <T> T doPrivileged(final PrivilegedAction<T> o) { + return java.security.AccessController.doPrivileged( o ); + } + static { allPermissions = new AllPermission(); - securityManager = System.getSecurityManager(); + securityManager = getSecurityManager(); if( DEBUG ) { final boolean hasAllPermissions; { - final ProtectionDomain insecPD = AccessController.doPrivileged(new PrivilegedAction<ProtectionDomain>() { + final ProtectionDomain insecPD = doPrivileged(new PrivilegedAction<ProtectionDomain>() { @Override public ProtectionDomain run() { return SecurityUtil.class.getProtectionDomain(); @@ -64,7 +83,7 @@ public class SecurityUtil { System.err.println("SecurityUtil: Has SecurityManager: "+ ( null != securityManager ) ) ; System.err.println("SecurityUtil: Has AllPermissions: "+hasAllPermissions); - final Certificate[] certs = AccessController.doPrivileged(new PrivilegedAction<Certificate[]>() { + final Certificate[] certs = doPrivileged(new PrivilegedAction<Certificate[]>() { @Override public Certificate[] run() { return getCerts(SecurityUtil.class); diff --git a/src/java/com/jogamp/common/util/UnsafeUtil.java b/src/java/com/jogamp/common/util/UnsafeUtil.java index 6fde3fa..d1b2dd8 100644 --- a/src/java/com/jogamp/common/util/UnsafeUtil.java +++ b/src/java/com/jogamp/common/util/UnsafeUtil.java @@ -31,7 +31,6 @@ import java.lang.reflect.Field; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.nio.ByteBuffer; -import java.security.AccessController; import java.security.PrivilegedAction; import com.jogamp.common.ExceptionUtils; @@ -73,7 +72,7 @@ public class UnsafeUtil { final Class<?>[] _illegalAccessLoggerClass = { null }; final Long[] _loggerOffset = { null }; - AccessController.doPrivileged(new PrivilegedAction<Object>() { + SecurityUtil.doPrivileged(new PrivilegedAction<Object>() { @Override public Object run() { Class<?> unsafeClass = null; @@ -172,7 +171,7 @@ public class UnsafeUtil { /** * Issue the given user {@code action} while {@code jdk.internal.module.IllegalAcessLogger}'s {@code logger} has been temporarily disabled. * <p> - * The caller shall place this call into their own {@link AccessController#doPrivileged(PrivilegedAction)} block. + * The caller shall place this call into their own {@link SecurityUtil#doPrivileged(PrivilegedAction)} block. * </p> * <p> * In case the runtime is not {@link PlatformPropsImpl#JAVA_9} or the logger is not accessible or disabling caused an exception, diff --git a/src/java/com/jogamp/gluegen/runtime/ProcAddressTable.java b/src/java/com/jogamp/gluegen/runtime/ProcAddressTable.java index 03ed5c1..2ced962 100644 --- a/src/java/com/jogamp/gluegen/runtime/ProcAddressTable.java +++ b/src/java/com/jogamp/gluegen/runtime/ProcAddressTable.java @@ -46,7 +46,6 @@ import java.io.IOException; import java.io.PrintStream; import java.lang.reflect.AccessibleObject; import java.lang.reflect.Field; -import java.security.AccessController; import java.security.PrivilegedAction; import java.util.Iterator; import java.util.LinkedHashSet; @@ -89,7 +88,7 @@ public abstract class ProcAddressTable { private final FunctionAddressResolver resolver; static { - AccessController.doPrivileged(new PrivilegedAction<Object>() { + SecurityUtil.doPrivileged(new PrivilegedAction<Object>() { @Override public Object run() { DEBUG = (System.getProperty("jogamp.debug.ProcAddressHelper") != null); @@ -207,7 +206,7 @@ public abstract class ProcAddressTable { * </p> */ private final Field fieldForFunctionInSec(final String name) throws IllegalArgumentException { - return AccessController.doPrivileged(new PrivilegedAction<Field>() { + return SecurityUtil.doPrivileged(new PrivilegedAction<Field>() { @Override public Field run() { try { |