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

折月煮酒 提交于 2019-12-06 10:39:32

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

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


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