Automatically adding users to NAV
Adding users to groups in Active Directory and Windows Groups is not enough to give access to NAV. Here we will show a way to automatically add a user to NAV Windows Logins when they are added to a specific group.
Getting ready
You will need to create the .NET project described in the Checking Active Directory groups section of the Checking for user-assigned roles recipe in this chapter.
How to do it...
Add the following functions to your .NET class:
public string RetrieveSID(string user, string domain) { string connectionPrefix = "LDAP://" + domain; byte[] userSID; DirectorySearcher ADSearcher = new DirectorySearcher(new DirectoryEntry(connectionPrefix)); ADSearcher.Filter = @"(&(objectClass=user) (cn=" + user + "))"; SearchResult result = ADSearcher.FindOne(); if (result == null) { throw new NullReferenceException ("Could not find " + user + " in the " + domain + " domain"); } DirectoryEntry ADUser = result.GetDirectoryEntry(); ADUser = new DirectoryEntry...