Categories
Apple User Help

How can java application request access to network volume?

My app is completely written in java and was running fine under High Sierra.
new RandomAccessFile(file_on_network_volume, "rws") gained access and execution continued.

With 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 proper 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
    request user for access to network volume
    then the test succeeded to do the required operation on the network volume.
  • 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.

Leave a Reply

Your email address will not be published. Required fields are marked *