Reading Windows ACLs from Java

As part of the Java program, I want to be able to list users and Windows groups that have permission to read this file. Java does not have the built-in ability to read Windows ACL information (at least until Java 7 ), so I'm looking for other solutions.

Are there third-party libraries available that can provide direct access to ACL information for a Windows file?

Otherwise, it is possible to run cacls and capture, and then process the output file, is a reasonable workaround. Is the cacls output format fully documented anywhere and can it change between versions of Windows?

+3
source share
2 answers

If you know the Windows APIs, you can use JNA (JNI without the hassle of writing your own code) to call the Windows API to receive ACL data.

Relatively here is an article that obtains file security information using VBScript. You can change this and return the data in a collapsible format (e.g. XML). You can call the VBScript file by running "cscript.exe" using Runtime.exec () or ProcessBuilder . You can write ACL information to standard output and use the streams available on java.lang.Processto read the output of the process.

, exec'ing vbscript , , ( , script .) script Win32 apis java JNA.

+5

mdma answer Java 6, Java 7

Path file = Paths.get("c:\\test-file.dat");
AclFileAttributeView aclFileAttributes = Files.getFileAttributeView(
    file, AclFileAttributeView.class);

for (AclEntry aclEntry : aclFileAttributes.getAcl()) {
    System.out.println(aclEntry.principal() + ":");
    System.out.println(aclEntry.permissions() + "\n");
}
+3

Source: https://habr.com/ru/post/1745027/


All Articles