URLPatternSpecpublic class URLPatternSpec extends javax.security.jacc.URLPattern This class extends the URLPattern class and is used to represent
URLPatternSpec objects.
URLPatternSpec objects occur withing WebResourcePermission and
WebUserDataPermission objects.
|
Fields Summary |
---|
private static String | DEFAULT_PATTERN | private static String | EMPTY_STRING | private transient int | hashCodeValue | private String | canonicalSpec | private final String | urlPatternList | private javax.security.jacc.URLPattern[] | urlPatternArray |
Constructors Summary |
---|
public URLPatternSpec(String urlPatternSpec)Creates a new URLPatternSpec that identifies the web
resources to which a WebResourcePermission or WebUserDataPermission
applies. The syntax of the name
parameter is as follows:
URLPatternList ::= URLPattern | URLPatternList colon URLPattern
URLPatternSpec ::= URLPattern | URLPattern colon URLPatternList
name ::= URLPatternSpec
The first URLPattern in a URLPatternSpec may be any of the pattern
types, exact, path-prefix, extension, or default as defined in the
Java Servlet Specification). When a URLPatternSpec includes
a URLPatternList, the patterns of the URLPatternList identify the
resources to which the permission does NOT apply and depend on the
pattern type and value of the first pattern as follows:
- No pattern may exist in the URLPatternList that matches the
first pattern.
- If the first pattern is a path-prefix
pattern, only exact patterns matched by the first pattern
and path-prefix patterns matched by, but different from,
the first pattern may occur in the URLPatternList.
- If the first pattern is an extension
pattern, only exact patterns that are matched by the first
pattern and path-prefix patterns may occur in the URLPatternList.
- If the first pattern is the default pattern, "/", any pattern
except the default pattern may occur in the URLPatternList.
- If the first pattern is an exact pattern a URLPatternList must not
be present in the URLPatternSpec.
super(getFirstPattern(urlPatternSpec));
int colon = urlPatternSpec.indexOf(":");
if (colon >= 0) {
urlPatternList = urlPatternSpec.substring(colon+1);
setURLPatternArray();
}
else urlPatternList = null;
|
Methods Summary |
---|
public boolean | equals(java.lang.Object o)
if (o == null || ! (o instanceof URLPatternSpec)) return false;
URLPatternSpec that = (URLPatternSpec) o;
return this.toString().equals(that.toString());
| private static java.lang.String | getFirstPattern(java.lang.String urlPatternSpec)
if (urlPatternSpec == null)
throw new IllegalArgumentException("Invalid URLPatternSpec");
int colon = urlPatternSpec.indexOf(":");
if (colon < 0) return urlPatternSpec;
else if (colon > 0) return urlPatternSpec.substring(0,colon);
else if (colon == 0) return EMPTY_STRING;
throw new IllegalArgumentException("Invalid URLPatternSpec");
| public java.lang.String | getURLPattern()This method returns a String containing the first URLPattern in
this URLPatternSpec.
return super.toString();
| public int | hashCode()Returns the hash code value for this URLPatternSpec
properties of the returned hash code must be as follows:
- During the lifetime of a Java application, the hashCode method
must return the same integer value, every time it is called on a
URLPatternSpec object. The value returned by hashCode for a
particular URlPatternSpec need not remain consistent from
one execution of an application to another.
- If two URLPatternSpec objects are equal according to the
equals method, then calling the hashCode method on each of the two
objects must produce the same integer result (within an
application).
if (hashCodeValue == 0)
hashCodeValue = this.toString().hashCode();
return hashCodeValue;
| public boolean | implies(javax.security.jacc.URLPatternSpec that)Determines if the argument URLPatternSpec is "implied by" this
URLPatternSpec. For this to be the case, all of the following must
be true:
- The argument is an instanceof URLPatternSpec, and
- The first Pattern in the argument URLPatternSpec
is matched by the first URLPattern of this URLPatternSpec.
- The first Pattern in the argument URLPatternSpec
is NOT matched by any URLPattern in the URLPatternList
of this URLPatternSpec.
- If the first Pattern in the argument URLPatternSpec matches
the first Pattern in this URLPatternSpec, then every URLPattern
in the URLPatternList of this URLPatternSpec is matched by
a URLPattern in the URLPatternList of the argument URLPatternSpec.
URLPattern matching is performed using the Servlet matching
rules where two URL patterns match if they are related as follows:
- their pattern values are String equivalent, or
- this pattern is the path-prefix pattern "/*", or
- this pattern is a path-prefix pattern (that is, it starts with
"/" and ends with "/*") and the argument pattern starts with the
substring of this pattern, minus its last 2 characters, and the
next character of the argument pattern, if there is one, is "/", or
- this pattern is an extension pattern (that is, it starts with
"*.") and the argument pattern ends with this pattern, or
- the reference pattern is the special default pattern, "/",
which matches all argument patterns.
All of the comparisons described above are case sensitive.
if (that == null) return false;
if (!super.implies(that)) return false;
for (int i=0; urlPatternArray != null && i<urlPatternArray.length; i++)
if (urlPatternArray[i] != null &&
urlPatternArray[i].implies(that)) return false;
if (urlPatternArray != null && ((URLPattern)that).implies(this)) {
if (that.urlPatternArray == null) return false;
boolean flags[] = new boolean[urlPatternArray.length];
for (int i=0; i<flags.length; i++) flags[i] = false;
int count = 0;
for (int j=0; j<that.urlPatternArray.length; j++) {
for (int i=0; i<flags.length; i++) {
if (!flags[i])
if (urlPatternArray[i] == null ||
(that.urlPatternArray[j] != null &&
that.urlPatternArray[j].implies
(urlPatternArray[i]))) {
count += 1;
flags[i] = true;
if (count == flags.length) return true;
}
}
}
return (count == flags.length);
}
return true;
| private void | setURLPatternArray()
if (urlPatternArray == null && urlPatternList != null) {
String[] tokens = urlPatternList.split(":",-1);
int count = tokens.length;
if (count == 0)
throw new IllegalArgumentException
("colon followed by empty URLPatternList");
urlPatternArray = new URLPattern[count];
int firstType = this.patternType();
for (int i=0; i<count; i++) {
urlPatternArray[i] = new URLPattern(tokens[i]);
if (urlPatternArray[i].implies(this))
throw new IllegalArgumentException
("pattern in URLPatternList implies first pattern");
switch(firstType) {
case URLPattern.PT_PREFIX:
case URLPattern.PT_EXTENSION:
switch (urlPatternArray[i].patternType()) {
case URLPattern.PT_PREFIX:
if (firstType == URLPattern.PT_PREFIX) {
if (super.equals(urlPatternArray[i]) ||
!super.implies(urlPatternArray[i]))
throw new IllegalArgumentException
("Invalid prefix pattern in URLPatternList");
}
break;
case URLPattern.PT_EXACT:
if (!super.implies(urlPatternArray[i]))
throw new IllegalArgumentException
("Invalid exact pattern in URLPatternList");
break;
default:
throw new IllegalArgumentException
("Invalid pattern type in URLPatternList");
}
case URLPattern.PT_DEFAULT:
if (super.equals(urlPatternArray[i]))
throw new IllegalArgumentException
("Invalid default pattern in URLPatternList");
break;
case URLPattern.PT_EXACT:
throw new IllegalArgumentException
("invalid URLPatternSpec");
default:
throw new IllegalArgumentException
("Invalid pattern type in URLPatternList");
}
}
Arrays.sort(urlPatternArray);
for (int i=0; i<urlPatternArray.length; i++) {
if (urlPatternArray[i] != null) {
switch(urlPatternArray[i].patternType()) {
case URLPattern.PT_PREFIX:
for (int j=i+1; j<urlPatternArray.length; j++)
if (urlPatternArray[i].implies(urlPatternArray[j]))
urlPatternArray[j] = null;
break;
default:
break;
}
}
}
}
| public java.lang.String | toString()
if (canonicalSpec == null) {
if (urlPatternList == null)
canonicalSpec = new String(super.toString());
else {
StringBuffer s = null;
for (int i=0; i<urlPatternArray.length; i++) {
if (urlPatternArray[i] != null) {
if (s == null)
s = new StringBuffer(urlPatternArray[i].toString());
else s.append(":" + urlPatternArray[i].toString());
}
}
if (s == null) canonicalSpec = new String(super.toString());
else canonicalSpec =
new String(super.toString() + ":" + s.toString());
}
}
return canonicalSpec;
|
|