Esempio n. 1
0
        /// <summary>
        /// Removes rules based on field filters from the current policy.
        /// </summary>
        /// <param name="sec"></param>
        /// <param name="ptype"></param>
        /// <param name="fieldIndex"></param>
        /// <param name="fieldValues"></param>
        /// <returns></returns>
        protected async Task <bool> InternalRemoveFilteredPolicyAsync(string sec, string ptype, int fieldIndex, params string[] fieldValues)
        {
            if (adapter is not null && autoSave)
            {
                try
                {
                    await adapter.RemoveFilteredPolicyAsync(sec, ptype, fieldIndex, fieldValues);
                }
                catch (NotImplementedException)
                {
                    // error intentionally ignored
                }
            }

            bool ruleRemoved = model.RemoveFilteredPolicy(sec, ptype, fieldIndex, fieldValues);

            if (ruleRemoved is false)
            {
                return(false);
            }

            if (sec.Equals(PermConstants.Section.RoleSection))
            {
                BuildRoleLinks();
                ExpressionHandler.SetGFunctions();
            }

            await NotifyPolicyChangedAsync();

            return(true);
        }
Esempio n. 2
0
        private async Task NoticePolicyChangedAsync(string section)
        {
            if (autoBuildRoleLinks && section.Equals(PermConstants.Section.RoleSection))
            {
                BuildRoleLinks();
                ExpressionHandler.SetGFunctions();
            }

            if (autoNotifyWatcher && watcher is not null)
            {
                await watcher.UpdateAsync();
            }
        }
Esempio n. 3
0
        private void NoticePolicyChanged(string section)
        {
            if (autoBuildRoleLinks && section.Equals(PermConstants.Section.RoleSection))
            {
                BuildRoleLinks();
                ExpressionHandler.SetGFunctions();
            }

            if (autoNotifyWatcher)
            {
                watcher?.Update();
            }
        }
Esempio n. 4
0
        /// <summary>
        /// Removes rules from the current policy.
        /// </summary>
        /// <param name="sec"></param>
        /// <param name="ptype"></param>
        /// <param name="rules"></param>
        /// <returns></returns>
        protected async Task <bool> InternalRemovePoliciesAsync(string sec, string ptype, IEnumerable <List <string> > rules)
        {
            var ruleArray = rules as List <string>[] ?? rules.ToArray();

            if (model.HasPolicies(sec, ptype, ruleArray) is false)
            {
                return(false);
            }

            if (adapter is not null && autoSave)
            {
                try
                {
                    await adapter.RemovePoliciesAsync(sec, ptype, ruleArray);
                }
                catch (NotImplementedException)
                {
                    // error intentionally ignored
                }
            }

            bool ruleRemoved = model.RemovePolicies(sec, ptype, ruleArray);

            if (ruleRemoved is false)
            {
                return(false);
            }

            if (sec.Equals(PermConstants.Section.RoleSection))
            {
                model.BuildIncrementalRoleLinks(roleManager, PolicyOperation.PolicyRemove,
                                                sec, ptype, ruleArray);
                ExpressionHandler.SetGFunctions();
            }

            await NotifyPolicyChangedAsync();

            return(true);
        }
Esempio n. 5
0
        /// <summary>
        /// Adds rules to the current policy.
        /// </summary>
        /// <param name="sec"></param>
        /// <param name="ptype"></param>
        /// <param name="rules"></param>
        /// <returns></returns>
        protected bool InternalAddPolicies(string sec, string ptype, IEnumerable <List <string> > rules)
        {
            var ruleArray = rules as List <string>[] ?? rules.ToArray();

            if (model.HasPolicies(sec, ptype, ruleArray))
            {
                return(false);
            }

            if (adapter is not null && autoSave)
            {
                try
                {
                    adapter.AddPolicies(sec, ptype, ruleArray);
                }
                catch (NotImplementedException)
                {
                    // error intentionally ignored
                }
            }

            bool ruleAdded = model.AddPolicies(sec, ptype, ruleArray);

            if (ruleAdded is false)
            {
                return(false);
            }

            if (sec.Equals(PermConstants.Section.RoleSection))
            {
                model.BuildIncrementalRoleLinks(PolicyOperation.PolicyAdd,
                                                sec, ptype, ruleArray);
                ExpressionHandler.SetGFunctions();
            }

            NotifyPolicyChanged();
            return(true);
        }
Esempio n. 6
0
        /// <summary>
        /// Adds a rule to the current policy.
        /// </summary>
        /// <param name="sec"></param>
        /// <param name="ptype"></param>
        /// <param name="rule"></param>
        /// <returns></returns>
        protected async Task <bool> InternalAddPolicyAsync(string sec, string ptype, List <string> rule)
        {
            if (model.HasPolicy(sec, ptype, rule))
            {
                return(false);
            }

            if (adapter is not null && autoSave)
            {
                try
                {
                    await adapter.AddPolicyAsync(sec, ptype, rule);
                }
                catch (NotImplementedException)
                {
                    // error intentionally ignored
                }
            }

            bool ruleAdded = model.AddPolicy(sec, ptype, rule);

            if (ruleAdded is false)
            {
                return(false);
            }

            if (sec.Equals(PermConstants.Section.RoleSection))
            {
                model.BuildIncrementalRoleLink(roleManager, PolicyOperation.PolicyAdd,
                                               sec, ptype, rule);
                ExpressionHandler.SetGFunctions();
            }

            await NotifyPolicyChangedAsync();

            return(true);
        }
Esempio n. 7
0
        /// <summary>
        /// Removes a rule from the current policy.
        /// </summary>
        /// <param name="sec"></param>
        /// <param name="ptype"></param>
        /// <param name="rule"></param>
        /// <returns></returns>
        protected bool InternalRemovePolicy(string sec, string ptype, List <string> rule)
        {
            if (model.HasPolicy(sec, ptype, rule) is false)
            {
                return(false);
            }

            if (adapter is not null && autoSave)
            {
                try
                {
                    adapter.RemovePolicy(sec, ptype, rule);
                }
                catch (NotImplementedException)
                {
                    // error intentionally ignored
                }
            }

            bool ruleRemoved = model.RemovePolicy(sec, ptype, rule);

            if (ruleRemoved is false)
            {
                return(false);
            }

            if (sec.Equals(PermConstants.Section.RoleSection))
            {
                model.BuildIncrementalRoleLink(PolicyOperation.PolicyRemove,
                                               sec, ptype, rule);
                ExpressionHandler.SetGFunctions();
            }

            NotifyPolicyChanged();
            return(true);
        }
Esempio n. 8
0
 /// <summary>
 /// Sets the current role manager.
 /// </summary>
 /// <param name="roleManager"></param>
 public void SetRoleManager(IRoleManager roleManager)
 {
     SetRoleManager(PermConstants.DefaultRoleType, roleManager);
     ExpressionHandler.SetGFunctions();
 }