在C#中使用AMO获取给定用户的完整权限列表的最佳方法是什么 [英] What is the best way to obtain the complete list of permission of a given user using AMO in C#
问题描述
我正在使用Visual Studio 2013(C#)和SSAS 2014(通过AMO).我需要在SSAS数据库中准备给定用户的权限列表.例如,domainName \ userName拥有数据库中可用的5个维度中的2个的权限.我喜欢准备这样的清单.
I am using Visual Studio 2013(C#) and SSAS 2014 (through AMO). I need to prepare a list of permissions of a given user in the SSAS database. For example, domainName\userName has permissions on the 2 dimensions out of 5 available in the database. I like to prepare a list like this.
维度名称|属性|多维数据集中使用的尺寸VisualTotal | Mdx集(如果有)|角色名称
Dimension Name | Attributes | Dimension used in Cube | VisualTotal | Mdx Set (if any) | Role Name
我可以遍历角色和成员并获取一些信息.但是,这似乎是一个遥不可及的过程,并且在生产环境中对性能不友好.任何建议都将不胜感激!
I can loop through Roles and members and get some information. But it seems that it is a long shot and will not be performance friendly in the production environment. Any advice is much appreciated!
推荐答案
最后,我能够使用AMO实现此目的.这是我为解决此问题所做的工作. 以下是代码片段,以查找一个用户在给定的SSAS数据库中拥有的权限列表.然后将该结果加载到假设的数据表中.我希望这将有助于其他试图找到类似解决方案的人.
Finally I am able to achieve this using AMO. Here is what I did to solve this. Following is the code snipped to find out the list of permissions one user has in a given SSAS database. This result is then loaded into a hypothetical DataTable. I hope this will help others trying to find out a similar solution.
using (Server Srv = new Server())
{
Srv.Connect("\\serverName\instanceName");
Database d = Srv.Databases.FindByName("My SSAS DB");
foreach (Role r in d.Roles)
{
foreach (RoleMember m in r.Members)
{
if (string.Compare(m.Name, "domainName\userName", StringComparison.InvariantCultureIgnoreCase) == 0)
{
foreach (Cube c in d.Cubes)
{
CubePermission cp = c.CubePermissions.FindByRole(r.ID);
if(!(cp == null))
{
foreach(CubeDimensionPermission cdimPerm in cp.DimensionPermissions)
{
foreach(AttributePermission attPerm in cdimPerm.AttributePermissions)
{
DataRow dr = dt.NewRow();
dr["Database Name"] = d.Name;
dr["Role Name"] = r.Name;
dr["Dimension Name"] = cdimPerm.CubeDimension.Name;
dr["Cube Name"] = c.Name;
dr["Attribute Name"] = attPerm.Attribute.Name;
dr["AllowedSet"] = attPerm.AllowedSet;
dr["DeniedSet"] = attPerm.DeniedSet;
dr["DefaultMember"] = attPerm.DefaultMember;
dr["VisualTotals"] = attPerm.VisualTotals;
dt.Rows.Add(dr);
}
}
}
}
}
}
}
Srv.Disconnect();
}
这篇关于在C#中使用AMO获取给定用户的完整权限列表的最佳方法是什么的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!