2016-02-29 57 views
0

我們正在使用的SiteMinder驗證用戶,但是我們所有的網站的監護者得到的是在標題用戶身份: ASP.NET Authentication with Siteminder的SharePoint高度信任提供商託管的應用程序 - 用戶模擬 - 網站的監護者

但是由於我們使用高信任提供商託管的SharePoint應用程序,我們有機會獲得tokenHelper.cs但模擬用戶需要System.Security.Principal.WindowsIdentity

我的問題是:

如何在這種情況下獲得的WindowsIdentity?

OR

如何延長tokenHelper冒充剛剛與用戶身份的用戶(沒有的WindowsIdentity)?

回答

0

我會用我的SP + Siteminder環境解釋上述情況。

首先你不能得到網站管理員保護的網站的ClientContext。

您只能使用網站[http://hostname:port/sites/xyz]的內部網址獲取該網站的clientContext。

爲了讓用戶均流 -

var spContext = SharePointContextProvider.Current.GetSharePointContext(HttpContext); 

    // We store internal url of webapplication in web.config 
    string strAdminSiteURL = ConfigurationManager.AppSettings["AdminSiteURL"].ToString(); 

// We have written one function to convert site-minder url to internal url 
       string webUrl = Helper.Helper.GetInternalSiteUrl(strAdminSiteURL, spContext.SPHostUrl.ToString()); 

// Use internal url to create client-context 
        using (ClientContext clientContext = new ClientContext(webUrl)) 
        { 
         clientContext.AuthenticationMode = ClientAuthenticationMode.FormsAuthentication; 
         clientContext.FormsAuthenticationLoginInfo = new FormsAuthenticationLoginInfo(uName, pswd); 

         Web web = clientContext.Web; 
         clientContext.Load(web); 
         clientContext.ExecuteQuery(); 

         // Load SP user from login name found from httpcontext 
         string currentSPUser = string.Concat("<<FBAIdentity>>", User.Identity.Name); 
         var currentUser = clientContext.Web.EnsureUser(currentSPUser); 
         clientContext.Load(currentUser); 
         clientContext.ExecuteQuery(); 
        } 

上面的代碼將正常工作,如果認證模式是FBA,將幫助您獲得當前用戶。

1

檢查這個blog通過Steve Peschka。我使用該博客在受SiteMinder保護的SharePoint 2013中設置了提供商託管的應用程序。爲了模擬用戶,您需要創建用戶的ClaimsIdentity並將其作爲當前用戶插入到HttpContext中。下面的示例代碼:

var identity = new ClaimsIdentity(AuthenticationTypes.Federation, "http://schemas.xmlsoap.org/claims/useridentifier", String.Empty); 
identity.AddClaim(new Claim("http://schemas.xmlsoap.org/claims/useridentifier", userId, "http://www.w3.org/2001/XMLSchema#string")); 
identity.AddClaim(new Claim(ClaimTypes.Email, smtp, "http://www.w3.org/2001/XMLSchema#string")); 
identity.AddClaim(new Claim("http://schemas.xmlsoap.org/ws/2005/05/identity/claims/sip", nameIdentifier, "http://www.w3.org/2001/XMLSchema#string")); 
ClaimsPrincipal principal = new ClaimsPrincipal(identity); 

設置此聲明爲Principalas Httpcontext用戶。 要傳遞的聲明值是smtp =用戶的電子郵件地址,nameidentifier =用戶的登錄名,userId =用戶的帳戶名稱

+0

謝謝我會試一試.Steve的博客非常豐富,但它沒有附件了。你有沒有附件? – user669915

相關問題