Utility class for reading permissions and authorizations.
Esempio n. 1
0
        /// <summary>
        /// Gets the subjects for the current resource.
        /// </summary>
        /// <returns>The subjects.</returns>
        private SubjectInfo[] GetSubjects()
        {
            if (CurrentResourceType != AclResources.Namespaces && string.IsNullOrEmpty(CurrentResourceName) ||
                (CurrentResourceType == AclResources.Directories && string.IsNullOrEmpty(CurrentFilesProvider)))
            {
                return(new SubjectInfo[0]);
            }

            AuthReader authReader = new AuthReader(Collectors.CollectorsBox.GetSettingsProvider(currentWiki));

            switch (CurrentResourceType)
            {
            case AclResources.Namespaces:
                return(authReader.RetrieveSubjectsForNamespace(Pages.FindNamespace(currentWiki, CurrentResourceName)));

            case AclResources.Pages:
                return(authReader.RetrieveSubjectsForPage(CurrentResourceName));

            case AclResources.Directories:
                return(authReader.RetrieveSubjectsForDirectory(
                           Collectors.CollectorsBox.FilesProviderCollector.GetProvider(CurrentFilesProvider, currentWiki), CurrentResourceName));

            default:
                throw new NotSupportedException();
            }
        }
Esempio n. 2
0
        protected void rptAccounts_ItemCommand(object sender, RepeaterCommandEventArgs e)
        {
            if (e.CommandName == "Select")
            {
                txtCurrentUsername.Value = e.CommandArgument as string;
                //rptAccounts.DataBind(); Not needed because the list is hidden on select

                UserInfo user = Users.FindUser(currentWiki, txtCurrentUsername.Value);

                txtUsername.Text     = user.Username;
                txtUsername.Enabled  = false;
                txtDisplayName.Text  = user.DisplayName;
                txtEmail.Text        = user.Email;
                chkSetActive.Checked = user.Active;
                providerSelector.SelectedProvider = user.Provider.GetType().FullName;
                providerSelector.Enabled          = false;
                btnCreate.Visible       = false;
                btnSave.Visible         = true;
                btnDelete.Visible       = user.Username != SessionFacade.CurrentUsername;
                rfvPassword1.Enabled    = false;
                cvUsername.Enabled      = false;
                lblPasswordInfo.Visible = true;

                pnlEditAccount.Visible = true;
                pnlList.Visible        = false;
                PopulateGroups();

                // Select user's groups
                List <UserGroup> groups = Users.GetUserGroupsForUser(user);
                foreach (ListItem item in lstGroups.Items)
                {
                    if (groups.Find(delegate(UserGroup g) { return(g.Name == item.Value); }) != null)
                    {
                        item.Selected = true;
                    }
                }

                // Select user's global permissions
                AuthReader authReader = new AuthReader(Collectors.CollectorsBox.GetSettingsProvider(currentWiki));
                aclActionsSelector.GrantedActions =
                    authReader.RetrieveGrantsForGlobals(user);
                aclActionsSelector.DeniedActions =
                    authReader.RetrieveDenialsForGlobals(user);

                // Enable/disable interface sections based on provider read-only settings
                lstGroups.Enabled         = !user.Provider.GroupMembershipReadOnly;
                pnlAccountDetails.Enabled = !user.Provider.UserAccountsReadOnly;
                btnDelete.Enabled         = !user.Provider.UserAccountsReadOnly;

                lblResult.CssClass = "";
                lblResult.Text     = "";
            }
        }
