Description: A prototype of allowing SecurityManager.
 Java 21 disables setting security manager without
 -Djava.security.manager property set.
 Set the property to allow Netbeans platform to manipulate
 SecurityManager.
Author: Jan Lahoda <jlahoda@netbeans.org>
Origin: https://github.com/apache/netbeans/commit/4c9d9492f70b09aaeae2b8b10fc26ae29433d667
Bug-Ubuntu: https://bugs.launchpad.net/ubuntu/+source/libnb-platform18-java/+bug/2061363
Bug-Debian: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=1069015
Forwarded: not-needed
Last-Update: 2024-04-15
---
 .../org/netbeans/core/netigso/Netigso.java    |   1 +
 platform/o.n.bootstrap/launcher/unix/nbexec   |   2 +-
 platform/o.n.bootstrap/src/allow.java         | 188 ++++++++++++++++++
 3 files changed, 190 insertions(+), 1 deletion(-)
 create mode 100644 platform/o.n.bootstrap/src/allow.java

--- a/platform/core.netigso/src/org/netbeans/core/netigso/Netigso.java
+++ b/platform/core.netigso/src/org/netbeans/core/netigso/Netigso.java
@@ -142,6 +142,7 @@
             }
             framework = frameworkFactory.newFramework(configMap);
             try {
+                System.clearProperty("java.security.manager");
                 framework.init();
                 NetigsoServices ns = new NetigsoServices(this, framework);
             } catch (BundleException ex) {
--- a/platform/o.n.bootstrap/launcher/unix/nbexec
+++ b/platform/o.n.bootstrap/launcher/unix/nbexec
@@ -189,7 +189,7 @@
 # rename old heap dump to .old
 mv "${userdir}/var/log/heapdump.hprof" "${userdir}/var/log/heapdump.hprof.old" > /dev/null 2>&1
 
-jargs_without_clusters="$jargs"
+jargs_without_clusters="$jargs -Djava.security.manager=allow"
 jargs="-Dnetbeans.dirs=\"${clusters}\" $jargs_without_clusters"
 
 if [ -z "$cachedirspecified" ]; then
--- /dev/null
+++ b/platform/o.n.bootstrap/src/allow.java
@@ -0,0 +1,184 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import java.io.FileDescriptor;
+import java.net.InetAddress;
+import java.security.Permission;
+
+/**
+ *
+ */
+public class allow extends SecurityManager {
+
+    @Override
+    public void checkAccept(String host, int port) {
+        uninstall();
+    }
+
+    @Override
+    public void checkAccess(Thread t) {
+        uninstall();
+    }
+
+    @Override
+    public void checkAccess(ThreadGroup g) {
+        uninstall();
+    }
+
+    public void checkAwtEventQueueAccess() {
+        uninstall();
+    }
+
+    @Override
+    public void checkConnect(String host, int port) {
+        uninstall();
+    }
+
+    @Override
+    public void checkConnect(String host, int port, Object context) {
+        uninstall();
+    }
+
+    @Override
+    public void checkCreateClassLoader() {
+        uninstall();
+    }
+
+    @Override
+    public void checkDelete(String file) {
+        uninstall();
+    }
+
+    @Override
+    public void checkExec(String cmd) {
+        uninstall();
+    }
+
+    @Override
+    public void checkExit(int status) {
+        uninstall();
+    }
+
+    @Override
+    public void checkLink(String lib) {
+        uninstall();
+    }
+
+    @Override
+    public void checkListen(int port) {
+        uninstall();
+    }
+
+    public void checkMemberAccess(Class<?> clazz, int which) {
+        uninstall();
+    }
+
+    @Override
+    public void checkMulticast(InetAddress maddr) {
+        uninstall();
+    }
+
+    @Override
+    public void checkMulticast(InetAddress maddr, byte ttl) {
+        uninstall();
+    }
+
+    @Override
+    public void checkPackageAccess(String pkg) {
+        uninstall();
+    }
+
+    @Override
+    public void checkPackageDefinition(String pkg) {
+        uninstall();
+    }
+
+    @Override
+    public void checkPermission(Permission perm) {
+        uninstall();
+    }
+
+    @Override
+    public void checkPermission(Permission perm, Object context) {
+        uninstall();
+    }
+
+    @Override
+    public void checkPrintJobAccess() {
+        uninstall();
+    }
+
+    @Override
+    public void checkPropertiesAccess() {
+        uninstall();
+    }
+
+    @Override
+    public void checkPropertyAccess(String key) {
+        uninstall();
+    }
+
+    @Override
+    public void checkRead(FileDescriptor fd) {
+        uninstall();
+    }
+
+    @Override
+    public void checkRead(String file) {
+        uninstall();
+    }
+
+    @Override
+    public void checkRead(String file, Object context) {
+        uninstall();
+    }
+
+    @Override
+    public void checkSecurityAccess(String target) {
+        uninstall();
+    }
+
+    @Override
+    public void checkSetFactory() {
+        uninstall();
+    }
+
+    public void checkSystemClipboardAccess() {
+        uninstall();
+    }
+
+    public boolean checkTopLevelWindow(Object window) {
+        uninstall();
+        return true;
+    }
+
+    @Override
+    public void checkWrite(FileDescriptor fd) {
+        uninstall();
+    }
+
+    @Override
+    public void checkWrite(String file) {
+        uninstall();
+    }
+
+    private void uninstall() {
+        System.setSecurityManager(null);
+    }
+}
