Some of my AD properties don't line up with the default provided in the code. There are also some additional properties I would like to automagically stick into a user's profile. Here is my take on a solution to that problem:
ADSIMap.xml (Add to Portal Directory - adjust fields to meet your needs)
<ADSI>
<UserInfo>
<Email>mail</Email>
<CName>cn</CName>
<DisplayName>displayName</DisplayName>
<DistinguishedName>distinguishedName</DistinguishedName>
<sAMAccountName>sAMAccountName</sAMAccountName>
</UserInfo>
<Profile>
<FirstName>givenName</FirstName>
<LastName>sn</LastName>
<City>companyCampusCode</City>
<Region>companySiteCode</Region>
<Country>companyRegionCode</Country>
<EmployeeID>employeeID</WWID>
<ManagerID>manager</ManagerWWID>
<BadgeType>employeeBadgeType</BadgeType>
</Profile>
</ADSI>
ADSIProvider.vb
Imports System.IO
Imports System.Reflection
Imports System.Xml
.....
Private Sub FillUserInfo(ByVal UserEntry As DirectoryEntry, ByVal UserInfo As UserInfo)
With UserInfo
.IsSuperUser = False
.Username = UserInfo.Username
.Membership.Approved = True
.Membership.LastLoginDate = Date.Today()
.Email = Utilities.CheckNullString(UserEntry.Properties(Configuration.ADSI_EMAIL).Value)
.CName = Utilities.CheckNullString(UserEntry.Properties(Configuration.ADSI_CNAME).Value.ToString)
.DisplayName = Utilities.CheckNullString(UserEntry.Properties(Configuration.ADSI_DISPLAYNAME).Value)
.DistinguishedName = Utilities.CheckNullString(UserEntry.Properties(Configuration.ADSI_DISTINGUISHEDNAME).Value.ToString)
.sAMAccountName = Utilities.CheckNullString(UserEntry.Properties(Configuration.ADSI_ACCOUNTNAME).Value.ToString)
.Profile.FirstName = Utilities.CheckNullString(UserEntry.Properties(Configuration.ADSI_FIRSTNAME).Value)
.Profile.LastName = Utilities.CheckNullString(UserEntry.Properties(Configuration.ADSI_LASTNAME).Value)
.Profile.Street = Utilities.CheckNullString(UserEntry.Properties(Configuration.ADSI_STREET).Value)
.Profile.City = Utilities.CheckNullString(UserEntry.Properties(Configuration.ADSI_CITY).Value)
.Profile.Region = Utilities.CheckNullString(UserEntry.Properties(Configuration.ADSI_REGION).Value)
.Profile.PostalCode = Utilities.CheckNullString(UserEntry.Properties(Configuration.ADSI_POSTALCODE).Value)
.Profile.Country = Utilities.CheckNullString(UserEntry.Properties(Configuration.ADSI_COUNTRY).Value)
.Profile.Telephone = Utilities.CheckNullString(UserEntry.Properties(Configuration.ADSI_TELEPHONE).Value)
.Profile.Fax = Utilities.CheckNullString(UserEntry.Properties(Configuration.ADSI_FAX).Value)
.Profile.Cell = Utilities.CheckNullString(UserEntry.Properties(Configuration.ADSI_CELL).Value)
.Profile.Website = Utilities.CheckNullString(UserEntry.Properties(Configuration.ADSI_WEBSITE).Value)
.AuthenticationExists = True
If File.Exists(System.IO.Path.Combine(_portalSettings.HomeDirectoryMapPath(), "ADSIMap.xml")) Then
Dim properties As ProfilePropertyDefinitionCollection = .Profile.ProfileProperties()
Dim objProfileController As ProfileController = New ProfileController()
Dim objProfileProperties As ProfilePropertyDefinitionCollection = objProfileController.GetPropertyDefinitionsByPortal(_portalSettings.PortalId)
Dim fieldPropertyDef As ProfilePropertyDefinition
Dim fieldPropertyInfo As PropertyInfo
Dim userInfoNode As XmlNode
Dim adsiMapDoc As New XmlDocument()
adsiMapDoc.Load(System.IO.Path.Combine(_portalSettings.HomeDirectoryMapPath(), "ADSIMap.xml"))
For Each userInfoNode In adsiMapDoc.SelectNodes("ADSI/UserInfo/*")
fieldPropertyInfo = UserInfo.GetType().GetProperty(userInfoNode.LocalName())
If Not fieldPropertyInfo Is Nothing Then
fieldPropertyInfo.SetValue(UserInfo, Utilities.CheckNullString(UserEntry.Properties(userInfoNode.InnerText).Value), Nothing)
End If
Next
For Each userInfoNode In adsiMapDoc.SelectNodes("ADSI/Profile/*")
fieldPropertyDef = properties.GetByName(userInfoNode.LocalName())
If Not fieldPropertyDef Is Nothing Then
.Profile.SetProfileProperty(fieldPropertyDef.PropertyName, Utilities.CheckNullString(UserEntry.Properties(userInfoNode.InnerText).Value))
End If
Next
End If
If .DisplayName = String.Empty Then
.DisplayName = .CName
End If
If .Profile.FirstName.Length = 0 Then
.Profile.FirstName = Utilities.TrimUserDomainName(UserInfo.Username)
End If
End With
End Sub