Problem in TFS API about member setting  
Author Message
Voltafil





PostPosted: Team Foundation Server - General, Problem in TFS API about member setting Top

I'd like to know which API can i use to set a new member id into TFS project group.

for example, i establish a TFS server "http://TFSM:8080". There is a team project "TP1". A user "voltafil" which is added into AD on TFS Server. Which API can i call to set "voltafil" as a member of TP1 Maybe set "voltafil" as a group member of "Administrator".



Visual Studio Team System33  
 
 
Naren Datha - MSFT





PostPosted: Team Foundation Server - General, Problem in TFS API about member setting Top

The tool to use is tfssecurity.exe with /g+ option. IGroupSecurityService has AddMemberToApplicationGroup method to add users to a group. You could get identity of an account using ReadIdentityFromSource method.

Here is a sample for using IGroupSecruityService and getting list of user identities in a group

IGroupSecurityService sec = (IGroupSecurityService)tfsServer.GetService(typeof(IGroupSecurityService));

TeamProject tp = tfsClient.GetTeamProject(teamProject);

Identity[] appGroups = sec.ListApplicationGroups(tp.ArtifactUri.AbsoluteUri);

foreach (Identity group in appGroups)

{

Identity[] groupMembers = sec.ReadIdentities(SearchFactor.Sid, new string[] { group.Sid }, QueryMembership.Expanded);

foreach (Identity member in groupMembers)

{

Console.WriteLine(member.DisplayName);

if (member.Members != null)

{

foreach (string memberSid in member.Members)

{

Identity memberInfo = sec.ReadIdentity(SearchFactor.Sid, memberSid, QueryMembership.None);

Console.WriteLine(" {0}", memberInfo.DisplayName);

}

}

}

}



 
 
Voltafil





PostPosted: Team Foundation Server - General, Problem in TFS API about member setting Top

Thank you for your kindly help. I can list all groups and members now.

But I don't know how to add an new account like "voltafil" into a group. Could you please give me more hints to do this Or I can only call tfssecurity.exe to set a new account in my program


 
 
Naren Datha - MSFT





PostPosted: Team Foundation Server - General, Problem in TFS API about member setting Top

As mentioned above, you can use AddMemberToApplicationGroup method of IGroupSecurityService. It takes SIDs for group and member. You can get sid for group from identity object from above sample. Below is a piece of code to get sid for an user name.

private string GetSidFromUserName(string userName)

{

NTAccount ntaccc = new NTAccount(userName);

SecurityIdentifier id = (SecurityIdentifier)ntaccc.Translate(typeof(SecurityIdentifier));

return id.ToString();

}

The names for NTAccount is System.Security.Principal



 
 
Voltafil





PostPosted: Team Foundation Server - General, Problem in TFS API about member setting Top

Hello.

Mai i ask a stupid question
Why can't i create a member group on TeamFoundationServer I used CreateApplicationGroup to create a new group, but i got an error. Is to create a group on TeamFoundationServer different from to create a group in TeamProject

Here are some code:
Dim NC As New NetworkCredential(strUserID, strPassword, strDomain)
Dim tfs As New TeamFoundationServer(strServerPath, NC)
Dim gss As IGroupSecurityService = tfs.GetService(GetType(IGroupSecurityService))
gss.CreateApplicationGroup(tfs.Uri.ToString, "TestGroup", "for test")


 
 
Naren Datha - MSFT





PostPosted: Team Foundation Server - General, Problem in TFS API about member setting Top

If you are creating a global group then project uri does not apply so try passing null for projectUri parameter (1st parameter) in CreateApplicationGroup