private void ReplacePrivileges(string name, IList <Privilege> privileges)
        {
            // Find grants.
            List <Privilege> grants = new List <Privilege>();

            foreach (Privilege privilege in privileges)
            {
                if (!FindRole(oldPrivileges, privilege))
                {
                    grants.Add(privilege);
                }
            }

            // Find revokes.
            List <Privilege> revokes = new List <Privilege>();

            foreach (Privilege oldPrivilege in oldPrivileges)
            {
                if (!FindRole(privileges, oldPrivilege))
                {
                    revokes.Add(oldPrivilege);
                }
            }

            if (grants.Count > 0)
            {
                client.GrantPrivileges(null, name, grants);
            }

            if (revokes.Count > 0)
            {
                client.RevokePrivileges(null, name, revokes);
            }
        }
Beispiel #2
0
        public void grantPrivilege()
        {
            // Get role
            Console.WriteLine("\nEnter role:");
            String roleName = Console.ReadLine();
            int    privilegeCode;

            if (roleName != null && roleName.Length > 0)
            {
                // Get new privilege
                Console.WriteLine("Enter a privilege code\n(0 = read, 1 = read-write, 2 = read-write-udf, 4 = sys-admin, 5 = user-admin):");
                privilegeCode = int.Parse(Console.ReadLine());
                Privilege privilege = new Privilege();
                switch (privilegeCode)
                {
                case 0: privilege.code = PrivilegeCode.READ; break;

                case 1: privilege.code = PrivilegeCode.READ_WRITE; break;

                case 2: privilege.code = PrivilegeCode.READ_WRITE_UDF; break;

                //MISSING FROM API! case 3: privilege.code = PrivilegeCode.DATA_ADMIN; break;
                case 4: privilege.code = PrivilegeCode.SYS_ADMIN; break;

                case 5: privilege.code = PrivilegeCode.USER_ADMIN; break;
                }

                AdminPolicy adminPolicy = new AdminPolicy();
                Privilege[] privileges  = { privilege };

                client.GrantPrivileges(adminPolicy, roleName, privileges);
                Console.WriteLine("\nINFO: The privilege has been added to: " + roleName);
            }
            else
            {
                Console.WriteLine("ERROR: Role not found!");
            }
        }