Inheritance: global::java.security.BasicPermission
示例#1
0
        /// <summary>
        /// Checks if this PropertyPermission object "implies" the specified
        /// permission.
        /// <P>
        /// More specifically, this method returns true if:
        /// <ul>
        /// <li> <i>p</i> is an instanceof PropertyPermission,
        /// <li> <i>p</i>'s actions are a subset of this
        /// object's actions, and
        /// <li> <i>p</i>'s name is implied by this object's
        ///      name. For example, "java.*" implies "java.home".
        /// </ul> </summary>
        /// <param name="p"> the permission to check against.
        /// </param>
        /// <returns> true if the specified permission is implied by this object,
        /// false if not. </returns>
        public override bool Implies(Permission p)
        {
            if (!(p is PropertyPermission))
            {
                return(false);
            }

            PropertyPermission that = (PropertyPermission)p;

            // we get the effective mask. i.e., the "and" of this and that.
            // They must be equal to that.mask for implies to return true.

            return(((this.Mask_Renamed & that.Mask_Renamed) == that.Mask_Renamed) && base.Implies(that));
        }
示例#2
0
        /// <summary>
        /// Checks two PropertyPermission objects for equality. Checks that <i>obj</i> is
        /// a PropertyPermission, and has the same name and actions as this object.
        /// <P> </summary>
        /// <param name="obj"> the object we are testing for equality with this object. </param>
        /// <returns> true if obj is a PropertyPermission, and has the same name and
        /// actions as this PropertyPermission object. </returns>
        public override bool Equals(Object obj)
        {
            if (obj == this)
            {
                return(true);
            }

            if (!(obj is PropertyPermission))
            {
                return(false);
            }

            PropertyPermission that = (PropertyPermission)obj;

            return((this.Mask_Renamed == that.Mask_Renamed) && (this.Name.Equals(that.Name)));
        }
示例#3
0
        /// <summary>
        /// Adds a permission to the PropertyPermissions. The key for the hash is
        /// the name.
        /// </summary>
        /// <param name="permission"> the Permission object to add.
        /// </param>
        /// <exception cref="IllegalArgumentException"> - if the permission is not a
        ///                                       PropertyPermission
        /// </exception>
        /// <exception cref="SecurityException"> - if this PropertyPermissionCollection
        ///                                object has been marked readonly </exception>
        public override void Add(Permission permission)
        {
            if (!(permission is PropertyPermission))
            {
                throw new IllegalArgumentException("invalid permission: " + permission);
            }
            if (ReadOnly)
            {
                throw new SecurityException("attempt to add a Permission to a readonly PermissionCollection");
            }

            PropertyPermission pp       = (PropertyPermission)permission;
            String             propName = pp.Name;

            lock (this)
            {
                PropertyPermission existing = Perms[propName];

                if (existing != null)
                {
                    int oldMask = existing.Mask;
                    int newMask = pp.Mask;
                    if (oldMask != newMask)
                    {
                        int    effective = oldMask | newMask;
                        String actions   = PropertyPermission.GetActions(effective);
                        Perms[propName] = new PropertyPermission(propName, actions);
                    }
                }
                else
                {
                    Perms[propName] = pp;
                }
            }

            if (!All_allowed)
            {
                if (propName.Equals("*"))
                {
                    All_allowed = true;
                }
            }
        }
示例#4
0
        /// <summary>
        /// Check and see if this set of permissions implies the permissions
        /// expressed in "permission".
        /// </summary>
        /// <param name="permission"> the Permission object to compare
        /// </param>
        /// <returns> true if "permission" is a proper subset of a permission in
        /// the set, false if not. </returns>
        public override bool Implies(Permission permission)
        {
            if (!(permission is PropertyPermission))
            {
                return(false);
            }

            PropertyPermission pp = (PropertyPermission)permission;
            PropertyPermission x;

            int desired   = pp.Mask;
            int effective = 0;

            // short circuit if the "*" Permission was added
            if (All_allowed)
            {
                lock (this)
                {
                    x = Perms["*"];
                }
                if (x != null)
                {
                    effective |= x.Mask;
                    if ((effective & desired) == desired)
                    {
                        return(true);
                    }
                }
            }

            // strategy:
            // Check for full match first. Then work our way up the
            // name looking for matches on a.b.*

            String name = pp.Name;

            //System.out.println("check "+name);

            lock (this)
            {
                x = Perms[name];
            }

            if (x != null)
            {
                // we have a direct hit!
                effective |= x.Mask;
                if ((effective & desired) == desired)
                {
                    return(true);
                }
            }

            // work our way up the tree...
            int last, offset;

            offset = name.Length() - 1;

            while ((last = name.LastIndexOf(".", offset)) != -1)
            {
                name = name.Substring(0, last + 1) + "*";
                //System.out.println("check "+name);
                lock (this)
                {
                    x = Perms[name];
                }

                if (x != null)
                {
                    effective |= x.Mask;
                    if ((effective & desired) == desired)
                    {
                        return(true);
                    }
                }
                offset = last - 1;
            }

            // we don't have to check for "*" as it was already checked
            // at the top (all_allowed), so we just return false
            return(false);
        }