How can java application (macOS Catalina) request access to network volume?
Asked Answered
Q

0

10

My app is completely written in java (we moved to java11 from java8) and was running fine under High Sierra:
new RandomAccessFile(file_on_network_volume, "rws") gained access and execution continued.

Running under Catalina it fails with
java.io.FileNotFoundException: /Volumes/messages/xyz/FILE.xdt (Operation not permitted)

I understand that any application trying to access a network volume needs a special permission, I reviewed them in System Preferences and they can be removed with tccutil reset SystemPolicyNetworkVolumes [bundle_id] for repeated testing.

How does the java code properly request the access right from the user so that the processing might continue?

What I did so far:

  • changed the code to
    AccessController.doPrivileged((PrivilegedExceptionAction<RandomAccessFile>) () -> new RandomAccessFile(file, "rws"));
    That caused a JUnitTest run with IntelliJ to request the right by a dialogue
    An application in IntelliJ IDEA requests access to files on a network volume

An application in IntelliJ IDEA requests access to files on a network volume


then the test succeeded to do the required operation on the network volume.
The effect is the permission indicated in system preferences as expected:
permission to access network volumes is present

permission to access network volumes is present

  • added in the Info.plist the entry
    <key>NSNetworkVolumesUsageDescription</key> <string>@@bundle_name@@ benötigt Zugriff auf ein Netzwerkvolume.</string>
    corresponding to the text in the dialog displayed to the user

But still something's missing. The app does not request the permission and consequently the operation fails. IntelliJ does something right that I didn't figure out so far.

Quirinus answered 25/1, 2021 at 14:31 Comment(2)
I'm also wondering about this one. In my case, the application is not one that is started and stopped by a user but rather a process that is started by another process which in turn is running as a daemon in the background (using a .plist file stored in /Library/LaunchDaemons). So in this case, even if I could get it to request the permission, how would a popup for requesting permission even be displayed to a user? Surely Apple, you must provide a way for a user to grant such permission to a certain executable up-front and not just reactively when that executable is executed?Whatsoever
Yes, this is a real bummer. I have found a workaround for an application with a GUI, but not for a headless application.Radiography

© 2022 - 2025 — McMap. All rights reserved.