带有携带者令牌的SharePoint搜索REST API返回错误的项目数



我在搜索中有一个非常奇怪的问题。我正在通过使用get进行查询 https://sonar-sandbox.gredspdev.loc/_api/search/query?querytext='DMSSonarDocId:5042aa1f-b3a4-4577-8e21-8a47ca27c243 OR DMSSonarDocId:1401144b-bd3d-429a-a386-5061ecc714e1'&sourceid='a0f4d450-e701-4f2a-888a-8d871002752d'&trimduplicates=false&rankingmodelid='05289DBE-73E9-4665-BF69-EE68274176EB'&rowlimit=9000&enablestemming=false&enablesorting=false&selectproperties='DMSSonarDocId,<...>'

我正在使用为用户生成的携带者令牌进行身份验证。此查询返回7个项目。然后,我与用户(NTLM(在浏览器中执行相同的URL,并返回10个项目。那不是全部。我再为用户生成令牌。将其粘贴到上一个携带者令牌上的get请求中,它返回10个项目...我等待几秒钟,假设30 ...再收到一段时间,我返回了7个项目(总是相同的(!这是100%可复制的。在另一个浏览器和令牌10项目的再生之后,一段时间在同一令牌7个项目上。

更新。我发现ULS的日志上有差异:正确工作时:

Context has no SMTP/UPN claims. IdentityContext: '{"nameid":"s-1-5-21-2843295230-2675739751-2774624307-1482","nii":"urn:office:idp:activedirectory","upn":"kowalj@spdev.loc","userId":"0#.w|spdev\kowalj","appliesTo":"https://sonar-sandbox.spdev.loc/"}'

不正确工作时:

Context has no SMTP/UPN claims. IdentityContext: '{"nameid":"s-1-5-21-2843295230-2675739751-2774624307-1482","nii":"urn:office:idp:activedirectory","upn":"spdev\kowalj","userId":"0#.w|spdev\kowalj","appliesTo":"https://sonar-sandbox.spdev.loc/"}'

另一个发现:丢失的项目是直接分配给我的项目 - 不是通过我们的自定义索赔提供商解决的小组 - 是的,我们有一个很长一段时间的自定义索赔提供商(我们仅使用NTLM授权(。我们正在发送这些主张:

new Claim[]
{
    new Claim("nameid", sid),
    new Claim("nii", Constants.Auth.Token.IdentityIssuer)
};

另一个发现:当一切正常工作时,请在某些REST代理中在SP Farm解决方案中执行此代码:((ClaimsIdentity)HttpContext.Current.User?.Identity).Claims.FirstOrDefault(c => c.ClaimType.EqualsIgnoreCase(ClaimTypes.Upn))返回UPN。当搜索不起作用时,相同的代码返回null ...正如我所说,我可以刷新页面,而在开始时,UPN就在那里,一段时间后,它没有...

我找到了工作。不是很好,但是我现在没有其他选择。我们已经开始对Windows代币服务索赔,如果用户对我们的应用程序提出了一些请求,我们(不时(请求将我们的自定义代理放置在SharePoint Farm解决方案中,以通过使用正常的Windows身份验证来模拟该用户使用SharePoint的模拟:

public void RefreshUpn()
{
    WindowsImpersonationContext _wic = null;
    try
    {
        string login = HttpContext.Current.User.Identity.Name;
        login = login.Substring(login.LastIndexOf('|') + 1);
        string[] loginParts = login.Split('\');
        string loginForUpnLogon = Culture.Invariant($"{loginParts[1]}@{loginParts[0]}");
        WindowsIdentity wi = S4UClient.UpnLogon(loginForUpnLogon);
        if(wi == null)
        {
            throw new InvalidOperationException(Culture.Invariant($"Could not impersonate user '{HttpContext.Current.User.Identity.Name}'."));
        }
        _wic = wi.Impersonate();
        using (var wc = new WebClient())
        {
            wc.UseDefaultCredentials = true;
            var requestUrl = HttpContext.Current.Request.Url;
            wc.DownloadString(requestUrl.Scheme + "://" + requestUrl.Host + "/_api/web/currentuser");
        }
    }
    finally
    {
        _wic?.Undo();
    }
}

在此要求之后,SharePoint在150秒左右正确响应我们。

最新更新