从 Azman 获取属于某个角色的任务列表
我正在使用 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(" -" + 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
-AdministratorAccount Manager
-Account ManagerCorporate Marketing Specialist
-Corporate Marketing SpecialistGeneral Employee
-General EmployeeMarketing Manager
-Marketing ManagerRegional Marketing Specialist
-Regional Marketing SpecialistSales Manager
-Sales ManagerWebmaster
-Webmaster
but what should come out is something like:
- Webmaster
- Websites Maintain
- News Maintain
- Events Maintain
- Reports Read
Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
嗯,欢迎来到 AzMan 的困惑:-) 目前有 3 个不同的版本/界面,有 2 种不同的方法来完成您所要求的操作。
从标准 COM 接口 (IAzApplication) 中,app.Roles 指的是角色分配(分配给角色的成员),而我认为您想要的是角色定义,这不是'直到版本 3 稍后才作为自己的类型引入。
对于 IAzApplication:要访问角色定义,您需要迭代所有 app.Tasks 并检查 task.IsRoleDefinition 标志以获取角色定义。
注意: 您还应该记住,您在 AzMan 中尝试执行的操作并不像原始代码解决方案那么简单。角色可以由子角色、任务和操作组成,任务可以由子任务和操作组成。因此,您确实需要递归角色以在每个给定角色中构建操作、任务和角色的完整列表。
以下代码将输出 AzMan 所有版本的应用程序角色定义的完整层次结构(只是想知道它有一个 .NET 3.5 回调 lambda 和其中的泛型,但这可以很容易地为 .NET 1.0 重写)。回调返回类型(角色、任务、操作)、名称和层次结构深度(用于缩进):
如果您知道您的目标平台将是 Windows 7、Vista 或 Windows Server 2008,那么您应该使用 IAzManApplication3 接口,这是更好的定义(RoleDefinition 有它自己的集合/类型)。如果您在 Windows XP 上进行开发,则需要安装 Windows Server 2008 Administration Pack,该管理包将附带更新的 AzMan DLL。
对于 AzMan v3,以下代码将迭代角色定义、任务和操作的层次结构(这与您最初要求的 v3 等效):
任务或操作没有枚举器,只有名称数组,因此如果如果您想要除名称之外的任何内容,您需要调用 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.
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 ...