Inheritance: global::java.security.Permission, global::java.io.Serializable
Example #1
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 FilePermission))
            {
                return(false);
            }

            FilePermission fp = (FilePermission)permission;

            int desired   = fp.Mask;
            int effective = 0;
            int needed    = desired;

            lock (this)
            {
                int len = Perms.Count;
                for (int i = 0; i < len; i++)
                {
                    FilePermission x = (FilePermission)Perms[i];
                    if (((needed & x.Mask) != 0) && x.ImpliesIgnoreMask(fp))
                    {
                        effective |= x.Mask;
                        if ((effective & desired) == desired)
                        {
                            return(true);
                        }
                        needed = (desired ^ effective);
                    }
                }
            }
            return(false);
        }
Example #2
0
        /// <summary>
        /// Checks if this FilePermission object "implies" the specified permission.
        /// <P>
        /// More specifically, this method returns true if:
        /// <ul>
        /// <li> <i>p</i> is an instanceof FilePermission,
        /// <li> <i>p</i>'s actions are a proper subset of this
        /// object's actions, and
        /// <li> <i>p</i>'s pathname is implied by this object's
        ///      pathname. For example, "/tmp/*" implies "/tmp/foo", since
        ///      "/tmp/*" encompasses all files in the "/tmp" directory,
        ///      including the one named "foo".
        /// </ul>
        /// </summary>
        /// <param name="p"> the permission to check against.
        /// </param>
        /// <returns> <code>true</code> if the specified permission is not
        ///                  <code>null</code> and is implied by this object,
        ///                  <code>false</code> otherwise. </returns>
        public override bool Implies(Permission p)
        {
            if (!(p is FilePermission))
            {
                return(false);
            }

            FilePermission that = (FilePermission)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) && ImpliesIgnoreMask(that));
        }
Example #3
0
        /// <summary>
        /// Checks two FilePermission objects for equality. Checks that <i>obj</i> is
        /// a FilePermission, and has the same pathname and actions as this object.
        /// </summary>
        /// <param name="obj"> the object we are testing for equality with this object. </param>
        /// <returns> <code>true</code> if obj is a FilePermission, and has the same
        ///          pathname and actions as this FilePermission object,
        ///          <code>false</code> otherwise. </returns>
        public override bool Equals(Object obj)
        {
            if (obj == this)
            {
                return(true);
            }

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

            FilePermission that = (FilePermission)obj;

            return((this.Mask_Renamed == that.Mask_Renamed) && this.Cpath.Equals(that.Cpath) && (this.Directory == that.Directory) && (this.Recursive == that.Recursive));
        }
Example #4
0
 /// <summary>
 /// Checks if the Permission's actions are a proper subset of the
 /// this object's actions. Returns the effective mask iff the
 /// this FilePermission's path also implies that FilePermission's path.
 /// </summary>
 /// <param name="that"> the FilePermission to check against. </param>
 /// <returns> the effective mask </returns>
 internal bool ImpliesIgnoreMask(FilePermission that)
 {
     if (this.Directory)
     {
         if (this.Recursive)
         {
             // make sure that.path is longer then path so
             // something like /foo/- does not imply /foo
             if (that.Directory)
             {
                 return((that.Cpath.Length() >= this.Cpath.Length()) && that.Cpath.StartsWith(this.Cpath));
             }
             else
             {
                 return((that.Cpath.Length() > this.Cpath.Length()) && that.Cpath.StartsWith(this.Cpath));
             }
         }
         else
         {
             if (that.Directory)
             {
                 // if the permission passed in is a directory
                 // specification, make sure that a non-recursive
                 // permission (i.e., this object) can't imply a recursive
                 // permission.
                 if (that.Recursive)
                 {
                     return(false);
                 }
                 else
                 {
                     return(this.Cpath.Equals(that.Cpath));
                 }
             }
             else
             {
                 int last = that.Cpath.LastIndexOf(System.IO.Path.DirectorySeparatorChar);
                 if (last == -1)
                 {
                     return(false);
                 }
                 else
                 {
                     // this.cpath.equals(that.cpath.substring(0, last+1));
                     // Use regionMatches to avoid creating new string
                     return((this.Cpath.Length() == (last + 1)) && this.Cpath.RegionMatches(0, that.Cpath, 0, last + 1));
                 }
             }
         }
     }
     else if (that.Directory)
     {
         // if this is NOT recursive/wildcarded,
         // do not let it imply a recursive/wildcarded permission
         return(false);
     }
     else
     {
         return(this.Cpath.Equals(that.Cpath));
     }
 }
Example #5
0
 public PrivilegedActionAnonymousInnerClassHelper(FilePermission outerInstance)
 {
     this.OuterInstance = outerInstance;
 }