簡體   English   中英

使用基於聲明的身份驗證對SharePoint 2010的相同AD進行身份驗證時,區分Windows Auth和Forms Auth用戶

[英]Differentiate between Windows Auth and Forms Auth users when authenticating against same AD with SharePoint 2010 using claims based authentication

我目前正在開發一個SharePoint 2010項目,其中使用基於聲明的身份驗證的SharePoint Web應用程序設置環境。 Web應用程序在端口8081上使用Windows身份驗證進行身份驗證,並使用基於表單的身份驗證擴展到端口80。

表單身份驗證提供程序設置為使用與基於Windows身份驗證的站點相同的活動目錄,使用應用程序的web.config中的以下條目(條目也在中央管理和安全令牌服務web.config文件中):

    <membership defaultProvider="i">
  <providers>
    <add name="i" type="Microsoft.SharePoint.Administration.Claims.SPClaimsAuthMembershipProvider, Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" />
    <add name="FBA_AD_MP" type="System.Web.Security.ActiveDirectoryMembershipProvider, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" connectionStringName="ADFBAConnectionString" enableSearchMethods="true" attributeMapUsername="userPrincipalName" />
  </providers>
</membership>

使用此設置按預期工作; 在端口8081上訪問應用程序的用戶將看到標准的Windows身份驗證質詢,端口80上的用戶將被定向到自定義登錄表單。 通過現成的管理工具將用戶添加到站點時,搜索特定用戶(如john.smith@mydomain.com)將返回兩個匹配,一個來自Windows身份驗證提供程序,另一個來自表單身份驗證提供程序。 將這兩個用戶添加到站點會顯示SharePoint存儲帳戶名稱,並在前面附加標識符。 windows auth用戶被翻譯為i:0#.w | mydomain \\ johnsmith,FBA用戶被翻譯為i:0#.f | fba_ad_mp | john.smith@mydomain.com。

這就是問題所在。我們使用自定義構建工具批量創建網站集,該工具解析輸入電子表格,創建網站集,並使用以下方法將適當的用戶添加到新創建的網站:

    private static void AddUser(SPSite site, String userName, String spGroupName)
    {
        try
        {
            SPUser spUser = site.RootWeb.EnsureUser(userName);

            if (spUser != null)
            {
                site.RootWeb.Groups[spGroupName].AddUser(spUser);
            }
        }
        catch(Exception ex)
        {
            SharePointManager.Counter.Warnings++;
            SharePointManager.Logger.Warn(String.Format("\t\tUnable to add user {0} to group {1} at site {2}: {3}", userName, spGroupName, site.RootWeb.Url, ex.ToString()));
        }
    }

傳入的userName參數遵循示例john.smith@mydomain.com。 但是,添加到站點的用戶始終是基於Windows身份驗證的用戶,i:0#.w | mydomain \\ johnsmith。

如何在調用EnsureUser時指定要輪詢的身份驗證提供程序,以便我可以保證將正確的用戶添加到站點中?

問題是兩個成員資格提供者都識別電子郵件地址,並使用第一個結果(AD)。 嘗試FBA_AD_MP:john.smith@mydomain.com - 該語法在標准用戶名控件中工作(使用檢查名稱而不是搜索對話框),我相信EnsureUser的工作方式相同。

簡而言之,您需要使用SPClaimProviderManager將SPUser轉換為SPClaim

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM