Autor Beitrag
FrEEzE2046
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 109

Windows 98, 2000, XP Pro, Vista Ultimate 32 & 64 Bit, Windows 7 Beta 64 Bit
C/C++, C# (VS 2008 TeamSystem) - Delphi (Delphi 5) - Java (Eclipse)
BeitragVerfasst: Fr 03.12.10 15:03 
Hallo,

ich möchte in meinem AuthenticationDomainService, welcher Windows Authentifizierung zugrunde liegt, die Gruppenzugehörigkeiten des authentifizierten Benutzers abfragen.

Folgender Weg ist leider gescheitert:
ausblenden C#-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
        public User GetAuthenticatedUser()
        {
            User user = base.GetAuthenticatedUser(new WindowsPrincipal(WindowsIdentity.GetCurrent()));
            string[] tmp = user.Name.Split('\\');

            DirectoryEntry entry = new DirectoryEntry("WinNT://" + tmp[0] + "/" + tmp[1]);
            user.FullName = entry.Properties["FullName"].Value.ToString();
            user.Groups = entry.Properties["Groups"].Value as string[]; 

            return user;
        }


Das Property "Groups" scheint in diesem Zusammenhang nicht zu existieren und ich bekomme immer null zurückgeliefert.
Weiß jemand Rat? Danke vorab.
Trashkid2000
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 561
Erhaltene Danke: 137



BeitragVerfasst: So 05.12.10 14:15 
Hallo,

wenn Du Dir mal die Properties anschaust, die in entry.Properties enthalten sind, stellst Du fest, dass es dort keine Property mit dem Namen "Groups" gibt. Ich denke, das ist nur in Verbindung mit dem LDAP-Provider möglich.

Aber so müsste es gehen:
ausblenden C#-Quelltext
1:
2:
3:
WindowsIdentity userIdentity = WindowsIdentity.GetCurrent();
string fullname = userIdentity.Name;
string[] userGroups = userIdentity.Groups.Select(identity => identity.Translate(typeof(NTAccount)).Value).ToArray();

mit dem fullname habe ich nicht ganz verstanden. Ist nicht der Fullname eigentlich schon der Anmeldename?
Marko