【发布时间】:2012-01-11 16:17:54
【问题描述】:
我试图通过模拟用户在 TFS2010 中创建一个错误,但总是得到
"TF30063 You are not authorized to access.."
我首先使用服务帐户进行身份验证,然后尝试模拟一个单独的用户帐户。我可以使用任一帐户以编程方式和在 Web UI 中成功创建工作项。但是,当我尝试使用模拟帐户(无论哪种方式)创建工作项时,我总是会收到此错误。我的代码是:
public int Save(List<KeyValuePair<string, string>> values, ticketType type,string user)
{
// get the Uri to the project collection to use
Uri tfsuri = new Uri("http://94.23.12.119:8085/tfs");
// get a reference to the team project collection (authenticate as generic service account)
using (var tfs = new TfsTeamProjectCollection(tfsuri, new System.Net.NetworkCredential("username", "password", "servername")))
{
tfs.EnsureAuthenticated();
//Now get the details of the user we want to impersonate
TeamFoundationIdentity identity = GetImpersonatedIdentity(tfsuri,tfs,user);
//Now connect as the impersonated user
using (TfsTeamProjectCollection ImpersonatedTFS = new TfsTeamProjectCollection(tfsuri, identity.Descriptor))
{
ImpersonatedTFS.EnsureAuthenticated();
var workItemStore = GetWorkItemStore(ImpersonatedTFS);
// create a new work item
WorkItem wi = new WorkItem(GetWorkItemType(type, workItemStore));
{
//Values are supplied as a KVP - Field Name/Value
foreach (KeyValuePair<string,string> kvp in values)
{
if (wi.Fields.Contains(kvp.Key))
{
wi.Fields[kvp.Key].Value = kvp.Value;
}
}
ValidationResult = wi.Validate();
}
if (ValidationResult.Count == 0)
{
wi.Save();
return wi.Id;
}
else
{
return 0;
}
}
}
}
成功获取了冒充身份,但失败了
ImpersonatedTFS.EnsureAuthenticated();
两个帐户都具有“代表他人提出请求”权限集。
【问题讨论】:
-
你要跳多少跳才能到达 tfs?在多个节点 X->Y->Z 的情况下,框 Y 上的服务可能能够模拟框 X 上的调用者的 ID。但是,它可能无权将该模拟传递给另一个上的服务框 Z。
-
据我所知只有一跳。
标签: c# tfs impersonation