Esempio n. 3
0
        protected void rptGroups_ItemCommand(object sender, RepeaterCommandEventArgs e)
        {
            if (e.CommandName == "Select")
            {
                txtCurrentName.Value = e.CommandArgument as string;
                //rptGroups.DataBind(); Not needed because the list is hidden on select

                UserGroup group = Users.FindUserGroup(currentWiki, txtCurrentName.Value);

                txtName.Text        = group.Name;
                txtName.Enabled     = false;
                txtDescription.Text = group.Description;
                providerSelector.SelectedProvider = group.Provider.GetType().FullName;
                providerSelector.Enabled          = false;

                // Select group's global permissions
                AuthReader authReader = new AuthReader(Collectors.CollectorsBox.GetSettingsProvider(currentWiki));
                aclActionsSelector.GrantedActions = authReader.RetrieveGrantsForGlobals(group);
                aclActionsSelector.DeniedActions  = authReader.RetrieveDenialsForGlobals(group);

                btnCreate.Visible = false;
                btnSave.Visible   = true;
                btnDelete.Visible = true;
                bool isDefaultGroup =
                    group.Name == Settings.GetAdministratorsGroup(currentWiki) ||
                    group.Name == Settings.GetUsersGroup(currentWiki) ||
                    group.Name == Settings.GetAnonymousGroup(currentWiki);

                pnlEditGroup.Visible = true;
                pnlList.Visible      = false;

                // Enable/disable interface sections based on provider read-only settings
                pnlGroupDetails.Enabled = !group.Provider.UserGroupsReadOnly;
                btnDelete.Enabled       = !group.Provider.UserGroupsReadOnly && !isDefaultGroup;

                lblResult.CssClass = "";
                lblResult.Text     = "";
            }
        }
Esempio n. 4
0
        /// <summary>
        /// Displays the permissions for a subject in the actions matrix.
        /// </summary>
        /// <param name="subject">The subject.</param>
        /// <param name="type">The subject type.</param>
        private void DisplaySubjectPermissions(string subject, SubjectType type)
        {
            lblSelectedSubject.Text = subject;

            string[] grants  = null;
            string[] denials = null;

            switch (CurrentResourceType)
            {
            case AclResources.Namespaces:
                if (type == SubjectType.Group)
                {
                    grants = AuthReader.RetrieveGrantsForNamespace(
                        Users.FindUserGroup(subject),
                        Pages.FindNamespace(CurrentResourceName));

                    denials = AuthReader.RetrieveDenialsForNamespace(
                        Users.FindUserGroup(subject),
                        Pages.FindNamespace(CurrentResourceName));
                }
                else
                {
                    grants = AuthReader.RetrieveGrantsForNamespace(
                        Users.FindUser(subject),
                        Pages.FindNamespace(CurrentResourceName));
                    denials = AuthReader.RetrieveDenialsForNamespace(
                        Users.FindUser(subject),
                        Pages.FindNamespace(CurrentResourceName));
                }
                break;

            case AclResources.Pages:
                if (type == SubjectType.Group)
                {
                    grants = AuthReader.RetrieveGrantsForPage(
                        Users.FindUserGroup(subject),
                        Pages.FindPage(CurrentResourceName));
                    denials = AuthReader.RetrieveDenialsForPage(
                        Users.FindUserGroup(subject),
                        Pages.FindPage(CurrentResourceName));
                }
                else
                {
                    grants = AuthReader.RetrieveGrantsForPage(
                        Users.FindUser(subject),
                        Pages.FindPage(CurrentResourceName));
                    denials = AuthReader.RetrieveDenialsForPage(
                        Users.FindUser(subject),
                        Pages.FindPage(CurrentResourceName));
                }
                break;

            case AclResources.Directories:
                string directory = CurrentResourceName;
                IFilesStorageProviderV30 prov = Collectors.FilesProviderCollector.GetProvider(CurrentFilesProvider);
                if (type == SubjectType.Group)
                {
                    grants = AuthReader.RetrieveGrantsForDirectory(
                        Users.FindUserGroup(subject),
                        prov, directory);
                    denials = AuthReader.RetrieveDenialsForDirectory(
                        Users.FindUserGroup(subject),
                        prov, directory);
                }
                else
                {
                    grants = AuthReader.RetrieveGrantsForDirectory(
                        Users.FindUser(subject),
                        prov, directory);
                    denials = AuthReader.RetrieveDenialsForDirectory(
                        Users.FindUser(subject),
                        prov, directory);
                }
                break;

            default:
                throw new NotSupportedException();
            }

            aclActionsSelector.GrantedActions = grants;
            aclActionsSelector.DeniedActions  = denials;

            btnSave.Enabled   = true;
            btnRemove.Enabled = true;
        }