您是否可以在不提供密码的情况下在SharePoint中执行模拟搜索?

Kir*_*ohn 6 sharepoint impersonation search

我过去通过执行以下操作在SharePoint中进行了很多模仿.

SPWeb web = SPContext.Current.Web;
string currentWebUrl = web.Url;
SPUser user = web.EnsureUser(loginToImpersonate);
using (SPSite site = new SPSite(currentWebUrl, user.UserToken)
{
    using (SPWeb impersonatedWeb = site.OpenWeb())
    {
        // Any SharePoint access here to 'impersonatedWeb'
        // is impersonated as 'loginToImpersonate'
    }
}
Run Code Online (Sandbox Code Playgroud)

请注意,这不需要您模拟的用户的密码,但需要运行某些代码访问安全性.另请注意,EnsureUser调用还要求当前用户为admin,但还有其他方法可用于代替EnsureUser来获取SPUser对象(尝试保持我的代码片段对于此问题简单).

现在我已经设置了阶段...我现在想要针对MOSS或WSS查询引擎执行FullTextSQLQuery或KeywordQuery,并根据模拟用户获取安全修整结果.两个对象都可以在构造函数上使用SPSite,但忽略我的模拟逻辑.它们与当前登录的用户一起使用(HTTPContext.Current.User).

还有其他构造函数:应用程序名称(字符串),对于MOSS,有一个带有ServerContext的SSP,但我不认为这些会有所帮助.

我在KeywordQuery类及其基类Query类上使用了Reflector,它非常难看.我相信确定用户的实际逻辑是非托管代码.

那么,我可以这样做吗?

Kir*_*ohn 1

事实证明,您无需密码即可在 SharePoint 中进行模拟搜索。我们早在 2009 年 8 月就发现了这个问题,但我在更新 Stack Overflow 时疏忽了答案。

详细信息请参见http://wiki. Threewill.com/display/is/2010/06/18/Connect+to+SharePoint+-+Forwarding+User+Identities,并特别注意特殊要求。请注意,这适用于 SharePoint 2007 和 SharePoint 2010。

非常感谢我的同事 Eric Bowden 完成了所有工作!