本文介绍了如果给定域,则返回正确的专有名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果给定一组域,我需要检查并根据 DC 选择正确的 DN

If given an array of domains I need to check and choose the right DN based on the DC

示例:给定的域是red.blue.net"

Example: given domain is "red.blue.net"

检查它是否存在于 Dn 的列表中

Check if it exist in a list of Dn’s

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", CN=Sam,OU=test,DC=RED,DC=Blue,DC=NET"];

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", "CN=Sam,OU=test,DC=RED,DC=Blue,DC=NET"];

返回

CN=Sam,OU=test,DC=RED,DC=Blue,DC=NET"

"CN=Sam,OU=test,DC=RED,DC=Blue,DC=NET"

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 = "red.blue.net"

let res = dnArray.map(item => item.split(",")

    .filter(e => e.startsWith("DC="))

    .join(".")

);

for (const dn of dnArray) {

   //if the DCs in domain matches the one for dnArray I want to return right dn "CN=Sam,OU=test,DC=RED,DC=Blue,DC=NET"

 }

推荐答案

下面的代码会返回

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/etc

    var 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);

这篇关于如果给定域,则返回正确的专有名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-02 23:32