Can we impersonate Windows user to TFS or TFS web access?

和自甴很熟 提交于 2019-12-11 03:53:59

问题


Is it possible to impersonate Windows user to TFS or TFS web access?


回答1:


Yes, it is possible. You will want to do something like this:

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;

Note that the service user must have the permissions to act on behalf of other users. Your TFSService typically has that privilege.



来源:https://stackoverflow.com/questions/15318497/can-we-impersonate-windows-user-to-tfs-or-tfs-web-access

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!