Skip to content

Commit

Permalink
Update useOpenLdap.js (#8366)
Browse files Browse the repository at this point in the history
Changed to case-insensitive attribute name indices, set base_dn for getSubSchemaDN to null, and added explicit limits to sendLdapSearchRequest function calls.
  • Loading branch information
E-ThanG authored and satkunas committed Nov 6, 2024
1 parent 71746f2 commit 601a3ee
Showing 1 changed file with 22 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,34 +10,45 @@ 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}
}
)
}

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 = () => {
Expand Down

0 comments on commit 601a3ee

Please sign in to comment.