Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
this.afterInclude(function(Model, result, records, include, cache){
var relation = include.relation
if(!relation || !relation.ldap) return
if(!result) return
var type = include.relation.ldap
if(!Array.isArray(result)) result = [result]
for(var i = 0; i < result.length; i++){
var dn = result[i].dn
if(type === 'children'){
dn = parseDN(dn).parent()
if(relation.recursive){
var found = false
do{
if(cache.dn_mapping[Utils.normalizeDn(dn)]){
found = true
break
}
if(!dn.parent()){
found = true // actually not, but we stop the loop here...
}else{
dn = dn.parent()
}
}while(!found)
}
scopeCheck = function(k) {
if (req.dn.equals(k)) {
return true
}
var parent = ldap.parseDN(k).parent()
return parent ? parent.equals(req.dn) : false
}
break
function normalizeDN(dn) {
return ldap.parseDN(dn).toString();
}
users.forEach((user) => {
const { cn, name, credentials } = user;
db[user.cn] = {
dn: ldap.parseDN(`cn=${cn}, ${suffix}`),
attributes: {
uid: cn,
name,
mail: `${cn}@${domain}`
},
credentials
};
});
scopeCheck = function(k) {
if(k === "rootDse")
return false;
if (req.dn.equals(k))
return true;
var parent = ldap.parseDN(k).parent();
return (parent ? parent.equals(req.dn) : false);
};
break;
oktaDirectory.users.forEach(function(user) {
user.shortName = user.profile.email.split('@')[0];
var dn = interpolateObject(config.okta.userDN, user);
user.dn = ldap.parseDN(dn).toString();
});
this.beforeInclude(function(Chains, records, include, cache){
var relation = include.relation
if(!relation || !relation.ldap) return
cache.dn_mapping = {}
var type = relation.ldap
var dns = []
for(var i = 0; i < records.length; i++){
var dn = records[i].dn
if(type === 'parent'){
dn = Utils.normalizeDn(parseDN(records[i].dn).parent().toString())
}else{
if(type !== 'children' && records[i][type] && relation.type === 'belongs_to_many'){
dn = Utils.normalizeDn(records[i][type])
}
}
if(!dn) dn = []
if(!Array.isArray(dn)) dn = [dn]
for(var d = 0; d < dn.length; d++){
cache.dn_mapping[dn[d]] = cache.dn_mapping[dn[d]] || []
cache.dn_mapping[dn[d]].push(records[i])
if(dns.indexOf(dn[d]) === -1){
dns.push(dn[d])
normalizeDn: function(dn, lowercased) {
if (Array.isArray(dn)) {
for (var i = 0; i < dn.length; i++) {
dn[i] = this.normalizeDn(dn[i])
}
return dn
}
try {
dn = parseDN(dn.toString())
.toString()
.replace(/, /g, ',')
if (lowercased !== false) dn = dn.toLowerCase()
return dn
} catch (e) {
return null
}
},