Beispiel #1
0
        /// <summary>
        /// Specify the roles allowed to read a given
        /// property.
        /// </summary>
        /// <param name="propertyName">Name of the property.</param>
        /// <param name="roles">List of roles granted read access.</param>
        /// <remarks>
        /// This method may be called multiple times, with the roles in
        /// each call being added to the end of the list of allowed roles.
        /// In other words, each call is cumulative, adding more roles
        /// to the list.
        /// </remarks>
        public void AllowRead(string propertyName, params string[] roles)
        {
            RolesForProperty currentRoles = GetRolesForProperty(propertyName);

            foreach (string item in roles)
            {
                currentRoles.ReadAllowed.Add(item);
            }
        }
Beispiel #2
0
        /// <summary>
        /// Specify the roles denied write access to
        /// a given property.
        /// </summary>
        /// <param name="propertyName">Name of the property.</param>
        /// <param name="roles">List of roles denied write access.</param>
        /// <remarks>
        /// This method may be called multiple times, with the roles in
        /// each call being added to the end of the list of denied roles.
        /// In other words, each call is cumulative, adding more roles
        /// to the list.
        /// </remarks>
        public void DenyWrite(string propertyName, params string[] roles)
        {
            RolesForProperty currentRoles = GetRolesForProperty(propertyName);

            foreach (string item in roles)
            {
                currentRoles.WriteDenied.Add(item);
            }
        }
Beispiel #3
0
        private RolesForProperty GetRolesForProperty(string propertyName)
        {
            RolesForProperty currentRoles = null;

            if (!Rules.ContainsKey(propertyName))
            {
                currentRoles = new RolesForProperty();
                Rules.Add(propertyName, currentRoles);
            }
            else
            {
                currentRoles = Rules[propertyName];
            }
            return(currentRoles);
        }
Beispiel #4
0
        public string[] GetRolesForProperty(string propertyName, AccessType access)
        {
            RolesForProperty currentRoles = GetRolesForProperty(propertyName);

            switch (access)
            {
            case AccessType.ReadAllowed:
                return(currentRoles.ReadAllowed.ToArray());

            case AccessType.ReadDenied:
                return(currentRoles.ReadDenied.ToArray());

            case AccessType.WriteAllowed:
                return(currentRoles.WriteAllowed.ToArray());

            case AccessType.WriteDenied:
                return(currentRoles.WriteDenied.ToArray());
            }
            return(null);
        }