|
44 | 44 | import java.util.stream.Stream; |
45 | 45 |
|
46 | 46 | import org.graalvm.nativeimage.ImageSingletons; |
47 | | -import org.graalvm.nativeimage.LogHandler; |
48 | 47 | import org.graalvm.nativeimage.Platform; |
49 | 48 | import org.graalvm.nativeimage.Platforms; |
50 | 49 | import org.graalvm.nativeimage.hosted.FieldValueTransformer; |
|
67 | 66 | import com.oracle.svm.core.hub.DynamicHub; |
68 | 67 | import com.oracle.svm.core.jdk.JavaLangSubstitutions.ClassValueSupport; |
69 | 68 | import com.oracle.svm.core.monitor.MonitorSupport; |
70 | | -import com.oracle.svm.core.option.HostedOptionKey; |
71 | 69 | import com.oracle.svm.core.snippets.SubstrateForeignCallTarget; |
72 | 70 | import com.oracle.svm.core.thread.JavaThreads; |
73 | 71 | import com.oracle.svm.core.thread.VMOperation; |
74 | 72 | import com.oracle.svm.core.util.VMError; |
75 | 73 | import com.oracle.svm.util.ReflectionUtil; |
76 | 74 |
|
77 | | -import jdk.graal.compiler.options.Option; |
78 | 75 | import jdk.graal.compiler.replacements.nodes.BinaryMathIntrinsicNode; |
79 | 76 | import jdk.graal.compiler.replacements.nodes.BinaryMathIntrinsicNode.BinaryOperation; |
80 | 77 | import jdk.graal.compiler.replacements.nodes.UnaryMathIntrinsicNode; |
@@ -413,32 +410,26 @@ private static String getProperty(String key, String def) { |
413 | 410 | @Alias @RecomputeFieldValue(kind = Kind.FromAlias, isFinal = true) // |
414 | 411 | private static int allowSecurityManager = 1; |
415 | 412 |
|
| 413 | + /** |
| 414 | + * We do not support the {@link SecurityManager} so this method must throw a |
| 415 | + * {@link SecurityException} when 'java.security.manager' is set to anything but |
| 416 | + * <code>disallow</code>. |
| 417 | + * |
| 418 | + * @see System#setSecurityManager(SecurityManager) |
| 419 | + * @see SecurityManager |
| 420 | + */ |
416 | 421 | @Substitute |
417 | | - @TargetElement(onlyWith = JavaLangSubstitutions.UseSecurityManagerPropertyAtRuntime.class) |
418 | | - private static void setSecurityManager(SecurityManager s) { |
419 | | - /* We read properties interpreted at isolate creation as that is what happens on the JVM */ |
420 | | - String smp = SystemPropertiesSupport.singleton().getSavedProperties().get("java.security.manager"); |
421 | | - if (smp != null && !smp.equals("disallow")) { |
422 | | - /* |
423 | | - * The strict failure is needed as the security precaution: In case a user does not read |
424 | | - * our documentation, uses this deprecated API marked for removal, and passes |
425 | | - * "-Djava.security.manager=allow" at runtime, and accidentally catches the |
426 | | - * UnsupportedOperationException, we don't want to compromise their security. |
427 | | - */ |
428 | | - System.err.println(""" |
429 | | - Fatal error: Property '-Djava.security.manager' is set, but SecurityManager is not supported by Native Image. Please unset this property. |
430 | | - Exiting the program to prevent misinterpretation of the set SecurityManager at:"""); |
431 | | - |
432 | | - for (var traceElement : new UnsupportedOperationException().getStackTrace()) { |
433 | | - System.err.println("\tat " + traceElement); |
| 422 | + private static void setSecurityManager(SecurityManager sm) { |
| 423 | + if (sm != null) { |
| 424 | + /* Read the property collected at isolate creation as that is what happens on the JVM */ |
| 425 | + String smp = SystemPropertiesSupport.singleton().getSavedProperties().get("java.security.manager"); |
| 426 | + if (smp != null && !smp.equals("disallow")) { |
| 427 | + throw new SecurityException("Setting the SecurityManager is not supported by Native Image"); |
| 428 | + } else { |
| 429 | + throw new UnsupportedOperationException( |
| 430 | + "The Security Manager is deprecated and will be removed in a future release"); |
434 | 431 | } |
435 | | - |
436 | | - /* bypasses possible filters on System.exit */ |
437 | | - ImageSingletons.lookup(LogHandler.class).fatalError(); |
438 | 432 | } |
439 | | - |
440 | | - throw new UnsupportedOperationException( |
441 | | - "The Security Manager is deprecated and will be removed in a future release"); |
442 | 433 | } |
443 | 434 | } |
444 | 435 |
|
@@ -686,18 +677,6 @@ public Object transform(Object receiver, Object originalValue) { |
686 | 677 | /** Dummy class to have a class with the file's name. */ |
687 | 678 | public final class JavaLangSubstitutions { |
688 | 679 |
|
689 | | - public static class UseSecurityManagerPropertyAtRuntime implements BooleanSupplier { |
690 | | - public static class Options { |
691 | | - @Option(help = "Used only for testing as exiting the program shadows other working tests, please do not use in production.")// |
692 | | - public static final HostedOptionKey<Boolean> TestingSecurityViolationUseSecurityManagerPropertyAtRuntime = new HostedOptionKey<>(true); |
693 | | - } |
694 | | - |
695 | | - @Override |
696 | | - public boolean getAsBoolean() { |
697 | | - return Options.TestingSecurityViolationUseSecurityManagerPropertyAtRuntime.getValue(); |
698 | | - } |
699 | | - } |
700 | | - |
701 | 680 | public static final class StringUtil { |
702 | 681 | /** |
703 | 682 | * Returns a character from a string at {@code index} position based on the encoding format. |
|
0 commit comments