#1 2025-01-19 10:21:36

johnnysynop
Member
Registered: 2018-07-01
Posts: 42

get custom attr does not work

How to display any attribute value?

Uinfo: TLdapUser;
WriteLn('ID: '+(UInfo.custom( 'EmployeeID')));

return just nothing (field is not empty)

Offline

#2 2025-01-19 12:26:11

johnnysynop
Member
Registered: 2018-07-01
Posts: 42

Re: get custom attr does not work

ab wrote:

Don't put JSON in-between.

  LDAPProperties := LDAP.SearchAll([], ObjectFilter(ofUsers, windowsUser),    [roCanonicalNameAtRoot, roSortByName, roSddlKnownUuid, roAutoRange,    roKnownValuesAsArray]);
...
   EmployeeID := LDAPProperties.EmployeeID;

@ab, I found your this snippet from other post .

what data types for EmployeeID and LDAPProperties you mean there? I mean var declarations.

Beside datatype question, what is the most proper way to get any single attribute (not listed in ldapuser)?

Last edited by johnnysynop (2025-01-19 12:53:54)

Offline

#3 2025-01-19 15:27:28

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,793
Website

Re: get custom attr does not work

TLdapClient.SearchAll() returns a variant.
This will be a TDocVariant.

If you want a single attribute, just specify a single so* enum in the TLdapAttributeTypes set.
If you want to specify the attributes as text (e.g. if it is not any TLdapAttributeTypes enum) , you can use TLdapClient.SearchAllDocRaw() or SearchAllRaw().

Offline

#4 2025-01-19 20:30:52

johnnysynop
Member
Registered: 2018-07-01
Posts: 42

Re: get custom attr does not work

thx, I set

var  LDAPProperties :variant:= LDAP.SearchAll([], ObjectFilter(ofUsers, windowsUser),    [roCanonicalNameAtRoot, roSortByName, roSddlKnownUuid, roAutoRange,    roKnownValuesAsArray]);
  var EmployeeID:utf8string := LDAPProperties.EmployeeID;
  Writeln('EmployeeID: ', EmployeeID);

compiles well but on runtime gives me error:
Could not convert variant of type (Null) into type (String)

but this attribute for that user sure has value I confirmed with windows attribute editor...

Last edited by johnnysynop (2025-01-20 07:30:32)

Offline

#5 2025-01-20 07:40:18

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,793
Website

Re: get custom attr does not work

What actually do you want to do?

The fact that you have the "Could not convert variant of type (Null) into type (String)" error has nothing to do with mORMot, it is your query which returns no result.
You did not define any "EmployeeID" attribute, so of course there is no EmployeeID field value, so LDAPProperties.EmployeeID returns null.

If you want to have the attribute value of one object, and are lost with variants, don't use SearchAll() but just SearchObject().
Then use TLdapResult.Attributes.GetByName().
Something like that:

EmployeeID := LDAP.SearchObject(DN, Filter, ['EmployeeID']).Attributes.GetByName('EmployeeID');

Offline

#6 2025-01-20 09:04:00

johnnysynop
Member
Registered: 2018-07-01
Posts: 42

Re: get custom attr does not work

ab wrote:

What actually do you want to do?

I want get single attribute value (employeeId) (not listed in TLdapUser properties) for chosen user in this case "windowsUser" var.
and I thought function Custom(const AttributeName: RawUtf8): RawUtf8; is for that from TLdapUser

or that I can extract it with

  var EmployeeID:utf8string := LDAPProperties.EmployeeID; 

Last edited by johnnysynop (2025-01-20 09:19:14)

Offline

#7 2025-01-20 10:17:41

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,793
Website

Re: get custom attr does not work

So what is wrong with TLdapClient.GetUserInfo() and ['windowsUser'] as CustomAttributes parameter?

Offline

#8 2025-01-20 11:23:45

johnnysynop
Member
Registered: 2018-07-01
Posts: 42

Re: get custom attr does not work

I'm not sure if you understand me
your earlier code

EmployeeID := LDAP.SearchObject(DN, Filter, ['EmployeeID']).Attributes.GetByName('EmployeeID');

gives me AV

Can you please provide  sample code, which works for you  to get value of EmployeeID attribute for ldap user 'windowsUser'?
I know it sounds trivial for you but I want to make sure that we have consistent result, I mean my AD, Delphi, mormot etc.

Last edited by johnnysynop (2025-01-20 15:35:42)

Offline

#9 2025-01-20 16:56:24

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,793
Website

Re: get custom attr does not work

    GetUserInfo('windowsUser', '', '', u, '', false, ['EmployeeID']);
    writeln(u.Custom('EmployeeID'));

works on my side.

Offline

#10 Yesterday 14:40:20

johnnysynop
Member
Registered: 2018-07-01
Posts: 42

Re: get custom attr does not work

thx, but I still wonder how it works for you if you copy/pasted it.
Second ver works for me good.

       LdapClient.GetUserInfo('windowsUser', '', '', info, '', false, ['EmployeeID']);
    writeln('Non 1:1 case sensitive, DOES NOT WORK');
    writeln(info.Custom('EmployeeID'));


           LdapClient.GetUserInfo('windowsUser', '', '', info, '', false, ['employeeID']);
    writeln('1:1 with attribute name from LDAP, WORKS PERFECT');
    writeln(info.Custom('employeeID'));
         readln;

Very interesting, maybe your AD has different naming or you just pased it without really running wink
Anyway maybe some adding some new beside current very strict function would be useful?
I mean to get custom attr name but do not care about case-sens.

So it could not work from the begening due to "E" instead of "e". No matter what code would be used smile Thank you.

Last edited by johnnysynop (Yesterday 14:58:57)

Offline

#11 Yesterday 16:06:13

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,793
Website

Re: get custom attr does not work

LDAP attribute names are case sensitive AFAICT.

Offline

#12 Yesterday 18:26:18

johnnysynop
Member
Registered: 2018-07-01
Posts: 42

Re: get custom attr does not work

ab wrote:

LDAP attribute names are case sensitive AFAICT.

interesting, hmm:
https://stackoverflow.com/a/29908970

Offline

#13 Yesterday 18:39:12

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,793
Website

Re: get custom attr does not work

This is about the value, not the name.

Offline

#14 Yesterday 18:40:39

johnnysynop
Member
Registered: 2018-07-01
Posts: 42

Re: get custom attr does not work

Ok got it, so AD username can be LiKeThAt, and will work but to get specific attribute strict naming needed.
All clear, thx Arnaud.

Offline

Board footer

Powered by FluxBB