What is the best way to obtain the complete list of permission of a given user using AMO in C#

那年仲夏 提交于 2019-12-22 11:22:38

问题


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.

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!


回答1:


Try checking out Analysis Services Stored Procedure Project and BIDS Helper. I have not tried any of these, however, first claims

"The following commands will extract information about roles, dimension permissions, attribute permissions and cube permissions and would allow for the complete documentation of the security settings."

and the second:

"To summarize all the security permissions granted via the roles instead of having to click into dozens of screens to find this information."




回答2:


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


}


来源:https://stackoverflow.com/questions/36654105/what-is-the-best-way-to-obtain-the-complete-list-of-permission-of-a-given-user-u

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!