Example #1
0
 private void PopulateWinUsersComboBox(string application, string role)
 {
     if (!role.Equals(_noRolesString))
     {
         List <string> winUsersList = new List <string>();
         winUsersList = AzManReader.ReadWinUsers(application, role);
         if (winUsersList != null)
         {
             WinUserlistBox.Items.Clear();
             WinUserlistBox.Items.AddRange(winUsersList.ToArray());
             if (winUsersList.Count == 0)
             {
                 WinUserlistBox.Items.Add(_noWinUsersString);
                 WinUserlistBox.SelectedItem = 0;
             }
             else
             {
                 WinUserlistBox.SelectedItem = WinUserlistBox.Items[0];
             }
         }
         else
         {
             WinUserlistBox.Items.Add(_noWinUsersString);
             WinUserlistBox.SelectedItem = WinUserlistBox.Items[0];
         }
     }
 }
Example #2
0
 private void btnShowUserRoles_Click(object sender, EventArgs e)
 {
     if (WinUserlistBox.SelectedItem != null)
     {
         if (WinUserlistBox.SelectedItem.ToString() != _noWinUsersString)
         {
             string        selectedUser      = WinUserlistBox.SelectedItem.ToString();
             List <string> selectedUserRoles = new List <string>();
             List <string> list = AzManReader.ReadRoles(GetSelectedApplication());
             if (list != null)
             {
                 foreach (string role in list)
                 {
                     List <string> userRoles = AzManReader.ReadUserRoles(GetSelectedApplication(), role);
                     if (userRoles != null)
                     {
                         foreach (string user in userRoles)
                         {
                             if (user.Equals(selectedUser))
                             {
                                 selectedUserRoles.Add(role);
                             }
                         }
                     }
                 }
                 var message = string.Join(Environment.NewLine, selectedUserRoles.ToArray());
                 MessageBox.Show(null, selectedUser + " belong to: \n" + message, "Show User's Roles", MessageBoxButtons.OK);
             }
             else
             {
                 MessageBox.Show("No user selected.");
             }
         }
     }
 }
Example #3
0
 internal static void AddAdministrator(string aStoreName)
 {
     try
     {
         AzAuthorizationStore store = new AzAuthorizationStore();
         string storeLocation       = AzManReader.GetAuthStoreLocation(aStoreName);
         //4 = AZ_AZSTORE_FLAG_BATCH_UPDATE
         store.Initialize(4, storeLocation, null);
         foreach (IAzApplication3 application in store.Applications)
         {
             //Create a new role assignment
             IAzRoleAssignments roleAssignments = application.RoleAssignments;
             bool hasAdministrator = false;
             foreach (IAzRoleAssignment roleassignment in roleAssignments)
             {
                 if (roleassignment.Name.Equals("Administrator"))
                 {
                     hasAdministrator = true;
                 }
             }
             if (!hasAdministrator)
             {
                 IAzRoleAssignment newRoleAssignment = application.CreateRoleAssignment("Administrator");
                 newRoleAssignment.AddRoleDefinition("Administrator");
                 newRoleAssignment.Submit();
                 application.Submit();
             }
         }
     }
     catch (COMException ce)
     {
         MessageBox.Show(null, ce.Message + "\n" + ce.ErrorCode.ToString(), "COMException occurred");
     }
 }
Example #4
0
        public static bool DeleteRole(string deleteRole, string aStoreName)
        {
            bool success = false;

            try
            {
                AzAuthorizationStore store = new AzAuthorizationStore();

                string storeLocation = AzManReader.GetAuthStoreLocation(aStoreName);
                string roleName      = "_" + deleteRole;
                //4 = AZ_AZSTORE_FLAG_BATCH_UPDATE
                store.Initialize(4, storeLocation, null);
                foreach (IAzApplication3 application in store.Applications)
                {
                    //Delete role assignment
                    application.DeleteRoleAssignment(roleName);
                    //Delete role definition
                    application.DeleteRoleDefinition(roleName);
                    application.Submit();
                }
                success = true;
            }
            catch (COMException ce)
            {
                MessageBox.Show(null, ce.Message + "\n" + ce.ErrorCode.ToString(), "COMException occurred");
            }
            catch (Exception)
            {
                success = false;
            }
            return(success);
        }
