Exemplo n.º 1
0
 public static IPermission Create(string fullname, SecurityElement se)
 {
     if (fullname == null)
     {
         throw new ArgumentNullException("fullname");
     }
     if (se == null)
     {
         throw new ArgumentNullException("se");
     }
     return(PermissionBuilder.CreatePermission(fullname, se));
 }
Exemplo n.º 2
0
        public virtual void FromXml(SecurityElement et)
        {
            if (et == null)
            {
                throw new ArgumentNullException("et");
            }
            if (et.Tag != tagName)
            {
                string msg = String.Format("Invalid tag {0} expected {1}", et.Tag, tagName);
                throw new ArgumentException(msg, "et");
            }

            list.Clear();

            if (CodeAccessPermission.IsUnrestricted(et))
            {
                state = PermissionState.Unrestricted;
#if NET_2_0
                // no need to continue for an unrestricted permission
                // because identity permissions now "supports" unrestricted
                return;
#endif
            }
            else
            {
                state = PermissionState.None;
            }

            if (et.Children != null)
            {
                foreach (SecurityElement se in et.Children)
                {
                    string className = se.Attribute("class");
                    if (className == null)
                    {
                        throw new ArgumentException(Locale.GetText(
                                                        "No permission class is specified."));
                    }
                    if (Resolver != null)
                    {
                                                #if !DISABLE_SECURITY
                        // policy class names do not have to be fully qualified
                        className = Resolver.ResolveClassName(className);
                                                #else
                        className = null;
                                                #endif
                    }

                    list.Add(PermissionBuilder.Create(className, se));
                }
            }
        }
Exemplo n.º 3
0
        internal static IPermission CreatePermission(string fullname, SecurityElement se)
        {
            Type type = Type.GetType(fullname);

            if (type == null)
            {
                string text = Locale.GetText("Can't create an instance of permission class {0}.");
                throw new TypeLoadException(string.Format(text, fullname));
            }
            IPermission permission = PermissionBuilder.Create(type);

            permission.FromXml(se);
            return(permission);
        }
Exemplo n.º 4
0
        public static IPermission Create(SecurityElement se)
        {
            if (se == null)
            {
                throw new ArgumentNullException("se");
            }
            string text = se.Attribute("class");

            if (text == null || text.Length == 0)
            {
                throw new ArgumentException("class");
            }
            return(PermissionBuilder.CreatePermission(text, se));
        }
Exemplo n.º 5
0
        public static IPermission Create(string fullname, PermissionState state)
        {
            if (fullname == null)
            {
                throw new ArgumentNullException("fullname");
            }
            SecurityElement securityElement = new SecurityElement("IPermission");

            securityElement.AddAttribute("class", fullname);
            securityElement.AddAttribute("version", "1");
            if (state == PermissionState.Unrestricted)
            {
                securityElement.AddAttribute("Unrestricted", "true");
            }
            return(PermissionBuilder.CreatePermission(fullname, securityElement));
        }
        internal bool CheckDeny(CodeAccessPermission denied)
        {
            if (denied == null)
            {
                return(true);
            }
            Type t = denied.GetType();

            if (t != this.GetType())
            {
                return(true);
            }
            IPermission inter = Intersect(denied);

            if (inter == null)
            {
                return(true);
            }
            // sadly that's not enough :( at this stage we must also check
            // if an empty (PermissionState.None) is a subset of the denied
            // (which is like a empty intersection looks like for flag based
            // permissions, e.g. AspNetHostingPermission).
            return(denied.IsSubsetOf(PermissionBuilder.Create(t)));
        }
        internal bool CheckDeny(CodeAccessPermission denied)
        {
            if (denied == null)
            {
                return(true);
            }
            Type type = denied.GetType();

            return(type != base.GetType() || this.Intersect(denied) == null || denied.IsSubsetOf(PermissionBuilder.Create(type)));
        }