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