Skip to content

Lift minimum JDK version to 21 and remove SecurityManager - #2214

Open
holgerfriedrich wants to merge 11 commits into
apache:mainfrom
holgerfriedrich:pr-secmgr-removal
Open

holgerfriedrich wants to merge 11 commits into
apache:mainfrom
holgerfriedrich:pr-secmgr-removal

Conversation

@holgerfriedrich

@holgerfriedrich holgerfriedrich commented Dec 30, 2025

Copy link
Copy Markdown
Contributor

This is a first step to prepare the 4.5 branch for running with Java 25.
Starting Karaf in Java 25 does not yet work, as a few functions related to the SecurityManager have been deprecated long time ago and cannot be activated any longer via command line switches.
As a new API has been added in Java 18, I for new lift the minimum required version to Java 21 (LTS).

Maybe this is not the way to go - as there has been some discussions if we could introduce an abstraction layer to allow Java 17 as well.

  • Lift minimum JDK version to 21
  • Remove occurrences of SecurityManager, as getSecurityManager returns
    null since JDK 18
  • Disable JavaSecurityTest, Rework JavaSecurityTest #2082
  • Enable verbose deprecation warnings
  • Replace getSubject and doAs calls
    ** getSubject can no longer be activated via JRE command line as
    SecurityManager has been removed in JDK 25.
    A replacement is available since Java 21.
    ** doAs was deprecated and is replaced by callAll.

For Java 25, another set of modifications is still needed and will be submitted as another PR.
Locally, I got Karaf compiling, passing the tests, and starting with Java 25. 🥳

@jbonofre
jbonofre self-requested a review December 31, 2025 05:20
<libraries>
</libraries>
<javase>17</javase>
<javase>21</javase>

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's require change on the karaf-maven-plugin and dependencies. I will create another PR (as planned) to tackle that.

import static org.ops4j.pax.exam.CoreOptions.maven;
import static org.ops4j.pax.exam.karaf.options.KarafDistributionOption.*;

@Ignore("Disabled due to removal of SecurityManager. ref Apache Karaf GitHub issue #2082")

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would rather remove the test (to avoid confusion) or refactor it instead of ignoring it.