Example #5
0
        public static bool DeleteWindowsUserFromRole(string role, string aStoreName, string windowsUser)
        {
            bool success;

            try
            {
                AzAuthorizationStore store = new AzAuthorizationStore();

                string storeLocation = AzManReader.GetAuthStoreLocation(aStoreName);
                if (role != "Administrator")
                {
                    role = "_" + role;
                }
                //4 = AZ_AZSTORE_FLAG_BATCH_UPDATE
                store.Initialize(4, storeLocation, null);
                foreach (IAzApplication3 application in store.Applications)
                {
                    IAzRole iAzRole = application.OpenRole(role);
                    iAzRole.DeleteMemberName(windowsUser);
                    iAzRole.Submit();
                    application.Submit();
                }
                success = true;
            }

            catch (Exception)
            {
                success = false;
            }
            return(success);
        }
Example #6
0
        public static bool AddWindowsUserToRole(string role, string aStoreName, string windowsUser)
        {
            bool success = false;

            try
            {
                AzAuthorizationStore store = new AzAuthorizationStore();

                string storeLocation = AzManReader.GetAuthStoreLocation(aStoreName);
                if (role != "Administrator")
                {
                    role = "_" + role;
                }
                //4 = AZ_AZSTORE_FLAG_BATCH_UPDATE
                store.Initialize(4, storeLocation, null);
                foreach (IAzApplication3 application in store.Applications)
                {
                    IAzRole iAzRole = application.OpenRole(role);
                    iAzRole.AddMemberName(windowsUser);
                    iAzRole.Submit();
                    application.Submit();
                }
                success = true;
            }
            catch (COMException ce)
            {
                MessageBox.Show(null, ce.Message + "\n" + ce.ErrorCode.ToString(), "COMException occurred");
            }
            catch (Exception)
            {
                success = false;
            }
            return(success);
        }
Example #7
0
        public static bool CreateRole(string role, string aStoreName)
        {
            bool success = false;

            try
            {
                AzAuthorizationStore store = new AzAuthorizationStore();

                string storeLocation = AzManReader.GetAuthStoreLocation(aStoreName);
                string roleName      = "_" + role;
                //4 = AZ_AZSTORE_FLAG_BATCH_UPDATE
                store.Initialize(4, storeLocation, null);
                foreach (IAzApplication3 application in store.Applications)
                {
                    //Create a new role definition
                    IAzRoleDefinition newRole = application.CreateRoleDefinition(roleName);
                    //Create a new role assignment
                    IAzRoleAssignment newRoleAssignment = application.CreateRoleAssignment(roleName);

                    newRole.Submit();
                    newRoleAssignment.AddRoleDefinition(roleName);
                    newRoleAssignment.Submit();
                    application.Submit();
                }
                success = true;
            }
            catch (COMException ce)
            {
                if (ce.ErrorCode.Equals(-2147024713))
                {
                    MessageBox.Show(null, "Role already exist in this application.", "Role already exist");
                }
                else
                {
                    MessageBox.Show(null, ce.Message + "\n" + ce.ErrorCode.ToString(), "COMException occurred");
                }
            }
            catch (Exception ex)
            {
                if (ex is UnauthorizedAccessException)
                {
                    MessageBox.Show("Access denied to " + aStoreName + "AuthStore.xml. Maybe it is read-only?", "", MessageBoxButtons.OK);
                }
                else
                {
                    MessageBox.Show("Could not create role. Maybe it already exists?", "", MessageBoxButtons.OK);
                }
                success = false;
            }
            return(success);
        }
Example #8
0
        private void PopulateRolesComboBox(string anApplication)
        {
            List <string> rolesList = new List <string>();

            rolesList = AzManReader.ReadRoles(anApplication);
            if (rolesList != null)
            {
                RolesComboBox.Items.Clear();
                RolesComboBox.Items.AddRange((rolesList.ToArray()));
                if (rolesList.Count == 0)
                {
                    RolesComboBox.Items.Add(_noRolesString);
                    RolesComboBox.SelectedItem = 0;
                }
                else
                {
                }
            }
        }
