public AuthorizationDialog(string url, string application, string user) : this()
        {
            m_Url = url;
            m_ApplicationTextBox.Text = application;
            m_UserComboBox.Text       = user;

            IRoleManager roleManager = UserManagerProviderFactory.CreateRoleManager();

            string[] roles = roleManager.GetRolesForUser(application, user);

            m_RoleComboBox.Items.AddRange(roles);
            if (roles.Length > 0)
            {
                m_RoleComboBox.Text = roles[roles.Length - 1];
            }

            IMembershipManager membershipManager = roleManager as IMembershipManager;

            string[] users = membershipManager.GetAllUsers(application);

            m_UserComboBox.Items.AddRange(users);
            if (users.Length > 0)
            {
                m_UserComboBox.Text = users[users.Length - 1];
            }
        }
Example #2
0
        void OnDeleteRole(object sender, EventArgs e)
        {
            DialogResult result = MessageBox.Show("Are you sure you want to delete the role " + RoleName + " ?", "Credentials Manager", MessageBoxButtons.OKCancel);

            if (result == DialogResult.OK)
            {
                IRoleManager roleManager = UserManagerProviderFactory.CreateRoleManager(); // new AspNetSqlProviderService(ServiceAddress);
                try
                {
                    bool deleted = roleManager.DeleteRole(ApplicationName, RoleName, m_ThrowIfPopulatedCheckBox.Checked);
                    if (deleted == false)
                    {
                        MessageBox.Show("Encountered an error trying to delete role " + m_RolesListView.CurrentListViewItem, "Credentials Manager", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                    else
                    {
                        m_RolesListView.RemoveItem(RoleName);
                        RefreshUsersForRoleComboBox();
                        RefreshRolesForUserComboBox();
                        RefreshRolePageButtons();
                    }
                }
                catch (SoapException exception)
                {
                    if (exception.Message.Contains("This role cannot be deleted because there are users present in it"))
                    {
                        MessageBox.Show("Failed to delete role " + m_RolesListView.CurrentListViewItem + " because it was populated.", "Credentials Manager", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                    else
                    {
                        throw;
                    }
                }
            }
        }
Example #3
0
        void OnRemoveUserFromRole(object sender, EventArgs e)
        {
            string role = m_RolesListView.CurrentListViewItem;

            Debug.Assert(!String.IsNullOrEmpty(role));
            IRoleManager roleManager = UserManagerProviderFactory.CreateRoleManager(); // new AspNetSqlProviderService(ServiceAddress);
            IUserManager userManager = roleManager as IUserManager;

            Debug.Assert(userManager != null);

            if (userManager.IsInRole(ApplicationName, UserToAssign, role))
            {
                DialogResult result = MessageBox.Show("Are you sure you want to remove the user " + UserToAssign + " from the role " + m_RolesListView.CurrentListViewItem + " ?", "Credentials Manager", MessageBoxButtons.OKCancel);
                if (result == DialogResult.OK)
                {
                    roleManager.RemoveUserFromRole(ApplicationName, UserToAssign, role);
                    RefreshRolesForUserComboBox();
                    RefreshUsersForRoleComboBox();
                    RefreshRolePageButtons();
                }
            }
            else
            {
                MessageBox.Show("The user " + UserToAssign + " is not a member of the role " + m_RolesListView.CurrentListViewItem, "Credentials Manager", MessageBoxButtons.OKCancel, MessageBoxIcon.Error);
            }
        }
Example #4
0
        void OnCreateRole(object sender, EventArgs e)
        {
            IRoleManager roleManager = UserManagerProviderFactory.CreateRoleManager(); // new AspNetSqlProviderService(m_Url);

            string[]           roles  = roleManager.GetAllRoles(m_Application);
            Predicate <string> exists = delegate(string role)
            {
                return(role == m_RoleTextBox.Text);
            };

            if (Array.Exists(roles, exists))
            {
                m_RoleValidator.SetError(m_RoleTextBox, "Role already exists");
                return;
            }
            m_RoleValidator.Clear();
            if (m_RoleTextBox.Text == String.Empty)
            {
                m_RoleValidator.SetError(m_RoleTextBox, "Role cannot be empty");
                return;
            }
            m_RoleValidator.Clear();
            roleManager.CreateRole(m_Application, m_RoleTextBox.Text);
            m_Roles.Add(m_RoleTextBox.Text);
            m_CreatedRolesListView.AddItem(m_RoleTextBox.Text, true);
            m_RoleTextBox.Focus();
            m_RoleTextBox.Text = String.Empty;
        }
Example #5
0
 void RefreshRolesForUserComboBox()
 {
     string[] roles = null;
     if (String.IsNullOrEmpty(UserToAssign) == false)
     {
         IRoleManager roleManager = UserManagerProviderFactory.CreateRoleManager(); // new AspNetSqlProviderService(ServiceAddress);
         roles = roleManager.GetRolesForUser(ApplicationName, UserToAssign);
     }
     m_RolesForUserComboBox.RefreshComboBox(UserToAssign, roles);
 }
Example #6
0
        void RefreshUsersForRoleComboBox()
        {
            string[] users = null;

            if (String.IsNullOrEmpty(RoleName) == false)
            {
                IRoleManager roleManager = UserManagerProviderFactory.CreateRoleManager(); // new AspNetSqlProviderService(ServiceAddress);
                users = roleManager.GetUsersInRole(ApplicationName, RoleName);
            }
            m_UsersInRoleComboBox.RefreshComboBox(RoleName, users);
        }
Example #7
0
        void RefreshRolesListView()
        {
            m_RolesListView.ClearItems();
            if (ApplicationName == String.Empty)
            {
                return;
            }
            IRoleManager roleManager = UserManagerProviderFactory.CreateRoleManager(); // new AspNetSqlProviderService(ServiceAddress);

            string[] roles = roleManager.GetAllRoles(ApplicationName);

            m_RolesListView.AddItems(roles, true);
        }
Example #8
0
        void OnDeleteAllRoles(object sender, EventArgs e)
        {
            DialogResult result = MessageBox.Show("Are you sure you want to delete all roles from the application?", "Credentials Manager", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning);

            if (result == DialogResult.OK)
            {
                IRoleManager roleManager = UserManagerProviderFactory.CreateRoleManager(); // new AspNetSqlProviderService(ServiceAddress);
                roleManager.DeleteAllRoles(ApplicationName, m_ThrowIfPopulatedCheckBox.Checked);

                m_RolesListView.ClearItems();
                RefreshUsersForRoleComboBox();
                RefreshRolesForUserComboBox();
                RefreshRolePageButtons();
            }
        }
Example #9
0
        void OnRemoveUsersFromAllRoles(object sender, EventArgs e)
        {
            DialogResult result = MessageBox.Show("Are you sure you want to remove the user " + UserToAssign + " from all its roles?", "Credentials Manager", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning);

            if (result == DialogResult.OK)
            {
                IRoleManager roleManager = UserManagerProviderFactory.CreateRoleManager(); // new AspNetSqlProviderService(ServiceAddress);
                string[]     roles       = roleManager.GetRolesForUser(ApplicationName, UserToAssign);
                if (roles.Length > 0)
                {
                    roleManager.RemoveUserFromRoles(ApplicationName, UserToAssign, roles);
                    RefreshRolesForUserComboBox();
                    RefreshUsersForRoleComboBox();
                    RefreshRolePageButtons();
                }
            }
        }
Example #10
0
        void OnAssignUserToRole(object sender, EventArgs e)
        {
            IRoleManager roleManager = UserManagerProviderFactory.CreateRoleManager(); // new AspNetSqlProviderService(ServiceAddress);
            IUserManager userManager = roleManager as IUserManager;

            Debug.Assert(userManager != null);

            string role = m_RolesListView.CurrentListViewItem;

            Debug.Assert(role != String.Empty);

            if (userManager.IsInRole(ApplicationName, UserToAssign, role))
            {
                MessageBox.Show("The user " + UserToAssign + " is already a member of the role " + m_RolesListView.CurrentListViewItem, "Credentials Manager", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                return;
            }
            else
            {
                roleManager.AddUserToRole(ApplicationName, UserToAssign, m_RolesListView.CurrentListViewItem);
                RefreshRolesForUserComboBox();
                RefreshUsersForRoleComboBox();
                RefreshRolePageButtons();
            }
        }