Return The Correct Distinguished Name If Given A Domain
If given an array of domains I need to check and choose the right DN based on the DC Example: given domain is “red.blue.net” Check if it exist in a list of Dn’s const dnArray
Solution 1:
like this?
const dnArray = ["CN=Larry,OU=test,DC=RED,DC=COM", "CN=JIM,OU=test,DC=GRE,DC=TEN,DC=COM", "CN=Will,OU=testUsers,DC= Example,DC=COM"];
const domain = "Example.COM"let res = dnArray.filter(e => e.toLowerCase().includes(domain.split('.')[0].toLowerCase()));
console.log(res)
Solution 2:
The following code will return
CN=Larry,OU=test,DC=RED,DC=BLUE,DC=COM
const dnArray =
[
"CN=JIM,OU=test,DC=GRE,DC=TEN,DC=COM",
"CN=Will,OU=testUsers,DC=Example,DC=COM",
"CN=Larry,OU=test,DC=RED,DC=COM",
"CN=Larry,OU=test,DC=BLUE,DC=COM",
"CN=Larry,OU=test,DC=RED,DC=BLUE,DC=NET",
"CN=Larry,OU=test,DC=RED,DC=BLUE,DC=COM"
];
var dn;
const domain = "RED.BLUE.COM"// Will also work as red.blue.net/gov/etcvar dc = domain.toLowerCase().split('.'); // "['red', 'blue', 'com']"var included = false;
dnArray.forEach(name => {
dc.forEach(domain => {
if(name.toLowerCase().includes('dc=' + domain))
included = true;
else
included = false;
});
// If included is true, set dn to equal the current name
dn = included ? name : dn;
});
console.log(dn);
Post a Comment for "Return The Correct Distinguished Name If Given A Domain"