Methods Summary |
---|
public boolean | equals(java.lang.Object obj)Indicates if this file permission is equal to another. The two are equal
if {@code obj} is a FilePermission, they have the same path, and they
have the same actions.
if (obj instanceof FilePermission) {
FilePermission fp = (FilePermission) obj;
if (fp.actions != actions) {
if (fp.actions == null || !fp.actions.equals(actions)) {
return false;
}
}
/* Matching actions and both are <<ALL FILES>> ? */
if (fp.includeAll || includeAll) {
return fp.includeAll == includeAll;
}
return fp.canonPath.equals(canonPath);
}
return false;
|
public java.lang.String | getActions()Returns the actions associated with this file permission.
return actions;
|
private int | getMask(java.lang.String actionNames)Returns the numerical representation of the argument.
int actionInt = 0, head = 0, tail = 0;
do {
tail = actionNames.indexOf(",", head); //$NON-NLS-1$
String action = tail > 0 ? actionNames.substring(head, tail).trim()
: actionNames.substring(head).trim();
if (action.equals("read")) { //$NON-NLS-1$
actionInt |= 8;
} else if (action.equals("write")) { //$NON-NLS-1$
actionInt |= 4;
} else if (action.equals("execute")) { //$NON-NLS-1$
actionInt |= 2;
} else if (action.equals("delete")) { //$NON-NLS-1$
actionInt |= 1;
} else {
throw new IllegalArgumentException(Msg.getString(
"K006f", action)); //$NON-NLS-1$
}
head = tail + 1;
} while (tail > 0);
return actionInt;
|
public int | hashCode()Calculates the hash code value for this file permission.
return (canonPath == null ? getName().hashCode() : canonPath.hashCode())
+ mask;
|
public boolean | implies(java.security.Permission p)Indicates whether the permission {@code p} is implied by this file
permission. This is the case if {@code p} is an instance of
{@code FilePermission}, if {@code p}'s actions are a subset of this
file permission's actions and if {@code p}'s path is implied by this
file permission's path.
int match = impliesMask(p);
return match != 0 && match == ((FilePermission) p).mask;
|
int | impliesMask(java.security.Permission p)Returns an int describing what masks are implied by a specific
permission.
if (!(p instanceof FilePermission)) {
return 0;
}
FilePermission fp = (FilePermission) p;
int matchedMask = mask & fp.mask;
// Can't match any bits?
if (matchedMask == 0) {
return 0;
}
// Is this permission <<ALL FILES>>
if (includeAll) {
return matchedMask;
}
// We can't imply all files
if (fp.includeAll) {
return 0;
}
// Scan the length of p checking all match possibilities
// \- implies everything except \
int thisLength = canonPath.length();
if (allSubdir && thisLength == 2
&& !fp.canonPath.equals(File.separator)) {
return matchedMask;
}
// need /- to imply /-
if (fp.allSubdir && !allSubdir) {
return 0;
}
// need /- or /* to imply /*
if (fp.allDir && !allSubdir && !allDir) {
return 0;
}
boolean includeDir = false;
int pLength = fp.canonPath.length();
// do not compare the * or -
if (allDir || allSubdir) {
thisLength--;
}
if (fp.allDir || fp.allSubdir) {
pLength--;
}
for (int i = 0; i < pLength; i++) {
char pChar = fp.canonPath.charAt(i);
// Is p longer than this permissions canonLength?
if (i >= thisLength) {
if (i == thisLength) {
// Is this permission include all? (must have matched up
// until this point).
if (allSubdir) {
return matchedMask;
}
// Is this permission include a dir? Continue the check
// afterwards.
if (allDir) {
includeDir = true;
}
}
// If not includeDir then is has to be a mismatch.
if (!includeDir) {
return 0;
}
/**
* If we have * for this and find a separator it is invalid. IE:
* this is '/a/*' and p is '/a/b/c' we should fail on the
* separator after the b. Except for root, canonical paths do
* not end in a separator.
*/
if (pChar == File.separatorChar) {
return 0;
}
} else {
// Are the characters matched?
if (canonPath.charAt(i) != pChar) {
return 0;
}
}
}
// Must have matched up to this point or it's a valid file in an include
// all directory
if (pLength == thisLength) {
if (allSubdir) {
// /- implies /- or /*
return fp.allSubdir || fp.allDir ? matchedMask : 0;
}
return allDir == fp.allDir ? matchedMask : 0;
}
return includeDir ? matchedMask : 0;
|
private void | init(java.lang.String path, java.lang.String pathActions)
if (pathActions == null || pathActions.equals("")) { //$NON-NLS-1$
throw new IllegalArgumentException(Msg.getString("K006d")); //$NON-NLS-1$
}
this.actions = toCanonicalActionString(pathActions);
if (path == null) {
throw new NullPointerException(Msg.getString("K006e")); //$NON-NLS-1$
}
if (path.equals("<<ALL FILES>>")) { //$NON-NLS-1$
includeAll = true;
} else {
canonPath = AccessController
.doPrivileged(new PrivilegedAction<String>() {
public String run() {
try {
return new File(path).getCanonicalPath();
} catch (IOException e) {
return path;
}
}
});
if (path.equals("*") || path.endsWith(File.separator + "*")) { //$NON-NLS-1$ //$NON-NLS-2$
allDir = true;
}
if (path.equals("-") || path.endsWith(File.separator + "-")) { //$NON-NLS-1$ //$NON-NLS-2$
allSubdir = true;
}
}
|
public java.security.PermissionCollection | newPermissionCollection()Returns a new PermissionCollection in which to place FilePermission
objects.
return new FilePermissionCollection();
|
private void | readObject(java.io.ObjectInputStream stream)
stream.defaultReadObject();
init(getName(), actions);
|
private java.lang.String | toCanonicalActionString(java.lang.String action)Returns the string representing this permission's actions. It must be of
the form "read,write,execute,delete", all lower case and in the correct
order if there is more than one action.
actions = action.trim().toLowerCase();
// get the numerical representation of the action list
mask = getMask(actions);
// convert the mask to a canonical action list.
int len = actionList.length;
// the test mask - shift the 1 to the leftmost position of the
// actionList
int highestBitMask = 1 << (len - 1);
// if a bit of mask is set, append the corresponding action to result
StringBuilder result = new StringBuilder();
boolean addedItem = false;
for (int i = 0; i < len; i++) {
if ((highestBitMask & mask) != 0) {
if (addedItem) {
result.append(","); //$NON-NLS-1$
}
result.append(actionList[i]);
addedItem = true;
}
highestBitMask = highestBitMask >> 1;
}
return result.toString();
|
private void | writeObject(java.io.ObjectOutputStream stream)
stream.defaultWriteObject();
|