@holgerfriedrich holgerfriedrich Jan 1, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, if I just remove the SecurityManager assertion, the test completes.
I am not sure if I get completely what this test was intended for (it checks that all bundles come up after applying a specific config - but how this was related to SecurityManager, I still don't get).

I pushed the change to ignore that no SecurityManager is there.

@holgerfriedrich

Copy link
Copy Markdown
Contributor Author

@jbonofre is there anying else open I should address?

@jbonofre

jbonofre commented Jan 9, 2026

Copy link
Copy Markdown
Member

@holgerfriedrich I think this PR is pretty good, it just needs dependent PRs. I will tackle that.

@jbonofre

Copy link
Copy Markdown
Member

@holgerfriedrich do you mind to share your email address with me ? I just realize that you didn't subscribe on the dev mailing list, and you are not on The ASF slack Karaf channel. Thanks !

@arusevm

arusevm commented Mar 12, 2026

Copy link
Copy Markdown

Hi @holgerfriedrich @jbonofre,

I've got here some ugly patches that seem to make the Subject-related stuff work on java 25.

Basically, there's an issue with that in 25, Subject.callAs() and current() use a ScopedValue and its binding "gets lost" across "thread-boundaries", of which there are a bunch :) It gets ugly, because every time you do something like ExecutorService.submit() you have to also "pass" the current Subject. Gets even worse, because Gogo needs a similar treatment...

Anyway, wondering if it might help if I share what we've got here with you... or if you already have something like it? Or if I might help in some other way? :)

@jbonofre

Copy link
Copy Markdown
Member

@arusevm I'm finalizing camel-karaf release. I will be back on Karaf just after, tackling this.

Sorry for the delay.

@jbonofre

Copy link
Copy Markdown
Member

Thanks @holgerfriedrich for the update ! I will do a new pass because I have a bunch of changes on the way.

@holgerfriedrich
holgerfriedrich force-pushed the pr-secmgr-removal branch 6 times, most recently from 7e6e4fd to 05bbfa0 Compare April 14, 2026 22:30
@holgerfriedrich

holgerfriedrich commented Apr 16, 2026

Copy link
Copy Markdown
Contributor Author

@jbonofre may I ask you to have a look at this again?

I rebased it in the last days and got the CI green.

It is a major step towards Java 25 compatibility.
Compilation with JDK 25 already works; one test needs a class downgrade and a few itests fail.
I'd like to keep that in a separate PR on top of this one.

❯ ./bin/karaf
WARNING: A terminally deprecated method in sun.misc.Unsafe has been called
WARNING: sun.misc.Unsafe::staticFieldOffset has been called by org.apache.felix.framework.util.SecureAction (file:/C:/Users/holgerf/src/karaf/assemblies/apache-karaf/target/assembly/system/org/apache/felix/org.apache.felix.framework/7.0.5/org.apache.felix.framework-7.0.5.jar)
WARNING: Please consider reporting this to the maintainers of class org.apache.felix.framework.util.SecureAction
WARNING: sun.misc.Unsafe::staticFieldOffset will be removed in a future release
        __ __                  ____
       / //_/____ __________ _/ __/
      / ,<  / __ `/ ___/ __ `/ /_
     / /| |/ /_/ / /  / /_/ / __/
    /_/ |_|\__,_/_/   \__,_/_/

  Apache Karaf (4.5.0-SNAPSHOT)

Hit '<tab>' for a list of available commands
and '[cmd] --help' for help on a specific command.
Hit '<ctrl-d>' or type 'system:shutdown' or 'logout' to shutdown Karaf.

@root()> shell:info
shell:info
Karaf
  Karaf version               4.5.0-SNAPSHOT
  Karaf home                  C:\Users\holgerf\src\karaf\assemblies\apache-karaf\target\assembly
  Karaf base                  C:\Users\holgerf\src\karaf\assemblies\apache-karaf\target\assembly
  OSGi Framework              org.apache.felix.framework-7.0.5

JVM
  Java Virtual Machine        OpenJDK 64-Bit Server VM version 25+36-3489
  Version                     25

@jbonofre

jbonofre commented May 6, 2026

Copy link
Copy Markdown
Member

@holgerfriedrich I removed the specs bundles. Can you please rebase?

What's your take about JDK 17 / JDK 21?
Personaly, I think it's completely ok to bump directly to JDK 21 for Karaf 4.5.x (JDK 17 is supported at runtime by Karaf 4.4.x).

@holgerfriedrich

Copy link
Copy Markdown
Contributor Author

@jbonofre if we do not consider writing a compat layer on our own, we need then new API available from JDK18. So 21 LTS is the natural choice.
I have rebased now (mainly due to the deleted files in the spec folder), but did not have time to give it a try in JDK25.

@jbonofre

jbonofre commented May 6, 2026

Copy link
Copy Markdown
Member

@holgerfriedrich I agree. I'm advocating for JDK 21 for Karaf 4.5.x. I propose to go that way (including updating our CI).

@holgerfriedrich

Copy link
Copy Markdown
Contributor Author

@jbonofre how shall we proceed with this one?
Is something missing, or do you have another approach in mind?

@kamilkrzywanski

Copy link
Copy Markdown

@holgerfriedrich there is needed wersion of aries proxy compatible with jdk 25, it seems that their repo is already compatible with jdk 25 but no new release yet.

org.apache.aries.proxy
org.apache.aries.proxy
1.1.14

@jbonofre

jbonofre commented Jun 2, 2026

Copy link
Copy Markdown
Member

@holgerfriedrich @kamilkrzywanski I think we can move forward with this PR and tackle more required updates in follow up PRs (I'm working on Aries releases).

@jbonofre

Copy link
Copy Markdown
Member

@holgerfriedrich I will be back on this one with you to finalize it.

@scootermorris

Copy link
Copy Markdown

Any progress on this? The Cytoscape project is trying to upgrade to Java 25 and right now, this PR seems to be what we need to start moving in that direction. Once this is committed, we should be able to use the nightly builds to start our testing and (if necessary) make the required changes to our REST infrastructure.

@jbonofre

jbonofre commented Sep 2, 2026

Copy link
Copy Markdown
Member

@scootermorris I'm back on this one for Karaf 4.5.0. I will push some improvements/fixes and we will good to go. Let's say mid next week.

@scootermorris

Copy link
Copy Markdown

@jbonofre Great to hear! Looking forward to it.

@github-actions

github-actions Bot commented Sep 3, 2026

Copy link
Copy Markdown

Test Results

  726 files  ±0    726 suites  ±0   1h 19m 34s ⏱️ -46s
  985 tests ±0    937 ✅ ±0   48 💤 ±0  0 ❌ ±0 
2 955 runs  ±0  2 811 ✅ ±0  144 💤 ±0  0 ❌ ±0 

Results for commit a9b9add. ± Comparison against base commit 54c6fb1.

♻️ This comment has been updated with latest results.

@holgerfriedrich

Copy link
Copy Markdown
Contributor Author

@jbonofre Should I rebase again to check?

@holgerfriedrich

Copy link
Copy Markdown
Contributor Author

@jbonofre I had to rework, since the files added in the meantime need changes as well.
Adding j25/ubuntu preview/mvn4 build, I stumbled upon an incompatibility: aries proxy package is to java21 byte code. A possible fix seems already been added, but never published:
https://github.com/apache/aries/blame/6f3c176af5449c7ff38445c5b4c5a16a0bdbf27a/proxy/proxy-impl/src/main/java/org/apache/aries/proxy/impl/ProxyUtils.java#L42
Anything we could do about that?

@jbonofre

Copy link
Copy Markdown
Member

@holgerfriedrich thanks for that! I'm working with Domonik for a new Aries Proxy release including the change.

holgerfriedrich and others added 11 commits September 16, 2026 18:17
* Lift minimum JDK version to 21
* Remove occurrences of SecurityManager, as getSecurityManager returns
  null since JDK 18
* Enable verbose deprecation warnings
* Replace getSubject and doAs calls,
  getSubject can no longer be activated via JRE command line as
  SecurityManager has been removed in JDK 25.
  A replacement is available since Java 21.
  doAs was deprecated and is replaced by callAll.
* Remove SecurityManager form JavaSecurityTest
Subject.current()/callAs() use a plain ScopedValue on JDK 25 (no
SecurityManager fallback like on JDK 21), which doesn't survive a
new Thread or an ExecutorService hop. Since Felix Gogo runs each
command on its own executor thread, this broke current-user lookup
and RBAC checks (bundle:list/bundle:info losing bundle visibility).

- JaasHelper.doAs/runAs now use Subject.callAs() instead of the old
  AccessControlContext/SubjectDomainCombiner plumbing; drop the now
  dead OsgiSubjectDomainCombiner/DelegatingProtectionDomain classes.
- SecuredCommand.execute() re-binds the subject from the session on
  whatever thread runs the command, since Session is always passed
  explicitly there regardless of the executing thread.
- LocalConsoleManager, ShellFactoryImpl and SuCommand store the
  subject on the session so SecuredCommand can read it back.
Signed-off-by: Holger Friedrich <mail@holger-friedrich.de>
@fabgio

fabgio commented Sep 19, 2026

Copy link
Copy Markdown

@jbonofre any news about Aries update?
@holgerfriedrich OpenHab contributor here!
Thank you both!

@jbonofre

Copy link
Copy Markdown
Member

@fabgio I'm on Aries stuff and related. I will get back to that later today or tomorrow: I'm busy with Karaf 4.4.12 release prep right now.

@jbonofre

Copy link
Copy Markdown
Member

@fabgio Karaf 4.5.0 (including this PR) will be my top priority as soon as Karaf 4.4.12 is out.

@holgerfriedrich

holgerfriedrich commented Sep 19, 2026

Copy link
Copy Markdown
Contributor Author

I did some testing in the past with the (already committed but not yet published) aries.proxy-1.1.15-SNAPSHOT. Apache aries needs to be cloned, then proxy installed. I did this with Java 21:

mvn install -N -f parent/pom.xml
mvn install -Daries.skip.version.check=true -f proxy/pom.xml

From here you can continue with Java 25 default:

Then it needs a small patch to bring in the new version and additional dependencies:

diff --git a/assemblies/features/standard/src/main/feature/feature.xml b/assemblies/features/standard/src/main/feature/feature.xml
index 06bb632a51..62a86fa849 100644
--- a/assemblies/features/standard/src/main/feature/feature.xml
+++ b/assemblies/features/standard/src/main/feature/feature.xml
@@ -37,6 +37,8 @@
         <bundle dependency="false" start-level="20">mvn:org.ow2.asm/asm-tree/${asm.version}</bundle>
         <bundle dependency="false" start-level="20">mvn:org.ow2.asm/asm-analysis/${asm.version}</bundle>
         <bundle dependency="false" start-level="20">mvn:org.ow2.asm/asm-commons/${asm.version}</bundle>
+        <!-- aries proxy >= 1.1.15 needs objenesis although its import is optional -->
+        <bundle dependency="false" start-level="20">mvn:org.objenesis/objenesis/${objenesis.version}</bundle>
         <bundle start-level="20">mvn:org.apache.aries.proxy/org.apache.aries.proxy/${aries.proxy.version}</bundle>
     </feature>
 
diff --git a/bom/pom.xml b/bom/pom.xml
index 225a9ed2e1..38ea526eac 100644
--- a/bom/pom.xml
+++ b/bom/pom.xml
@@ -478,6 +478,11 @@
                 <artifactId>asm-commons</artifactId>
                 <version>${asm.version}</version>
             </dependency>
+            <dependency>
+                <groupId>org.objenesis</groupId>
+                <artifactId>objenesis</artifactId>
+                <version>${objenesis.version}</version>
+            </dependency>
 
             <dependency>
                 <groupId>org.apache.felix</groupId>
diff --git a/itests/test/src/test/filtered-resources/etc/feature.xml b/itests/test/src/test/filtered-resources/etc/feature.xml
index b4c139af3d..7a0c9d69ab 100644
--- a/itests/test/src/test/filtered-resources/etc/feature.xml
+++ b/itests/test/src/test/filtered-resources/etc/feature.xml
@@ -37,6 +37,7 @@
         <bundle dependency="false" start-level="20">mvn:org.ow2.asm/asm-tree/${asm.version}</bundle>
         <bundle dependency="false" start-level="20">mvn:org.ow2.asm/asm-analysis/${asm.version}</bundle>
         <bundle dependency="false" start-level="20">mvn:org.ow2.asm/asm-commons/${asm.version}</bundle>
+        <bundle dependency="false" start-level="20">mvn:org.objenesis/objenesis/${objenesis.version}</bundle>
         <bundle start-level="20">mvn:org.apache.aries.proxy/org.apache.aries.proxy/${aries.proxy.version}</bundle>
     </feature>
 
diff --git a/pom.xml b/pom.xml
index 763c497567..ece6f5933d 100644
--- a/pom.xml
+++ b/pom.xml
@@ -263,7 +263,7 @@
         <aries.jndi.api.version>1.1.0</aries.jndi.api.version>
         <aries.jndi.core.version>1.0.2</aries.jndi.core.version>
         <aries.jndi.url.version>1.1.0</aries.jndi.url.version>
-        <aries.proxy.version>1.1.14</aries.proxy.version>
+        <aries.proxy.version>1.1.15-SNAPSHOT</aries.proxy.version>
         <aries.proxy.api.version>1.1.1</aries.proxy.api.version>
         <aries.spifly.version>1.3.7</aries.spifly.version>
         <aries.subsystem.api.version>2.0.10</aries.subsystem.api.version>
@@ -292,6 +292,7 @@
         <maven.wagon.version>3.5.3</maven.wagon.version>
         <maven-plugin-annotations.version>3.16.0</maven-plugin-annotations.version>
         <maven.resolver.version>2.0.23</maven.resolver.version>
+        <objenesis.version>3.6</objenesis.version>
 
         <osgi.version>8.0.0</osgi.version>
         <org.osgi.annotation.bundle.version>2.0.0</org.osgi.annotation.bundle.version>

This makes all our tests work on a Java 25.
Note that we still lock the code generation to Java 21 in Karaf.

For newer Java versions, aries needs another patch, apache/aries#912. I tried this and got it working with Java 27.
It matters on which JDK aries proxy runs - not the class file version which is generated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants