vforteli/Flexinets.Ldap.Server

Add thumbnailPhoto or jpegPhoto attribute to sequence as byte

aria321 opened this issue · 3 comments

Hello,
I finally succeeded to improve your LDAP source to be compatible with https://github.com/RocketChat/Rocket.Chat LDAP integration, but I still have little problem, AFAIK I should make all needed attributes manually.

How can I make a thumbnailPhoto as byte buffer, your SearchValue just get string key and string value, I tried to pass out thumbnail picture as Base64 string like below, but it can be read in consumer side:

string thumbnail = SysConv.ToBase64String(thumbnialByte); 
pk[43] = new SearchValue("thumbnailPhoto", thumbnail);

in consumer side it will be retrieved like
const rs = RocketChatFile.bufferToStream(ldapUser._raw.thumbnailPhoto);
seems trying to bufferToStream,
as Microsoft mentioned here thumbnailphoto it's type is Object(Replica-Link) which is System.Byte[]

So which one of data type in UniversalDataType can pass byte and how can I do it?

LCore.LdapAttribute partialAttr = new LCore.LdapAttribute(LCore.UniversalDataType.GraphicString);
partialAttr.ChildAttributes.Add(new LCore.LdapAttribute(LCore.UniversalDataType.GraphicString,arrayObject));

any suggestion and help would be truly appreciated.

It is resolved by ObjectDescriptor data type,
but I have to change some logic,
First I have changed the SearchValue class to get attribute value with it's UneversalDataType and value as object not string, as below:

internal struct SearchValue
{
    internal string[] Keys;
    internal object[] Values;
    internal LCore.UniversalDataType Type; 

    internal SearchValue(string Key, object Value, LCore.UniversalDataType type = LCore.UniversalDataType.OctetString) : this(new string[] { Key }, new object[] { Value }, type) { /* NOTHING */ }

    internal SearchValue(string[] Keys, object[] Values, LCore.UniversalDataType type = LCore.UniversalDataType.OctetString) : this()
    {
        this.Keys = Keys;
        this.Values = Values;
        this.Type = type;
    }

    internal SearchValue(string Key, object[] Values, LCore.UniversalDataType type = LCore.UniversalDataType.OctetString) : this(new string[] { Key }, Values, type) { /* NOTHING */ }
    internal SearchValue(string[] Keys, object Value, LCore.UniversalDataType type = LCore.UniversalDataType.OctetString) : this(Keys, new object[] { Value }, type) { /* NOTHING */ }
}

Then in UserPack() method I am adding thumbnailPhoto like below which is array of byte:
pk[43] = new SearchValue(new string[] { "thumbnailPhoto" }, thumbnail/*Byte array*/, LCore.UniversalDataType.ObjectDescriptor);
then changed AddAttribute() method like below to Add search value item with it's DataType to the output stream:

private void AddAttribute(LCore.LdapAttribute partialAttributeList, string AttributeName, object AttributeValue, LCore.UniversalDataType type = LCore.UniversalDataType.OctetString)
{
    LCore.LdapAttribute partialAttr = new LCore.LdapAttribute(LCore.UniversalDataType.Sequence);
    partialAttr.ChildAttributes.Add(new LCore.LdapAttribute(LCore.UniversalDataType.OctetString, AttributeName));
    LCore.LdapAttribute partialAttrVals = new LCore.LdapAttribute(LCore.UniversalDataType.Set);
    partialAttrVals.ChildAttributes.Add(new LCore.LdapAttribute(type, AttributeValue));
    partialAttr.ChildAttributes.Add(partialAttrVals);
    partialAttributeList.ChildAttributes.Add(partialAttr);
}

in RespondUserData method the AddAttribute() will be called per SearchValue .

Everything is working nice.

Thank you, I finally got it sorted but after a while time, you are right it is low level library but very useful for custom LDAP purpose like us, we have a designed system for user authentication and authorization at the same way we want to expose this current system as LDAP server so this library helped us, but as you know it is not 100% compatible with all LDAP consumer, as I mentioned in last issue (I have to change the main code to reproduce the out put like what that LDAP client needs ).

Sorry for bothering you I have to create issue here as Core lib because I was not able to create issue https://github.com/Sammuel-Miranda/LdapServerLib

anyway I should thank you many times that you make a public library to use.