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

Shivalik Chakravarty

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.

Shivalik Chakravarty

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


}

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

What is the best way to find length of split characters from the given string by using String.Split() Method or Linq Lambda Expression in C#

From Java

What would be the best way to define a gatling a user flow using ChainBuilder?

From Dev

What is the best way to add a new user using the command line?

From Dev

What is the best way to add a new user using the command line?

From Dev

In C#, What is the best way to see if a list contains another list?

From Dev

PowerShell: What is the best way to check whether the current user has permission to overwrite a file in PowerShell?

From Dev

What is the best way of using Arrays.asList() to initialize a List

From Dev

What is the best way to categorize/group and sort a list of elements using javascript?

From Dev

What is the best way to center list items using bootstrap?

From Dev

What's the best way to organize a display list using AS3?

From Dev

What is the best way to set the followers list using parse.com

From Dev

What is the best way to categorize/group and sort a list of elements using javascript?

From Dev

What is the best way to implement promise in the given scenario?

From Dev

What is the best way to trim a list?

From Dev

What is the best way to trim a list?

From Dev

In C#, what is the best way to group consecutive dates in a list?

From Dev

C# - What is the best way to serialize list of objects to files?

From Dev

What is the best way to retrieve the count of users with complete and incomplete profiles using spring boot and mongodb?

From Dev

What is the best way to find the nearest lesser and greater values in a list to a given number

From Dev

Given a list of ids, what's the best way to query which ids do not exist in the collection?

From Dev

What is the best way to find the nearest lesser and greater values in a list to a given number

From Dev

What is the best way for using PayPal adaptive payment API with C++?

From Dev

What is best way to calculate roots using recursion | C#

From Dev

What is the best way to generate all binary strings of the given length in Python using Recursion?

From Dev

What is the best way to search a List<List<string>>?

From Dev

What is the best way to implement user account activation?

From Dev

What is the best way to store a user feature?

From Dev

What is the best way to safely read user input?

From Dev

What is the best way to store user notifications in MySQL?

Related Related

  1. 1

    What is the best way to find length of split characters from the given string by using String.Split() Method or Linq Lambda Expression in C#

  2. 2

    What would be the best way to define a gatling a user flow using ChainBuilder?

  3. 3

    What is the best way to add a new user using the command line?

  4. 4

    What is the best way to add a new user using the command line?

  5. 5

    In C#, What is the best way to see if a list contains another list?

  6. 6

    PowerShell: What is the best way to check whether the current user has permission to overwrite a file in PowerShell?

  7. 7

    What is the best way of using Arrays.asList() to initialize a List

  8. 8

    What is the best way to categorize/group and sort a list of elements using javascript?

  9. 9

    What is the best way to center list items using bootstrap?

  10. 10

    What's the best way to organize a display list using AS3?

  11. 11

    What is the best way to set the followers list using parse.com

  12. 12

    What is the best way to categorize/group and sort a list of elements using javascript?

  13. 13

    What is the best way to implement promise in the given scenario?

  14. 14

    What is the best way to trim a list?

  15. 15

    What is the best way to trim a list?

  16. 16

    In C#, what is the best way to group consecutive dates in a list?

  17. 17

    C# - What is the best way to serialize list of objects to files?

  18. 18

    What is the best way to retrieve the count of users with complete and incomplete profiles using spring boot and mongodb?

  19. 19

    What is the best way to find the nearest lesser and greater values in a list to a given number

  20. 20

    Given a list of ids, what's the best way to query which ids do not exist in the collection?

  21. 21

    What is the best way to find the nearest lesser and greater values in a list to a given number

  22. 22

    What is the best way for using PayPal adaptive payment API with C++?

  23. 23

    What is best way to calculate roots using recursion | C#

  24. 24

    What is the best way to generate all binary strings of the given length in Python using Recursion?

  25. 25

    What is the best way to search a List<List<string>>?

  26. 26

    What is the best way to implement user account activation?

  27. 27

    What is the best way to store a user feature?

  28. 28

    What is the best way to safely read user input?

  29. 29

    What is the best way to store user notifications in MySQL?

HotTag

Archive