Get a list of tasks belonging to a role from Azman

I use AZROLESLib, which is from the COM links "azroles 1.0 Type Library", and I try to create a list of assigned tasks for each role that I set in my authorization manager, but when I go through tasks for the role, I get the role name.

I looked around, but could not find anything that could help.

Here is what I got at the moment (it's not very 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("&nbsp;&nbsp; -" + ob.ToString() + "<br />"); } } return output.ToString(); 

What comes out :

  • Administrator -Administrator

  • Account Manager -Account Manager

  • Corporate Marketing Specialist -Corporate Marketing Specialist

  • General Officer - General Employee

  • Marketing Manager - Marketing Manager

  • Regional Marketing Specialist - Regional Marketing Specialist

  • Sales Manager - Sales Manager

  • Webmaster -Webmaster

but what should happen:

  • Webmaster
    • Website Maintenance
    • News Service
    • Developments
    • Reports Read

Thanks in advance.

+4
source share
1 answer

Umm, welcome to the confusion that AzMan is :-) There are currently 3 different versions / interfaces, with two different methods that you do.

From the COM interface, stanard (IAzApplication) app.Roles refers to Role Assignments (member assigned to roles), whereas I think you want to define roles that were not presented as their own type until later version 3.

For IAzApplication: to access role definitions, you need to iterate through all applications. Set and check the task.IsRoleDefinition flag to get role definitions.

 | IAzApplication3 | IAzApplication | |---------------------|---------------------------| | app.RoleAssignments | app.Roles | | app.RoleDefinitions | app.Tasks | | | and only consider tasks: | | | task.IsRoleDefinition = 1 | 

Note. . You should also remember that what you are trying to do is not as simple in AzMan as the original code solution. Roles can consist of subordinate elements, tasks, and operations. Tasks can consist of subtasks and operations. Therefore, you really need to rewrite the roles to create a complete list of operations, tasks, and roles in each given role.

The following code will display a complete hierarchy of application role definitions for all versions of AzMan (just to imagine that it has lambda .NET feedback and is common in it, but it can be rewritten for .NET. 1.0 quite simply). The callback returns the type (role, task, operation), name and hierarchy depth (for indentation):

  private static void ProcessAzManRoleDefinitions(IAzApplication app, IAzTask task, int level, Action<string, string, int> callbackAction) { bool isRole = (task.IsRoleDefinition == 1); callbackAction((isRole ? "Role" : "Task"), task.Name, level); level++; // Iterate over any subtasks defined for this task (or role) Array tasks = (Array)task.Tasks; foreach (string taskName in tasks) { IAzTask currentTask = app.OpenTask(taskName, null); // Need to recursively process child roles and tasks ProcessAzManRoleDefinitions(app, currentTask, level, callbackAction); } // Iterate over any opeations defined for this task (or role) Array taskOperations = (Array)task.Operations; foreach (string operationName in taskOperations) callbackAction("Operation", operationName, level); } private static string GetRoleDefinitionHierarchy() { AzAuthorizationStore azManStore = new AzAuthorizationStoreClass(); azManStore.Initialize(0, "connectionstring", null); IAzApplication azApp = azManStore.OpenApplication("TestApp", null); StringBuilder output = new StringBuilder(); foreach (IAzTask task in azApp.Tasks) { if (task.IsRoleDefinition == 1) ProcessAzManRoleDefinitions(azApp, task, 0, (type, name, level) => output.Append("".PadLeft(level * 2) + type + ": " + name + "\n")); } return output.ToString(); } 

If you know that your target platform will be Windows 7, Vista or Windows Server 2008, then you should use the IAzManApplication3 interface, and this is much better defined (RoleDefinition has its own collection / type). If you are developing Windows XP, you will need to install the Windows Server 2008 administration package, and this will be associated with the updated AzMan DLL.

For AzMan v3, the following code will iterate over the hierarchy of definitions of roles, tasks, and operations (this is the equivalent of v3 of what you originally requested):

 private string GetAllRoleDefinitionHierarchies() { AzAuthorizationStore azManStore = new AzAuthorizationStoreClass(); azManStore.Initialize(0, "connectionstring", null); IAzApplication3 azApp = azManStore.OpenApplication("TestApp", null) as IAzApplication3; if (azApp == null) throw new NotSupportedException("Getting Role Definitions is not supported by older versions of AzMan COM interface"); StringBuilder output = new StringBuilder(); foreach (IAzRoleDefinition currentRoleDefinition in azApp.RoleDefinitions) { output.Append(currentRoleDefinition.Name + "<br />"); Array roleTasks = (Array) currentRoleDefinition.Tasks; foreach (string taskId in roleTasks) { IAzTask currentTask = azApp.OpenTask(taskId, null); output.Append("&nbsp;&nbsp; - Task: " + currentTask.Name + "<br />"); Array taskOperations = (Array)currentTask.Operations; foreach (string operationId in taskOperations) { IAzOperation currentOperation = azApp.OpenOperation(operationId, null); output.Append("&nbsp;&nbsp;&nbsp;&nbsp; - Operation: " + currentOperation.Name + "<br />"); } } } return output.ToString(); } 

There are no enumerations in tasks or operations, just an array of names, so if you need something other than the name you must call for App.OpenXXX () to get more information.

Hope this helps ...

+5
source

All Articles