Skip to content

Introduce SystemAccessUtils to wrap AccessController.doPrivileged() - #1668

Open
taoliult wants to merge 1 commit into
IBM:java21from
taoliult:java21_SecurityManager
Open

Introduce SystemAccessUtils to wrap AccessController.doPrivileged()#1668
taoliult wants to merge 1 commit into
IBM:java21from
taoliult:java21_SecurityManager

Conversation

@taoliult

@taoliult taoliult commented Jul 23, 2026

Copy link
Copy Markdown
Collaborator

Introduce SystemAccessUtils to wrap AccessController.doPrivileged() in APIs (doPrivileged, doPrivilegedChecked, runPrivileged). On JDK 21 and earlier, all three methods delegate to AccessController.doPrivileged() so privileged operations succeed when SecurityManager enabled and required permission. On JDK 25 and later, where SecurityManager and AccessController are removed entirely, the same SystemAccessUtils class is kept but the methods become pass-through no-ops that simply invoke the supplied action directly, so callers need no changes regardless of JDK version.

Comment thread src/main/java/com/ibm/crypto/plus/provider/OpenJCEPlusFIPS.java Outdated

//disable caching mechanism for windows OS
final static private boolean isWindows = System.getProperty("os.name").startsWith("Windows");
final static private boolean isWindows = SystemAccessUtils.doPrivileged(() -> System.getProperty("os.name")).startsWith("Windows");

@KostasTsiounis KostasTsiounis Jul 27, 2026

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.

Should we change this to something that most resembles the existing call? Could we do something like SystemAccessUtils.getProperty("os.name");

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

I considered adding a SystemAccessUtils.getProperty() method before, but the problem is it doesn't stop there — we would also need separate methods for System.load(), File.exists(), File.getAbsolutePath(), new FileReader(), Class.forName(), OCK context initialization, and so on. That would turn SystemAccessUtils into an ever-growing class with one wrapper per JDK operation.

The three existing methods — doPrivileged(), doPrivilegedChecked(), and runPrivileged() — I think they can cover all cases in the current codebase: value-returning without checked exceptions, value-returning with checked exceptions, and void operations respectively. Any future privileged operation can be wrapped with one of these three without touching SystemAccessUtils.

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.

Hi @taoliult I also lean toward it being a better approach what Kostas mentioned above for a few reasons. I think it will be easier to ensure that a call that needs a privledged action actually calls the utility class. We can review it as so on PRs made to main. Also doing this will avoid having generic lambda functions throughout the code making it a bit cleaner. For example all calls would do a SystemAccessUtils.getProperty instead of having to write a lambda expression for each.

@taoliult
taoliult force-pushed the java21_SecurityManager branch from a435aee to 81b622d Compare July 27, 2026 18:57
@@ -143,7 +143,7 @@ public List<ServiceDefinition> readServices() throws IOException {
throw new IOException("File not found: " + filePath);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Should we add a privileged check on this Files.exists() function?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Yes, updated.

Comment thread src/main/java/com/ibm/crypto/plus/provider/SystemAccessUtils.java Outdated
Comment thread src/main/java/com/ibm/crypto/plus/provider/ock/NativeOCKImplementation.java Outdated
@taoliult
taoliult force-pushed the java21_SecurityManager branch from 10601e3 to a7e07b9 Compare July 28, 2026 21:22
@taoliult
taoliult requested a review from jasonkatonica July 28, 2026 21:27
@taoliult
taoliult force-pushed the java21_SecurityManager branch from b0a56a3 to 9323557 Compare July 29, 2026 14:06

@jasonkatonica jasonkatonica left a comment

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.

LGTM

@taoliult
taoliult force-pushed the java21_SecurityManager branch 5 times, most recently from db4db36 to 3274784 Compare August 10, 2026 16:34
Introduce SystemAccessUtils to wrap AccessController.doPrivileged()
in APIs (doPrivileged, doPrivilegedChecked, runPrivileged). On JDK
21 and earlier, all three methods delegate to
AccessController.doPrivileged() so privileged operations succeed
when SecurityManager enabled and required permission. On JDK 25
and later, where SecurityManager and AccessController are removed
entirely, the same SystemAccessUtils class is kept but the methods
become pass-through no-ops that simply invoke the supplied action
directly, so callers need no changes regardless of JDK version.

Signed-off-by: Tao Liu <tao.liu@ibm.com>
@taoliult
taoliult force-pushed the java21_SecurityManager branch from 1e50e81 to d725f65 Compare August 10, 2026 17:03
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.

5 participants