I'm using the AZROLESLib which is from the COM references "azroles 1.0 Type Library" and I am trying to create a list of the designated tasks for each role that I have currently set in my authorization manager but when I loop through the tasks for the role, I get the role name.
I've looked all around but couldn't find anything that would help.
Here's what I got currently (It's not super pretty but i'm just trying to get it working at the moment).
AzAuthorizationStoreClass AzManStore = new AzAuthorizationStoreClass();
AzManStore.Initialize(0, ConfigurationManager.ConnectionStrings["AzManStore"].ConnectionString, null);
IAzApplication azApp = AzManStore.OpenApplication("StoreName", null);
StringBuilder output = new StringBuilder();
Array tasks = null;
foreach (IAzRole currentRole in azApp.Roles)
{
output.Append(currentRole.Name + "<br />");
tasks = (Array)currentRole.Tasks;
foreach (object ob in tasks)
{
output.Append(" -" + ob.ToString() + "<br />");
}
}
return output.ToString();
What comes out is:
Administrator -Administrator
Account Manager -Account Manager
Corporate Marketing Specialist -Corporate Marketing Specialist
General Employee -General Employee
Marketing Manager -Marketing Manager
Regional Marketing Specialist -Regional Marketing Specialist
Sales Manager -Sales Manager
Webmaster -Webmaster
but what should come out is something like:
- Webmaster
- Websites Maintain
- News Maintain
- Events Maintain
- Reports Read
Thanks in advance.
Umm, welcome to the confusion that is AzMan :-) There are currently 3 different versions/interfaces, with 2 different methods of doing what you ask.
From the stanard COM interface (IAzApplication), app.Roles refers to Role Assignments (Member assigned to roles), whereas I think what you want are Role Definitions, which weren't introduced as their own type until later in version 3.
For IAzApplication: to access Role Definitions you need to iterate over all the app.Tasks and check the task.IsRoleDefinition flag to get the role definitions.
Note: You should also bear in mind that what you're attempting to do is not quite as simple in AzMan as your original code solution. Roles can consist of sub-Roles, Tasks and Operations, Tasks can consist of sub-Tasks and Operations .. so you really need to recurse over the roles to build up a complete list of operations, tasks and roles in each given role.
The following code will output a full hierarchy of an apps Role Definitions for all versions of AzMan (just to be fancy it's got a .NET 3.5 callback lambda and a generic in it, but this could be re-written for .NET 1.0 easy enough). The callback returns the type (Role, Task, Operation), name and the hierarchy depth (for indenting):
If you know your target platform is going to be Windows 7, Vista or Windows Server 2008 then you should be using the IAzManApplication3 interface, and this is a lot better defined (RoleDefinition has it's own collection/type). If you're developing on Windows XP, you will need to install the Windows Server 2008 Administration Pack and this will come with the updated AzMan DLL.
For AzMan v3, the following code will iterate over the hierarchy of Role Definitions, Tasks and Operations (it's the v3 equivalent of what you were asking originally):
There are no enumerators on the tasks or operations, just an array of names, so if you want anything other than the name you need to call App.OpenXXX() to get more information.
Hope this helps ...