TFS API Part 11: Get Area/Iteration Security Settings Using IAuthorizationService

02/02/2009

no comments

TFS API Part 11: Get Area/Iteration Security Settings Using IAuthorizationService

In the previous post TFS API Part 9: Get Area/Iteration Programmatically I talked about how to get Area/Iteration nodes from TFS.

In this post I’ll show to get Area/Iteration security settings using TFS IAuthorizationService.

 image

Download Demo

First add reference for Microsoft.TeamFoundation, Microsoft.TeamFoundation.Client, Microsoft.TeamFoundation.Common.dll,Microsoft.TeamFoundation.WorkItemTracking.Client.dll
located in – C:\Program Files\Microsoft Visual Studio 9.0\Common7\IDE\PrivateAssemblies\

Add using for:

using Microsoft.TeamFoundation.Proxy;

using Microsoft.TeamFoundation.Server;

using Microsoft.TeamFoundation.Client;

Download Demo

Get Node Path

XmlNode Node = tree.ChildNodes[0].ChildNodes[i];

NodeItem nodeitem = new NodeItem(Node.Attributes["Name"].Value,

    Node.Attributes["NodeID"].Value, type);

 

if (type == StructureType.Area)

    list_area.Items.Add(nodeitem);

else

    list_iteration.Items.Add(nodeitem);

 

I made a NodeItem to collect Node Path for each from TFS.

 

public class NodeItem

{

    public string Name { get; set; }

    public string Uri { get; set; }

    public Get_Area_Iteration_Security.Window1.StructureType Structure { get; set; }

 

    public NodeItem(string name, string uri, Get_Area_Iteration_Security.Window1.StructureType structure)

    {

        this.Name = name;

        this.Uri = uri;

        this.Structure = structure;

    }

 

    public override string ToString()

    {

        return Name;

    }

}

 

Using IAuthorizationService to get AccessControlEntry by NodePath

 

public static AccessControlEntry[] GetAccessControl(TeamFoundationServer tfs, string nodeuri)

{

    IAuthorizationService auth = (IAuthorizationService)tfs.GetService(typeof(IAuthorizationService));

    AccessControlEntry[] auth_list = auth.ReadAccessControlList(nodeuri);

    return auth_list;

}

 

Selecting specific Node and write Security

 

NodeItem item = (NodeItem)list_area.SelectedItem;

 

AccessControlEntry[] list = AccessControl.GetAccessControl(server, item.Uri);

StringBuilder sb = new StringBuilder();

foreach (AccessControlEntry entry in list)

{

    sb.AppendLine(entry.ActionId + "=" + entry.Deny.ToString());

}

 

MessageBox.Show(sb.ToString(), "Security", MessageBoxButton.OK, MessageBoxImage.Information);

 

image

Download Demo

Add comment
facebook linkedin twitter email

Leave a Reply