Developer forum

Forum » Integration » Import custom attributes from Active Directory

Import custom attributes from Active Directory

Roald Haahr Jensen
Reply

We have been following the guide provided on https://doc.dynamicweb.com/documentation-9/integration/other-systems/active-directory-integration and now we have a simple AD integration that works. However, now we are wondering whether it is possible to import custom attributes along with the user and map them to user fields of our own choosing. If so, how do we do it?

Best regards
Roald, Novicell


Replies

 
Morten Bengtson Dynamicweb Employee
Morten Bengtson
Reply

Hi Roald,

You need to make some modifications to the DynamicwebADIntegration project and add column mappings in the data integration job.
I haven't actually tried this, but it should work :)

  1. Implement a class which inherits from System.DirectoryServices.AccountManagement.UserPrincipal and add properties which makes use of the ExtensionGet method to retrieve the attribute values. See details: https://anyrest.wordpress.com/2010/10/14/how-to-use-ad-attributes-not-represented-in-userprincipal-groupprincipal-and-computerprincipal/
  2. Modify DynamicwebADIntegration.ADHelper to use your custom principal class instead of UserPrincipal.
  3. Modify DynamicwebADIntegration.Entities.User by adding a property for each custom attribute and then set these properties when mapping from your custom principal to the User entity class.
  4. Modify DynamicwebADIntegration.XmlFormatter to append an xml element for each of the new properties of the user entity.
  5. Deploy the updated web service and you should now be able to retrieve xml which includes the values of your custom attributes.
  6. Create a custom user field in Dynamicweb for each of the new columns you have added to the xml.
  7. Modify your data integration job (users import activity) by adding a mapping from each of the new column elements to a custom user field.

Now you should be able to import users with custom attribute values by running the scheduled task.

Best regards,
Morten

 
Roald Haahr Jensen
Reply

Hi Morten,

Thank you! It's good to know. However, we have chosen to go with the default attributes instead and then filter by group names, but we are still missing some information, e.g. city.

What mappings does the standard AD integration come with? We were wondering what options we have to map the data.

Best regards,
Roald, Novicell

 
Morten Bengtson Dynamicweb Employee
Morten Bengtson
Reply

Hi Roald,

As far as I know address information like city is not available as standard for users in Active Directory. This information needs to be set up in Active Directory as custom attributes and DynamicwebADIntegration needs to be changed to include those attributes in the mapping.

The standard integration setup includes the following user information:

Dynamicweb User Active Directory UserPrincipal
UserName EmailAddress
Name Name
FirstName GivenName
LastName Surname
MiddleName MiddleName
Email EmailAddress
ExternalID EmployeeId
Phone VoiceTelephoneNumber
Active Enabled
Groups Properties["memberOf"]

For details see:

Dynamicweb.Security.UserManagement.User

System.DirectoryServices.AccountManagement.UserPrincipal

Best regards,
Morten

 

 
Roald Haahr Jensen
Reply

Hi Morten,

Thank you for the list!

I managed to solve the problem in a somehow messy way. I know that the groups that I want to sort by city will have a group name like 'Administration - Aarhus', so knowing from your reply that I cannot import information about the city easily, I chose to create an IndexBuilderExtender to separate the two values. The code is shown below. The name of the sortable groups are in this case always '{Subject area} - {City}', so a user can belong to several departments and several cities. To filter out as many groups as possible, I check whether the string ' - ' is present in the group name and if so, I split the group name and save them as two new fields, AccessUserSubjectAreas and AccessUserCities, in the document that is being indexed.

I can then use these two values in queries to filter the users correctly employee lists.

Best regards,
Roald, Novicell

 

public class UserIndexExtender : IIndexBuilderExtender<UserIndexBuilder>
    {
        public void ExtendDocument(IndexDocument indexDocument)
        {
            if (indexDocument.ContainsKey("GroupNames"))
            {
                var groups = ((IEnumerable)indexDocument["GroupNames"]).Cast<object>().Select(x => x.ToString()).ToArray();
                List<string> subjectAreas = new List<string>();
                List<string> cities = new List<string>();
                foreach (string name in groups)
                {
                    int dividerPos = name.IndexOf(" - ");
                    if (dividerPos > -1)
                    {
                        string subjectArea = name.Substring(0, dividerPos);
                        string city = name.Substring(dividerPos + 3, name.Length - dividerPos - 3);
                        subjectAreas.Add(subjectArea);
                        cities.Add(city);
                    }
                }
                if (subjectAreas.Any())
                {
                    indexDocument.AddToIndex("AccessUserSubjectAreas", subjectAreas.ToArray());
                }
                if (cities.Any())
                {
                    indexDocument.AddToIndex("AccessUserCities", cities.ToArray());
                }
            }

        }
    }

    public static class IndexBuilderExtension
    {
        public static void AddToIndex(this IndexDocument document, string fieldName, object fieldValue)
        {
            if (!document.ContainsKey(fieldName))
            {
                document.Add(fieldName, fieldValue);
            }
            else
            {
                document[fieldName] = fieldValue;
            }
        }
    }

 

 

You must be logged in to post in the forum