コード例 #1
0
 /// <summary>
 /// Add rights for the specified object.
 /// </summary>
 protected void AddObjRight(RightByObj rightByObj, int objNum, Right right)
 {
     if (!rightByObj.ContainsKey(objNum))
     {
         rightByObj.Add(objNum, right);
     }
 }
コード例 #2
0
 /// <summary>
 /// Gets the access rights on the specified object.
 /// </summary>
 public Right GetRightByObj(int?objID)
 {
     if (RoleIsBuiltIn)
     {
         return(DefaultRight);
     }
     else
     {
         return(objID > 0 && RightByObj != null && RightByObj.TryGetValue(objID.Value, out Right right)
             ? right
             : Right.Empty);
     }
 }
コード例 #3
0
        /// <summary>
        /// Add rights for the specified role.
        /// </summary>
        protected void AddRoleRight(ITableIndex objRight_roleIndex, ITableIndex obj_parentObjIndex,
                                    RightByObj rightByObj, int roleID)
        {
            // explicitly defined rights have higher priority
            foreach (ObjRight objRight in objRight_roleIndex.SelectItems(roleID))
            {
                AddObjRight(rightByObj, objRight.ObjNum, new Right(objRight));
            }

            // add rights on child objects
            foreach (ObjRight objRight in objRight_roleIndex.SelectItems(roleID))
            {
                Right right = new Right(objRight);

                foreach (Obj childObj in EnumerateChildObjects(obj_parentObjIndex, objRight.ObjNum))
                {
                    AddObjRight(rightByObj, childObj.ObjNum, right);
                }
            }
        }
コード例 #4
0
        /// <summary>
        /// Initializes the access rights.
        /// </summary>
        public void Init(ConfigDataset configDataset)
        {
            if (configDataset == null)
            {
                throw new ArgumentNullException(nameof(configDataset));
            }

            // initialize rights matrix
            Matrix = new Dictionary <int, RightByObj>(configDataset.RoleTable.ItemCount);

            // get indexes
            if (!configDataset.RoleRefTable.TryGetIndex("ChildRoleID", out ITableIndex roleRef_childRoleIndex))
            {
                throw new ScadaException(CommonPhrases.IndexNotFound);
            }

            if (!configDataset.ObjRightTable.TryGetIndex("RoleID", out ITableIndex objRight_roleIndex))
            {
                throw new ScadaException(CommonPhrases.IndexNotFound);
            }

            if (!configDataset.ObjTable.TryGetIndex("ParentObjNum", out ITableIndex obj_parentObjIndex))
            {
                throw new ScadaException(CommonPhrases.IndexNotFound);
            }

            // fill rights
            foreach (Role role in configDataset.RoleTable.EnumerateItems())
            {
                int        roleID     = role.RoleID;
                RightByObj rightByObj = new RightByObj();
                Matrix.Add(roleID, rightByObj);
                AddRoleRight(objRight_roleIndex, obj_parentObjIndex, rightByObj, roleID);

                foreach (int parentRoleID in EnumerateParentRoleIDs(roleRef_childRoleIndex, roleID))
                {
                    AddRoleRight(objRight_roleIndex, obj_parentObjIndex, rightByObj, parentRoleID);
                }
            }
        }