비밀번호를 제공하지 않고 SharePoint에서 가장 한 검색을 수행 할 수 있습니까?
-
06-07-2019 - |
문제
나는 다음과 같은 일을함으로써 과거에 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'
}
}
이는 가장 한 사용자의 비밀번호가 필요하지 않지만 특정 코드 액세스 보안이 실행되기 위해서는 필요합니다. 부수적으로 보증자 호출은 현재 사용자가 관리자가되어야하지만, 보장 사용자 대신에 사용할 수있는 다른 방법이 있습니다 (이 질문에 대한 내 코드 조각을 간단하게 유지하려고합니다).
이제 무대를 설정 했으니 ... 이제 MOSS 또는 WSS 쿼리 엔진에 대해 FullTextSqlQuery 또는 KeywordQuery를 수행하고 가장 한 사용자를 기반으로 보안을 얻고 싶습니다. 두 객체 모두 생성자에서 SPSITE를 취할 수 있지만 내 사망자 논리를 무시합니다. 대신 로그인 한 사용자와 함께 사용합니다 (httpcontext.current.user).
다른 생성자도 있습니다 : 애플리케이션 이름 (문자열)과 Moss의 경우 SSP에 ServerContext가있는 것이 있지만 전혀 도움이되지 않을 것이라고 생각합니다.
KeywordQuery 클래스와 기본 쿼리 클래스에서 반사판을 사용했으며 매우 빠르게 꽤 빠릅니다. 사용자를 결정하는 실제 논리가 관리되지 않는 코드로 다운되어 있다고 생각합니다.
그래서, 내가 이것을 할 수 있습니까?
해결책 2
당신이 밝혀졌습니다 ~할 수 있다 비밀번호없이 SharePoint에서 가장하는 검색을 수행하십시오. 우리는 이것을 2009 년 8 월에 다시 알아 냈으며 답으로 스택 오버플로를 업데이트하는 데 해고되었습니다.
보다 http://wiki.threewill.com/display/is/2010/06/18/connect++sharepoint+-+ forwarding+user+ 딜리티 세부 사항은 특별한 요구 사항에 특별한주의를 기울입니다. 이것은 SharePoint 2007과 SharePoint 2010과 함께 작동합니다.
모든 일을 해낸 동료 인 에릭 보우 덴에게 감사드립니다!
다른 팁
이 작업을 수행하려면 실제 창립기가 필요합니다. SPSITE 가장 인신은 실제 사칭이 아닙니다. 단지 WSS 객체 모델에 콘텐츠 데이터베이스의 생성 및 수정 된 필드에 다른 사용자 ID를 작성하도록 지시합니다.
Windows Missernation의 경우 불행히도 애플리케이션 풀 계정을 사용하지 않는 한 로그인과 비밀번호가 모두 필요합니다. spsecurity.runwithelevatedPrivileges
다음과 같이 Windows 가장를 구현할 수 있습니다.
using (Impersonator imp = new Impersonator("user", "domain", "password"))
{
// Do stuff impersonated
}
사망자 클래스가 구현되는 경우 :
public sealed class Impersonator : IDisposable
{
private WindowsImpersonationContext impersonationContext;
public Impersonator(string user, string domain, string password)
{
WindowsIdentity id = Logon(user, domain, password);
impersonationContext = id.Impersonate();
}
public void Dispose()
{
if (impersonationContext != null)
{
impersonationContext.Undo();
impersonationContext = null;
}
}
private WindowsIdentity Logon(string user, string domain, string password)
{
WindowsIdentity identity;
IntPtr handle = IntPtr.Zero;
bool logonSucceeded = LogonUser(
user, domain, password,
8, // LOGON32_LOGON_NETWORK_CLEARTEXT
0, // LOGON32_PROVIDER_DEFAULT
ref handle);
if (!logonSucceeded)
{
int errorCode = Marshal.GetLastWin32Error();
throw new UnauthorizedAccessException("User logon failed. Error Number: " + errorCode);
}
identity = new WindowsIdentity(handle);
CloseHandle(handle);
return identity;
}
[DllImport("advapi32.dll", SetLastError = true)]
private static extern bool LogonUser(string lpszUsername,
string lpszDomain,
string lpszPassword,
int dwLogonType,
int dwLogonProvider,
ref IntPtr phToken);
[DllImport("kernel32.dll", CharSet = CharSet.Auto)]
private static extern bool CloseHandle(IntPtr handle);
}
실제로 객체 모델을 사용하여 검색을 수행 할 때 가장하는 또 다른 방법이 있습니다. 나는 고가의 권한과 함께 달릴 때 가장하는 데있어서 일을 할 수있었습니다. 여기 내 게시물을 참조하십시오. http://vishalseth.com/post/2013/11/05/impersonated-searching-against-sharepoint.aspx