从 Azman 获取属于某个角色的任务列表

发布于 2024-08-09 04:28:50 字数 1237 浏览 8 评论 0原文

我正在使用 AZROLESLib,它来自 COM 引用“azroles 1.0 类型库”,我试图为我当前在授权管理器中设置的每个角色创建指定任务的列表,但是当我循环遍历任务时角色,我得到角色名称。

我环顾四周,但找不到任何有帮助的东西。

这是我目前得到的(它不是非常漂亮,但我只是想让它在此刻工作)。

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();

结果是

  • 管理员 -管理员

  • 客户经理 -客户经理

  • 企业营销专家 -企业营销专家

  • 普通员工 -普通员工

  • 营销经理 -营销经理

  • 区域营销专家 -区域营销专员

  • 销售经理 -销售经理

  • 网站管理员 -网站管理员

但结果应该是这样的:

  • 网站管理员
    • 网站维护
    • 新闻维护
    • 活动维护
    • 报告阅读

提前阅读致谢。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

动听の歌 2024-08-16 04:28:50

嗯,欢迎来到 AzMan 的困惑:-) 目前有 3 个不同的版本/界面,有 2 种不同的方法来完成您所要求的操作。

从标准 COM 接口 (IAzApplication) 中,app.Roles 指的是角色分配(分配给角色的成员),而我认为您想要的是角色定义,这不是'直到版本 3 稍后才作为自己的类型引入。

对于 IAzApplication:要访问角色定义,您需要迭代所有 app.Tasks 并检查 task.IsRoleDefinition 标志以获取角色定义。

| IAzApplication3     | IAzApplication            |
|---------------------|---------------------------|
| app.RoleAssignments | app.Roles                 |

| app.RoleDefinitions | app.Tasks                 |
|                     | and only consider tasks:  |
|                     | task.IsRoleDefinition = 1 |

注意: 您还应该记住,您在 AzMan 中尝试执行的操作并不像原始代码解决方案那么简单。角色可以由子角色、任务和操作组成,任务可以由子任务和操作组成。因此,您确实需要递归角色以在每个给定角色中构建操作、任务和角色的完整列表。

以下代码将输出 AzMan 所有版本的应用程序角色定义的完整层次结构(只是想知道它有一个 .NET 3.5 回调 lambda 和其中的泛型,但这可以很容易地为 .NET 1.0 重写)。回调返回类型(角色、任务、操作)、名称和层次结构深度(用于缩进):

    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();
    }

如果您知道您的目标平台将是 Windows 7、Vista 或 Windows Server 2008,那么您应该使用 IAzManApplication3 接口,这是更好的定义(RoleDefinition 有它自己的集合/类型)。如果您在 Windows XP 上进行开发,则需要安装 Windows Server 2008 Administration Pack,该管理包将附带更新的 AzMan DLL。

对于 AzMan v3,以下代码将迭代角色定义、任务和操作的层次结构(这与您最初要求的 v3 等效):

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("   - Task: " + currentTask.Name + "<br />");

            Array taskOperations = (Array)currentTask.Operations;
            foreach (string operationId in taskOperations)
            {
                IAzOperation currentOperation = azApp.OpenOperation(operationId, null);
                output.Append("     - Operation: " + currentOperation.Name + "<br />");
            }
        }
    }

    return output.ToString();
}

任务或操作没有枚举器,只有名称数组,因此如果如果您想要除名称之外的任何内容,您需要调用 App.OpenXXX() 来获取更多信息。

希望这有帮助...

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.

| IAzApplication3     | IAzApplication            |
|---------------------|---------------------------|
| app.RoleAssignments | app.Roles                 |

| app.RoleDefinitions | app.Tasks                 |
|                     | and only consider tasks:  |
|                     | task.IsRoleDefinition = 1 |

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):

    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 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):

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("   - Task: " + currentTask.Name + "<br />");

            Array taskOperations = (Array)currentTask.Operations;
            foreach (string operationId in taskOperations)
            {
                IAzOperation currentOperation = azApp.OpenOperation(operationId, null);
                output.Append("     - Operation: " + currentOperation.Name + "<br />");
            }
        }
    }

    return output.ToString();
}

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 ...

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文