Skip to content

Commit 37c992f

Browse files
authored
[PM-13007] Fix Active Directory externalId parsing (#693)
Return AD ObjectGuid attribute as buffer so it can be parsed properly
1 parent 6915667 commit 37c992f

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

src/services/ldap-directory.service.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,11 @@ import { IDirectoryService } from "./directory.service";
1818

1919
const UserControlAccountDisabled = 2;
2020

21+
/**
22+
* The attribute name for the unique identifier used by Active Directory.
23+
*/
24+
const ActiveDirectoryExternalId = "objectGUID";
25+
2126
export class LdapDirectoryService implements IDirectoryService {
2227
private client: ldapts.Client;
2328
private dirConfig: LdapConfiguration;
@@ -240,7 +245,7 @@ export class LdapDirectoryService implements IDirectoryService {
240245
* otherwise it falls back to the provided referenceId.
241246
*/
242247
private getExternalId(searchEntry: ldapts.Entry, referenceId: string) {
243-
const attr = this.getAttr<Buffer>(searchEntry, "objectGUID");
248+
const attr = this.getAttr<Buffer>(searchEntry, ActiveDirectoryExternalId);
244249
if (attr != null) {
245250
return this.bufToGuid(attr);
246251
} else {
@@ -358,6 +363,9 @@ export class LdapDirectoryService implements IDirectoryService {
358363
filter: filter,
359364
scope: "sub",
360365
paged: this.dirConfig.pagedSearch,
366+
// We need to expressly tell ldapts what attributes to return as Buffer objects,
367+
// otherwise they are returned as strings
368+
explicitBufferAttributes: [ActiveDirectoryExternalId],
361369
};
362370
const { searchEntries } = await this.client.search(path, options, controls);
363371
return searchEntries.map((e) => processEntry(e)).filter((e) => e != null);

0 commit comments

Comments
 (0)