Esempio n. 1
0
 /// <summary>
 /// 删除授权节点信息
 /// </summary>
 /// <param name="node">授权节点</param>
 public void Remove(AuthorizationNode node)
 {
     if (node != null && !String.IsNullOrEmpty(node.AuthorizationUri))
     {
         Remove(node.AuthorizationUri);
     }
 }
        /// <summary>
        /// 删除授权节点
        /// </summary>
        /// <param name="node">授权节点</param>
        public void Delete(AuthorizationNode node)
        {
            IList <AuthorizationNode> lns = db.Query <AuthorizationNode>((AuthorizationNode an) => an.AuthorizationUri == node.AuthorizationUri);

            foreach (AuthorizationNode an in lns)
            {
                db.Delete(an); // 删除所有授权节点
            }
        }
Esempio n. 3
0
        /// <summary>
        /// 存储授权节点
        /// </summary>
        /// <param name="node">授权节点</param>
        public void Store(AuthorizationNode node)
        {
            Guard.ArgumentNotNull(node, "node");

            Dictionary <string, AuthorizationAction> acs = new Dictionary <string, AuthorizationAction>();

            //// 原来的授权信息
            //foreach (AuthorizationCommand cmd in node.Commands) {
            //    string key = SecurityUtility.HashObject(node.AuthorizationUri + cmd.CommandUri);
            //    if (actions.ContainsKey(key))
            //        acs[key] = actions[key];
            //}

            //Remove(node.AuthorizationUri); // 删除原来的授权信息
            //authorizations[node.AuthorizationUri] = node;
            //foreach (AuthorizationCommand cmd in node.Commands) {
            //    string key = SecurityUtility.HashObject(node.AuthorizationUri + cmd.CommandUri);
            //    if (acs.ContainsKey(key))
            //        actions[key] = acs[key];
            //    else
            //        actions[key] = AuthorizationAction.Deny;
            //}

            // 首先删除原来的授权信息
            foreach (AuthorizationCommand cmd in node.Commands)
            {
                string key = SecurityUtility.HashObject(node.AuthorizationUri + cmd.CommandUri);
                AuthorizationActionInfo actionInfo = new AuthorizationActionInfo(key, cmd.Action);
                if (actions.Contains(actionInfo))
                {
                    actions.Remove(actionInfo);
                }
            }
            Remove(node.AuthorizationUri);
            authorizations.Add(node);
            foreach (AuthorizationCommand cmd in node.Commands)
            {
                string key = SecurityUtility.HashObject(node.AuthorizationUri + cmd.CommandUri);
                AuthorizationActionInfo actionInfo = new AuthorizationActionInfo(key, cmd.Action);
                actions.Add(actionInfo);
            }
        }
 /// <summary>
 /// 保存授权节点
 /// </summary>
 /// <param name="node">授权节点</param>
 public void Save(AuthorizationNode node)
 {
     Delete(node);
     db.Store(node);
 }