/** * Indicates whether this permissions collection implies a specific * {@code permission}. * * @param permission * the permission to check. * @see java.security.PermissionCollection#implies(java.security.Permission) */ public override bool implies(java.security.Permission permission) { if (permission is FilePermission) { FilePermission fp = (FilePermission)permission; int matchedMask = 0; int i = 0; while (i < permissions.size() && ((matchedMask & fp.mask) != fp.mask)) { // Cast will not fail since we added it matchedMask |= ((FilePermission)permissions.elementAt(i)) .impliesMask(permission); i++; } return((matchedMask & fp.mask) == fp.mask); } return(false); }
/** * 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. * * @param obj * the object to check equality with. * @return {@code true} if this file permission is equal to {@code obj}, * {@code false} otherwise. */ public override bool Equals(Object obj) { if (obj is 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); }
/** * Returns an int describing what masks are implied by a specific * permission. * * @param p * the permission * @return the mask applied to the given permission */ internal int impliesMask(java.security.Permission p) { if (!(p is 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); } bool 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); }