n8n-nodes-base
Version:
Base nodes of n8n
55 lines • 2.14 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.resolveBinaryAttributes = exports.BINARY_AD_ATTRIBUTES = void 0;
exports.createLdapClient = createLdapClient;
exports.escapeValue = escapeValue;
const ldapts_1 = require("ldapts");
exports.BINARY_AD_ATTRIBUTES = ['objectGUID', 'objectSid'];
const resolveEntryBinaryAttributes = (entry) => {
Object.entries(entry)
.filter(([k]) => exports.BINARY_AD_ATTRIBUTES.includes(k))
.forEach(([k]) => {
entry[k] = entry[k].toString('hex');
});
return entry;
};
const resolveBinaryAttributes = (entries) => {
entries.forEach((entry) => resolveEntryBinaryAttributes(entry));
};
exports.resolveBinaryAttributes = resolveBinaryAttributes;
async function createLdapClient(context, credentials, nodeDebug, nodeType, nodeName) {
const protocol = credentials.connectionSecurity === 'tls' ? 'ldaps' : 'ldap';
const url = `${protocol}://${credentials.hostname}:${credentials.port}`;
const ldapOptions = { url };
const tlsOptions = {};
if (credentials.connectionSecurity !== 'none') {
tlsOptions.rejectUnauthorized = credentials.allowUnauthorizedCerts === false;
if (credentials.caCertificate) {
tlsOptions.ca = [credentials.caCertificate];
}
if (credentials.connectionSecurity !== 'startTls') {
ldapOptions.tlsOptions = tlsOptions;
}
}
if (credentials.timeout) {
// Convert seconds to milliseconds
ldapOptions.timeout = credentials.timeout * 1000;
}
if (nodeDebug) {
context.logger.info(`[${nodeType} | ${nodeName}] - LDAP Options: ${JSON.stringify(ldapOptions, null, 2)}`);
}
const client = new ldapts_1.Client(ldapOptions);
if (credentials.connectionSecurity === 'startTls') {
await client.startTLS(tlsOptions);
}
return client;
}
function escapeValue(value) {
return value
.replace(/\\/g, '\\5c')
.replace(/\*/g, '\\2a')
.replace(/\(/g, '\\28')
.replace(/\)/g, '\\29')
.replace(/\x00/g, '\\00');
}
//# sourceMappingURL=Helpers.js.map