diff options
author | Sven Gothel <[email protected]> | 2023-01-15 03:14:29 +0100 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2023-01-15 03:14:29 +0100 |
commit | c965bcf2b8cce8f81e2abc64b8960b653ddf5c00 (patch) | |
tree | 082d34aac719545954e8e83350aa3addd398276f | |
parent | 32c3fbccac055b3fc878f53dfb385d00d6789c7d (diff) |
SecurityUtil: Skip System's SecurityManager action for getSecurityManager() and doPrivileged() for Java17+
-rw-r--r-- | src/java/com/jogamp/common/util/SecurityUtil.java | 38 |
1 files changed, 31 insertions, 7 deletions
diff --git a/src/java/com/jogamp/common/util/SecurityUtil.java b/src/java/com/jogamp/common/util/SecurityUtil.java index 9591f70..6d5b639 100644 --- a/src/java/com/jogamp/common/util/SecurityUtil.java +++ b/src/java/com/jogamp/common/util/SecurityUtil.java @@ -34,6 +34,8 @@ import java.security.PrivilegedAction; import java.security.ProtectionDomain; import java.security.cert.Certificate; +import jogamp.common.os.PlatformPropsImpl; + public class SecurityUtil { @SuppressWarnings("removal") private static final SecurityManager securityManager; @@ -41,22 +43,44 @@ public class SecurityUtil { private static final boolean DEBUG = false; /** - * Deprecated call to {@link System#getSecurityManager()} w/o warnings. + * Call wrapper for {@link System#getSecurityManager()}. + * <p> + * {@link System#getSecurityManager()} is deprecated + * since Java 17 (JEP 411) and earmarked to be removed.<br/> + * </p> + * <p> + * On a Java 17 machine, this method will simply return null. + * </p> */ @SuppressWarnings({ "deprecation", "removal" }) public static final SecurityManager getSecurityManager() { - return System.getSecurityManager(); + if( PlatformPropsImpl.JAVA_17 ) { + return null; + } else { + return System.getSecurityManager(); + } } /** - * Deprecated call to {@link java.security.AccessController#doPrivileged(PrivilegedAction)} w/o warnings. - * @param <T> - * @param o - * @return + * Call wrapper for {@link java.security.AccessController#doPrivileged(PrivilegedAction)}. + * <p> + * {@link java.security.AccessController#doPrivileged(PrivilegedAction)} is deprecated + * since Java 17 (JEP 411) and earmarked to be removed.<br/> + * </p> + * <p> + * On a Java 17 machine, this method will simply invoke the given PrivilegedAction<T>. + * </p> + * @param <T> return type of PrivilegedAction<T> + * @param o the PrivilegedAction<T> + * @return the return type */ @SuppressWarnings({ "deprecation", "removal" }) public static <T> T doPrivileged(final PrivilegedAction<T> o) { - return java.security.AccessController.doPrivileged( o ); + if( PlatformPropsImpl.JAVA_17 ) { + return o.run(); + } else { + return java.security.AccessController.doPrivileged( o ); + } } static { |