Example #9
0
        private void LoadRoleActionsIntoTreeNode(TreeNode aTreeNode)
        {
            string currentRole;

            if (RolesComboBox.SelectedItem == null)
            {
                currentRole = RolesComboBox.Items[0].ToString();
            }
            else
            {
                currentRole = GetSelectedRole();
            }
            List <string> operationsList = AzManReader.ReadOperationsRole(GetSelectedApplication(), currentRole);

            if (operationsList != null)
            {
                OperationLoader.LoadIntoTreeNode(aTreeNode, operationsList);
            }
            List <string> allTreeOperations = TreeViewToOperationsListTranslator.GetAllNodeOperations(GetRootNode());

            duplicateKeys = allTreeOperations.GroupBy(x => x).Where(group => group.Count() > 1).Select(group => group.Key).ToList();
        }
Example #10
0
        public static void SaveRole(List <string> anOperations, string aRole, string aStoreName, List <string> allTreeOperations)
        {
            try
            {
                //Make sure all operations exist in Azman
                List <string> allOperations      = AzManReader.ReadOperations(aStoreName);
                List <string> excludedOperations = new List <string>();
                if (allOperations != null)
                {
                    List <string> addOperations = new List <string>();
                    foreach (string operation in anOperations)
                    {
                        if (allOperations.Contains(operation))
                        {
                            addOperations.Add(operation);
                        }
                    }
                    foreach (string operation in allOperations)
                    {
                        if (!allTreeOperations.Contains(operation))
                        {
                            excludedOperations.Add(operation);
                        }
                    }

                    //read OK and Cancel operations
                    List <string> oKAndCancelOperations = AzManReader.ReadOkCancelAndCloseOperations(aStoreName);
                    if (oKAndCancelOperations != null)
                    {
                        foreach (string operation in allOperations)
                        {
                            if (oKAndCancelOperations.Contains(operation))
                            {
                                excludedOperations.Remove(operation);
                            }
                        }
                        addOperations.AddRange(excludedOperations);

                        //save down the operations into the role in AuthStore
                        AzAuthorizationStore store = new AzAuthorizationStore();

                        string storeLocation = AzManReader.GetAuthStoreLocation(aStoreName);
                        string roleName      = "_" + aRole;
                        //4 = AZ_AZSTORE_FLAG_BATCH_UPDATE
                        store.Initialize(4, storeLocation, null);

                        foreach (IAzApplication3 application in store.Applications)
                        {
                            foreach (IAzRoleDefinition role in application.RoleDefinitions)
                            {
                                if (role.Name != roleName)
                                {
                                    continue;
                                }
                                //remove all existing operations in the role
                                foreach (string operation in role.Operations)
                                {
                                    role.DeleteOperation(operation);
                                }
                                //Role needs to be submitted after deleting operations otherwise Azman freaks out
                                role.Submit();
                                //Save all selected operations to the role
                                foreach (string operationString in addOperations)
                                {
                                    role.AddOperation(operationString);
                                }
                                foreach (string oKOrCancelOperation in oKAndCancelOperations)
                                {
                                    role.AddOperation(oKOrCancelOperation);
                                }
                                //Submit role so changes are saved
                                role.Submit();
                                MessageBox.Show("Setting for " + aRole + " has been saved.", "Role Settings Saved", MessageBoxButtons.OK);
                            }
                            //Submit everything just to be sure
                            application.Submit();
                        }
                        store.Submit();
                    }
                }
            }
            catch (COMException ce)
            {
                MessageBox.Show(null, ce.Message + "\n" + ce.ErrorCode.ToString(), "COMException occurred");
            }
            catch (Exception ex)
            {
                if (ex is UnauthorizedAccessException)
                {
                    MessageBox.Show("Access denied to " + aStoreName + "AuthStore.xml. Maybe it is read-only?", "", MessageBoxButtons.OK);
                }
                else
                {
                    MessageBox.Show("Failed to save configuration", "", MessageBoxButtons.OK);
                }
            }
        }