Extending profile field types for the Sitecore Active Directory module
The Sitecore Active Directory module provides integration between one or more Active Directory domains and Sitecore. Out-of-the-box this module supports reading and writing of data types such as: string, int and bool, however a common Active Directory data type byte[] is not supported.
Sitecore only deals with string types regardless of the original type in Active Directory. It does this by converting all types to and from string at runtime. There is no reason why types such as byte[] would be any different. Overwriting Sitecore's default behavior allows additional types to be supported whilst letting Sitecore handle all remaining types.
Enabling additional support for byte[] is simple enough:
- Create a custom StringSettingsPropertyValue class that can handle getting/setting data from a byte[] field by encoding it as a Base64 string.
- Override the default SettingsPropertyValueFactory to use the StringSettingsPropertyValue or fallback to the Sitecore implementation.
- Update the Sitecore configuration to support the new SettingsPropertyValueFactory.
Create a custom StringSettingsPropertyValue
Create a ByteArraySettingsPropertyValue provider to read/write/convert data between byte[] and string.
Override the default SettingsPropertyValueFactory
Make Sitecore aware of the new StringSettingsPropertyValue by overriding the SettingsPropertyValueFactory. Ensuring the new byte array type is added to the switch statement.
Update the Sitecore configuration
Now the provider exists to translate byte[] to string update the LDAP.config as shown below:
Update any profile fields that require the byte[] type in the configuration as shown in the Profile Photo example below: