I continued researching this problem and found a solution:
In this case (accessing a Windows share) the objects returned by aclEntry.principal()
are actually of class WindowsUserPrincipals.Group
or WindowsUserPrincipals.User
. UserPrincipal
is an interface implemented by WindowsUserPrincipals.User
. And WindowsUserPrincipals.Group
is a subclass of WindowsUserPrincipals.User
.
Class sun.nio.fs.WindowsUserPrincipals
is not public, so it can't be accessed directly. But I saw that the inner class WindowsUserPrincipals.User
contains exactly the SID which I have been looking for. It is in a private field called sidString
.
So my solution is to check if the returned UserPrincipal
is a WindowsUserPrincipal
and if yes, use reflection to read the value of field sidString
.
It works and can be written in a reliable way, however, it is not a really super nice solution because I had to use reflection. But I did not find an easier way to access or get the SID.
Please still answer this question if you know better ways to read the SID. Thank you.