Kuldeep Shige
Kuldeep Shige

Reputation: 453

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

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

Upvotes: 2

Views: 448

Answers (1)

Assaf Stone
Assaf Stone

Reputation: 6317

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.

Upvotes: 1

Related Questions