2011-05-20 42 views
-1

我工作的公司有2個活動目錄林。一個森林被稱爲我們,在那裏我在我的個人資料(我們\ maflorin)早上登錄,另一個森林被稱爲(mail.us),這是專用於Exchange。兩個活動目錄林,找到相應的交換活動目錄對象/郵箱

我創建了一個在SharePoint上運行並獲取SPContext.Current.Web.CurrentUser.LoginName這是美國域名登錄名的asp.net應用程序。 (例如我們\我的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; 
} 

是否有可能得到交換對象有一個LDAP查詢直接我們samAccountName?

交換森林上的mailNickname屬性並不總是與美林的sAMAccountName相匹配。如果不匹配,我使用第二個ldap查詢來查看是否通過查詢描述字段返回記錄。說明字段對於兩個森林來說都是相同的,但有時管理員會更改它。

是否可以更輕鬆地爲美國域憑證找到相應的Exchange Active Directory對象? Outlook如何從我們的憑證中找到相應的郵箱/廣告對象?我正在用adsiedit查看AD架構,但找不到用於將兩個林對象鏈接在一起的明確字段。

此外,我正在研究交換Web服務託管API(郵箱DN屬性)的自動發現服務,但您需要傳遞給GetUserSettings方法一個SMTP地址,並且此字段未填充到我們的域。

非常感謝,

馬蒂亞斯

+0

什麼版本的Exchange您使用的是? – 2011-05-26 20:30:48

+0

Exchange 2007,感謝您查看此問題 – 2011-05-27 10:09:00

回答

-1

我能找到這個問題的答案具有比上述這取決於公司的命名約定的一個更好的方法。

在交換林中,我使用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; 
}