首页 文章

两个活动目录林,找到相应的交换活动目录对象/邮箱

提问于
浏览
-1

我工作的公司有2个Active Directory林 . 一个森林叫做我们,我早上用我的 Profiles (us \ maflorin)登录,另一个森林叫做(mail.us),专门用于Exchange .

我创建了一个在SharePoint上运行的asp.net应用程序,并获取了SPContext.Current.Web.CurrentUser.LoginName,它是us域登录名 . (我们\ maflorin例如对我来说) . 我想从美国凭证中获取Exchange林上的相应对象,以便为在线管理器批准过程之后打开页面的用户写入全局地址列表(GAL)的更改 .

我编写了以下工作代码来获取Exchange对象,但它使用两个ldap查询来查找对象:

private Dictionary<string,AdRecod> FindExchangeAdProperties(string samAccountName,string description)
 {
        Dictionary<string,AdRecod> properties = null;
        if (!string.IsNullOrEmpty(samAccountName))
        {
            properties = GetUserProperties(@"(&(objectCategory=person)(mailNickname=" +
                                               samAccountName + "))");
            if (properties != null) return properties;
         }

        if ((description == "") || (description == "0"))
            throw new Exception("No matching Description, couldn't find correct Exchange AD object");

        properties = GetUserProperties(@"(&(objectCategory=person)(description=" +
                                       description + "))");
        return properties;
 }

是否可以直接从us samAccountName获取具有单个ldap查询的交换对象?

Exchange林上的mailNickname属性并不总是与us林上的sAMAccountName匹配 . 如果它不匹配,我使用第二个ldap查询来查看是否通过查询描述字段返回记录 . 对于两个林,描述字段的次数相同,但有时管理员会对其进行更改 .

是否可以更轻松地为us域凭据找到相应的Exchange Active Directory对象? Outlook如何从美国凭据中找到相应的邮箱/广告对象?我正在使用adsiedit查看AD模式,但找不到用于将两个林对象链接在一起的清除字段 .

此外,我正在研究交换Web服务托管api(邮箱dn属性)的自动发现服务,但您需要将GetAserSettings方法传递给SMTP地址,并且此字段不会填充在us域中 .

非常感谢,

马蒂亚斯

1 回答

  • -1

    我能够找到一个比上面更好的方法来回答这个问题,这取决于公司的命名惯例 .

    在Exchange林中,我使用DirectorySearcher类运行LDAP查询以获取属性msExchMasterAccountSid .

    以下代码然后在我们用于登录的林上提供正确的sam:

    var sid = directoryEntry.Properties["msExchMasterAccountSid"].Value as byte[];
    // no mailbox
    if (sid == null) continue;
    
    var sidString = new SecurityIdentifier(sid, 0).ToString();
    var samAccountName = "";
    using (var context = new PrincipalContext(ContextType.Domain, "US"))
    {
           var principal = UserPrincipal.FindByIdentity(context, IdentityType.Sid, sidString);
           if (principal == null) continue;
           samAccountName = principal.SamAccountName;
    }
    

相关问题