diff --git a/api/src/auth/drivers/ldap.ts b/api/src/auth/drivers/ldap.ts index 63f0bfe31f207..77633057f9ff8 100644 --- a/api/src/auth/drivers/ldap.ts +++ b/api/src/auth/drivers/ldap.ts @@ -4,6 +4,7 @@ import ldap, { Error, SearchCallbackResponse, SearchEntry, + LDAPResult, InappropriateAuthenticationError, InvalidCredentialsError, InsufficientAccessRightsError, @@ -18,6 +19,7 @@ import { InvalidPayloadException, ServiceUnavailableException, InvalidConfigException, + UnexpectedResponseException, } from '../../exceptions'; import { AuthenticationService, UsersService } from '../../services'; import asyncHandler from '../../utils/async-handler'; @@ -97,6 +99,13 @@ export class LDAPAuthDriver extends AuthDriver { } }); }); + + res.on('end', (result: LDAPResult | null) => { + if (result?.status === 0) { + // Handle edge case with IBM systems where authenticated bind user could not fetch their DN + reject(new UnexpectedResponseException('Failed to find bind user record')); + } + }); }); }); } diff --git a/api/src/exceptions/index.ts b/api/src/exceptions/index.ts index 5d5f255707aba..d66940192b2a6 100644 --- a/api/src/exceptions/index.ts +++ b/api/src/exceptions/index.ts @@ -14,3 +14,4 @@ export * from './route-not-found'; export * from './service-unavailable'; export * from './unprocessable-entity'; export * from './user-suspended'; +export * from './unexpected-response'; diff --git a/api/src/exceptions/unexpected-response.ts b/api/src/exceptions/unexpected-response.ts new file mode 100644 index 0000000000000..ff7ba28b1640d --- /dev/null +++ b/api/src/exceptions/unexpected-response.ts @@ -0,0 +1,7 @@ +import { BaseException } from '@directus/shared/exceptions'; + +export class UnexpectedResponseException extends BaseException { + constructor(message: string) { + super(message, 503, 'UNEXPECTED_RESPONSE'); + } +}