From 601a3ee683a7af9b65dad20d1e2b56926dc47353 Mon Sep 17 00:00:00 2001 From: E-ThanG <19691760+E-ThanG@users.noreply.github.com> Date: Wed, 6 Nov 2024 12:20:47 -0800 Subject: [PATCH] Update useOpenLdap.js (#8366) Changed to case-insensitive attribute name indices, set base_dn for getSubSchemaDN to null, and added explicit limits to sendLdapSearchRequest function calls. --- .../_components/ldapCondition/useOpenLdap.js | 33 ++++++++++++------- 1 file changed, 22 insertions(+), 11 deletions(-) diff --git a/html/pfappserver/root/src/views/Configuration/sources/_components/ldapCondition/useOpenLdap.js b/html/pfappserver/root/src/views/Configuration/sources/_components/ldapCondition/useOpenLdap.js index faae79176bd7..0d290e18fd5c 100644 --- a/html/pfappserver/root/src/views/Configuration/sources/_components/ldapCondition/useOpenLdap.js +++ b/html/pfappserver/root/src/views/Configuration/sources/_components/ldapCondition/useOpenLdap.js @@ -10,7 +10,7 @@ import { function useOpenLdap(form) { const performSearch = (filter, scope, attributes, base_dn) => { - return sendLdapSearchRequest({...form.value}, filter, scope, attributes, base_dn) + return sendLdapSearchRequest({...form.value}, filter, scope, attributes, base_dn, 1000) .then((result) => { return {results: parseLdapResponseToAttributeArray(result, extractAttributeFromFilter(filter)), success: true} } @@ -18,26 +18,37 @@ function useOpenLdap(form) { } const getSubSchemaDN = () => { - return sendLdapSearchRequest({...form.value}, null, 'base', ['subSchemaSubEntry'], form.value.basedn) + return sendLdapSearchRequest({...form.value}, null, 'base', ['subSchemaSubEntry'], '', 1) .then((response) => { - let firstAttribute = response[Object.keys(response)[0]] - return firstAttribute['subschemaSubentry'] + const keys = Object.keys(response) + if (keys.length) { + const firstAttribute = response[keys[0]] + const lowerCaseKeys = Object.keys(firstAttribute).map(key => key.toLowerCase()) + const subSchemaSubEntryIndex = lowerCaseKeys.indexOf('subschemasubentry') + if (subSchemaSubEntryIndex !== -1) { + const subSchemaSubEntryKey = Object.keys(firstAttribute)[subSchemaSubEntryIndex] + return firstAttribute[subSchemaSubEntryKey] + } + } + return [] }) } const fetchAttributeTypes = (subSchemaDN) => { - return sendLdapSearchRequest({...form.value}, '(objectclass=subschema)', - 'base', - ['attributeTypes'], - subSchemaDN) + return sendLdapSearchRequest({...form.value}, '(objectClass=subSchema)', 'base', ['attributeTypes'], subSchemaDN, 1000) .then((response) => { const keys = Object.keys(response) if (keys.length) { - const { attributeTypes } = response[keys[0]] - return attributeTypes + const firstAttribute = response[keys[0]] + const lowerCaseKeys = Object.keys(firstAttribute).map(key => key.toLowerCase()) + const attributeTypesIndex = lowerCaseKeys.indexOf('attributetypes') + if (attributeTypesIndex !== -1) { + const attributeTypesKey = Object.keys(firstAttribute)[attributeTypesIndex] + return firstAttribute[attributeTypesKey] + } } return [] - }) + }) } const getAttributes = () => {