【问题标题】:SharePoint High trust provider hosted app - user impersonation - Site minderSharePoint 高信任提供程序托管应用程序 - 用户模拟 - 站点管理员
【发布时间】:2016-02-29 19:08:44
【问题描述】:

我们正在使用 SiteMinder 对用户进行身份验证,但我们从站点管理器获得的只是标题中的用户身份: ASP.NET Authentication with Siteminder

但是,由于我们使用的是高度信任提供商托管的 SharePoint 应用程序,因此我们可以访问 tokenHelper.cs,但模拟用户需要 System.Security.Principal.WindowsIdentity

我的问题是:

这种情况下如何获取WindowsIdentity?

如何扩展 tokenHelper 以仅使用用户身份(不带 windowsIdentity)来模拟用户?

【问题讨论】:

    标签: asp.net iis sharepoint siteminder sharepoint-apps


    【解决方案1】:

    查看 Steve Peschka 的 blog。我已经使用该博客在受 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);
    

    将此 ClaimsPrincipal 设置为 Httpcontext 用户。 要传递的声明值是 smtp=用户的电子邮件,nameidentifier=用户的登录名,userId=用户的帐户名

    【讨论】:

    • 谢谢,我会试一试。史蒂夫的博客内容丰富,但它不再有附件。你碰巧有附件吗
    【解决方案2】:

    我将在我的 SP+Siteminder 环境中解释上述场景。

    首先你无法获取受site-minder保护的站点的ClientContext。

    您只能使用站点的内部 url [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,上面的代码将可以正常工作,并将帮助您获取当前用户。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-10-28
      • 2015-04-24
      • 2013-09-29
      • 1970-01-01
      • 2014-07-11
      • 1970-01-01
      • 2016-07-10
      相关资源
      最近更新 更多