광고 정보 사용자 권한을 요청하는 .NET 웹 서비스의 웹 메서드와 관련하여 이상한 "버그"에 많은 시간을 보냈습니다.셰어 포인트 RunWithElevatedPrivileges 대 가장
좋은 소식은 버그를 수정했지만 왜 수정이 효과적인 지 이해할 수 있습니다.
버그와 웹 방법은 다음
public bool ValidateTask(string originatingUser)
{
SPUserToken userToken = null;
// get the System account for impersonation
string userToken = site.SystemAccount.UserToken;
using (SPSite rootSite = new SPSite(site.ID, userToken))
{
using (SPWeb web = rootSite.OpenWeb())
{
// get the domain name of the application pool of the web app
string servicesDomain =
StringUtilities.GetDomain(site.WebApplication.ApplicationPool.ManagedAccount.Username);
// get the domain name of the user
string accountsDomain = StringUtilities.GetDomain(originatingUser);
PrincipalContext ServicesDomainContext =
new PrincipalContext(ContextType.Domain, servicesDomain);
PrincipalContext AccountsDomainContext =
new PrincipalContext(ContextType.Domain, accountsDomain);
// COMException when the FindByIdentity is called because
// AccountsDomainContext.connectedServer throw exception
using (UserPrincipal usr =
UserPrincipal.FindByIdentity(AccountsDomainContext, IdentityType.SamAccountName, originatingUser))
{
// get user groups memberships
}
}
// check groups memberships and return the true or false
}
}
보정하여 웹 방법은 다음과 같다 :
======== ========================================================================================================== =================
나는 셰어 포인트에서 Imperso 국가와 RunWithElevatedPrivilege는 동일한 결과를 생성합니다. 내 질문에 대답 :
1- 그래서 RunWithElevatedPrivilege가 작동하는 이유는 무엇입니까?
2 WebMethod 컨텍스트에서 권한을 상승시킬 때 자격 증명은 무엇입니까? 이것은 SharePoint 웹 서비스 루트의 ID 풀 계정입니까?
3 우리는 2 가지 방법의 자격 증명을 추적 할 수 있습니까?
Thx. 내 asmx 파일은 template \ layouts 폴더에 있고 dll은 GAC에 있습니다. 사용자 토큰은 "sharepoint \ system"계정입니다. 그러나 새로운 SPSite (siteId, usertoken)로 가장 할 때 셰어 포인트 컨텍스트에서 완전한 권한을 가지지 만 AD (또는 파일 시스템)에서 쿼리를 실행하면 WindowsIdentity는 여전히 웹 서비스를 호출하는 현재 사용자입니다. 그 이유는 RunWithElevatedPrivileges가 ApplicationPoolidentity가있는 새 스레드로 인해 더욱 강력해진 이유입니다. – user1380787