I am accessing a remote server with Java. The server runs Microsoft Windows and provides an Active Directory as well as a file system share. I read users and groups from the Active Directory via JNDI, which works great. I get all user attributes like distinguishedName
, objectSid
and so on.
My Java program also connects to a Windows share on the same server, using Java 7 and NIO.2. I can read the remote file system and get information about it. I can also read file permission settings like this:
import java.nio.file.Files;
import java.nio.file.attribute.AclEntry;
import java.nio.file.attribute.AclFileAttributeView;
import java.nio.file.attribute.UserPrincipal;
[...]
AclFileAttributeView aclView = Files.getFileAttributeView(path, AclFileAttributeView.class);
for (AclEntry aclEntry : aclView.getAcl()) {
UserPrincipal principal = aclEntry.principal();
[...]
}
This way I get access rights for a UserPrincipal
object. This class only provides a method getName()
which returns some name or sometimes an SID.
For actual users the UserPrincipal
object returns an SID which I can use to find the corresponding user in the Active Directory. However, if UserPrincipal
represents a group, getName()
just returns a text like for example "VORDEFINIERT\Administratoren"
.
I could not find a way to map this text to a group defined in the Active Directory. The corresponding group in AD has this distinguishedName
property: CN=Administratoren,CN=Builtin,DC=mydomain,DC=com
.
Both the machine where the Java program runs and the server are running a German version of Windows. It's strange that AD returns CN=Builtin
(English) but the file system returns a group name with a German translation VORDEFINIERT
. If both would be e.g. Builtin
I could probably parse the UserPrincipal
and find out what the distinguishedName
of the AD object should be... however, this approach does not seem to be very reliable.
I'd really like to be able to read the SID of all UserPrincipal
objects so that I can find the corresponding user or group in AD.
Is there a way to do this? Please let me know if you need more information.
Best regards, sky