2

是否可以模拟 Windows 用户进行 TFS 或 TFS Web 访问?

4

1 回答 1

1

对的,这是可能的。你会想做这样的事情:

NetworkCredential serviceUser = new NetworkCredential(username, password, domain);
ICredentialsProvider TfsProxyCredentials = new NetworkCredentialsProvider(serviceUser);
Uri tpcUri = new Uri("http://yourserver:8080/tfs/yourCollectionName");
TfsTeamProjectCollection tpc = new TfsTeamProjectCollection(tpcUri, serviceUser);

// Get the TFS identity management service
IIdentityManagementService ims = tpc.GetService<IIdentityManagementService>();

// Look up the user that we want to impersonate
TeamFoundationIdentity identity = ims.ReadIdentity(IdentitySearchFactor.AccountService, userToImpersonate, MembershipQuery.None, ReadIdentityOptions.None);

TfsTeamProjectCollection impersonatedCollection = new TfsTeamProjectCollection(tpcUri, serviceUser, TfsProxyCredentials, identity.Descriptor);

return impersonatedCollection;

请注意,服务用户必须具有代表其他用户执行操作的权限。您的TFSService通常具有该特权。

于 2013-03-10T07:30:45.000 回答