Example #1
0
        /// <summary>
        /// Returns true if, this.getActions().equals(p.getActions())
        /// and p's url equals this's url.  Returns false otherwise.
        /// </summary>
        public override bool Equals(Object p)
        {
            if (!(p is URLPermission))
            {
                return(false);
            }
            URLPermission that = (URLPermission)p;

            if (!this.Scheme.Equals(that.Scheme))
            {
                return(false);
            }
            if (!this.Actions.Equals(that.Actions))
            {
                return(false);
            }
            if (!this.Authority.Equals(that.Authority))
            {
                return(false);
            }
            if (this.Path != null)
            {
                return(this.Path.Equals(that.Path));
            }
            else
            {
                return(that.Path == null);
            }
        }
Example #2
0
        /// <summary>
        /// Checks if this URLPermission implies the given permission.
        /// Specifically, the following checks are done as if in the
        /// following sequence:
        /// <ul>
        /// <li>if 'p' is not an instance of URLPermission return false</li>
        /// <li>if any of p's methods are not in this's method list, and if
        ///     this's method list is not equal to "*", then return false.</li>
        /// <li>if any of p's headers are not in this's request header list, and if
        ///     this's request header list is not equal to "*", then return false.</li>
        /// <li>if this's url scheme is not equal to p's url scheme return false</li>
        /// <li>if the scheme specific part of this's url is '*' return true</li>
        /// <li>if the set of hosts defined by p's url hostrange is not a subset of
        ///     this's url hostrange then return false. For example, "*.foo.oracle.com"
        ///     is a subset of "*.oracle.com". "foo.bar.oracle.com" is not
        ///     a subset of "*.foo.oracle.com"</li>
        /// <li>if the portrange defined by p's url is not a subset of the
        ///     portrange defined by this's url then return false.
        /// <li>if the path or paths specified by p's url are contained in the
        ///     set of paths specified by this's url, then return true
        /// <li>otherwise, return false</li>
        /// </ul>
        /// <para>Some examples of how paths are matched are shown below:
        /// <table border>
        /// <caption>Examples of Path Matching</caption>
        /// <tr><th>this's path</th><th>p's path</th><th>match</th></tr>
        /// <tr><td>/a/b</td><td>/a/b</td><td>yes</td></tr>
        /// <tr><td>/a/b/*</td><td>/a/b/c</td><td>yes</td></tr>
        /// <tr><td>/a/b/*</td><td>/a/b/c/d</td><td>no</td></tr>
        /// <tr><td>/a/b/-</td><td>/a/b/c/d</td><td>yes</td></tr>
        /// <tr><td>/a/b/-</td><td>/a/b/c/d/e</td><td>yes</td></tr>
        /// <tr><td>/a/b/-</td><td>/a/b/c/*</td><td>yes</td></tr>
        /// <tr><td>/a/b/*</td><td>/a/b/c/-</td><td>no</td></tr>
        /// </table>
        /// </para>
        /// </summary>
        public override bool Implies(Permission p)
        {
            if (!(p is URLPermission))
            {
                return(false);
            }

            URLPermission that = (URLPermission)p;

            if (!this.Methods[0].Equals("*") && Collections.IndexOfSubList(this.Methods, that.Methods) == -1)
            {
                return(false);
            }

            if (this.RequestHeaders.Count == 0 && that.RequestHeaders.Count > 0)
            {
                return(false);
            }

            if (this.RequestHeaders.Count > 0 && !this.RequestHeaders[0].Equals("*") && Collections.IndexOfSubList(this.RequestHeaders, that.RequestHeaders) == -1)
            {
                return(false);
            }

            if (!this.Scheme.Equals(that.Scheme))
            {
                return(false);
            }

            if (this.Ssp.Equals("*"))
            {
                return(true);
            }

            if (!this.Authority.Implies(that.Authority))
            {
                return(false);
            }

            if (this.Path == null)
            {
                return(that.Path == null);
            }
            if (that.Path == null)
            {
                return(false);
            }

            if (this.Path.EndsWith("/-"))
            {
                String thisprefix = this.Path.Substring(0, this.Path.Length() - 1);
                return(that.Path.StartsWith(thisprefix));
            }

            if (this.Path.EndsWith("/*"))
            {
                String thisprefix = this.Path.Substring(0, this.Path.Length() - 1);
                if (!that.Path.StartsWith(thisprefix))
                {
                    return(false);
                }
                String thatsuffix = that.Path.Substring(thisprefix.Length());
                // suffix must not contain '/' chars
                if (thatsuffix.IndexOf('/') != -1)
                {
                    return(false);
                }
                if (thatsuffix.Equals("-"))
                {
                    return(false);
                }
                return(true);
            }
            return(this.Path.Equals(that.Path));
        }