/// <summary> /// Read all roles for this specific application /// </summary> /// <param name="aStoreName"></param> /// <param name="aPath"></param> /// <returns></returns> public static List <string> ReadRoles(string aStoreName) { try { AzAuthorizationStore store = new AzAuthorizationStore(); string storeLocation = GetAuthStoreLocation(aStoreName); //0 = The authorization store is opened for use by the Update method and the AccessCheck method. store.Initialize(0, storeLocation, null); List <string> roles = new List <string>(); foreach (IAzApplication3 toApplication in store.Applications) { foreach (IAzRoleDefinition role in toApplication.RoleDefinitions) { if (role.Name.StartsWith("_")) { roles.Add(role.Name.Substring(1)); } else if (role.Name.Equals("Administrator")) { roles.Add(role.Name); AzManWriter.AddAdministrator(aStoreName); } } } return(roles); } catch (COMException ce) { MessageBox.Show(null, ce.Message + "\n" + ce.ErrorCode.ToString(), "COMException occurred"); return(null); } }
private void btnDelWinUser_Click(object sender, EventArgs e) { if (!HasRoles()) { MessageBox.Show("There are no roles for this application."); } else if (GetSelectedUser().Equals(_noWinUsersString)) { MessageBox.Show("There are no users for this role."); } else { DialogResult dialogResult = MessageBox.Show("Do you really want to disconnect " + GetSelectedUser() + "?", "Disconnect Windows User from Role", MessageBoxButtons.YesNo); if (dialogResult == DialogResult.Yes) { bool success = AzManWriter.DeleteWindowsUserFromRole(GetSelectedRole(), GetSelectedApplication(), GetSelectedUser()); if (success) { PopulateWinUsersComboBox(GetSelectedApplication(), GetSelectedRole()); WinUserlistBox.SelectedIndex = 0; MessageBox.Show("user successfully disconnected!", "", MessageBoxButtons.OK); } else { MessageBox.Show("Could not delete user.", "", MessageBoxButtons.OK); } } } }
private void btnDeleteRole_Click(object sender, EventArgs e) { if (RolesComboBox.SelectedItem.ToString() != "Administrator") { if (!HasRoles()) { MessageBox.Show("There are no roles to delete for this application."); } else { DialogResult dialogResult = MessageBox.Show("Do you really want to delete " + GetSelectedRole() + "?", "Delete Role", MessageBoxButtons.YesNo); if (dialogResult == DialogResult.Yes) { bool success = AzManWriter.DeleteRole(GetSelectedRole(), GetSelectedApplication()); if (success) { PopulateRolesComboBox(GetSelectedApplication()); RolesComboBox.SelectedIndex = 0; PopulateWinUsersComboBox(GetSelectedApplication(), GetSelectedRole()); MessageBox.Show("Role successfully deleted!", "", MessageBoxButtons.OK); } else { MessageBox.Show("Could not delete role.", "", MessageBoxButtons.OK); } } } } else { MessageBox.Show("You can not delete the Administrator role.", "", MessageBoxButtons.OK); } }
private void btnCreateRole_Click(object sender, EventArgs e) { string roleName = Microsoft.VisualBasic.Interaction.InputBox("Please enter a role name", "New Role", "Role", -1, -1); if (!string.IsNullOrEmpty(roleName)) { if (roleName != "Administrator") { bool success = AzManWriter.CreateRole(roleName, GetSelectedApplication()); if (success) { PopulateRolesComboBox(GetSelectedApplication()); //Put the new role as the selected role. RolesComboBox.SelectedIndex = RolesComboBox.Items.Count - 1; MessageBox.Show("Role successfully created!", "", MessageBoxButtons.OK); } } else { MessageBox.Show("Administrator role already exist.", "", MessageBoxButtons.OK); } } AllNodescheckBox.Checked = false; ApplicationTreeView.CollapseAll(); }
private void SaveRole(string aRole, string anApplication, TreeNode aTreeNode) { List <string> selectedOperations = TreeViewToOperationsListTranslator.Translate(aTreeNode); List <string> allTreeOperations = TreeViewToOperationsListTranslator.GetAllNodeOperations(GetRootNode()); AzManWriter.SaveRole(selectedOperations, aRole, anApplication, allTreeOperations); isRoleSaved = true; }
private void btnAddWinUser_Click(object sender, EventArgs e) { if (!HasRoles()) { MessageBox.Show("There are no roles for this application."); } else { string windowsUser = Microsoft.VisualBasic.Interaction.InputBox("Please enter a Windows username", "Connect Windows User to Role", "Username", -1, -1); if (!string.IsNullOrEmpty(windowsUser)) { bool success = AzManWriter.AddWindowsUserToRole(GetSelectedRole(), GetSelectedApplication(), windowsUser); if (success) { PopulateWinUsersComboBox(GetSelectedApplication(), GetSelectedRole()); MessageBox.Show("Added " + windowsUser + " to " + GetSelectedRole() + ".", "", MessageBoxButtons.OK); } else { MessageBox.Show("Could not bind " + windowsUser + " to " + GetSelectedRole() + ". Please check so you spelled the username correctly.", "Could not add user to role", MessageBoxButtons.OK); } } } }