static boolean impliesPath(String ourName, String theirName) { if ("<<ALL FILES>>".equals(ourName)) { return true; } return impliesPath(ourName, theirName, 0); }
private boolean impliesUnchecked(final VirtualFilePermission permission) { final int theirFlags = permission.actionFlags; return (actionFlags & theirFlags) == theirFlags && impliesPath(getName(), permission.getName()); }
private static boolean impliesPath(String ourName, String theirName, int idx) { final int ourLen = ourName.length(); final int theirLen = theirName.length(); final int ei1 = ourIndexOf(ourName, '/', idx); final int ei2 = ourIndexOf(theirName, '/', idx); if (ei1 == idx + 1) { final char ch = ourName.charAt(idx); if (ch == '-') { // recursive wildcard... // if they are non-empty, match return theirLen > idx; // otherwise their segment is empty (no match) } else if (ch == '*') { // non-recursive wildcard... // if they are non-empty, and this is their last segment, match, unless they are '-' return theirLen > idx && ei2 == theirLen && (ei2 != ei1 || theirName.charAt(idx) != '-'); } } if (ei1 == ei2) { if (ei1 == ourLen && ei2 == theirLen) { // exact match return true; } else { // leading sequence matches, check next segment return impliesPath(ourName, theirName, ei1 + 1); } } else { return false; } }
private boolean implies(final VirtualFilePermission permission) { assert permission != null; // else the above check would have failed int remainingFlags = permission.getActionFlags(); if (remainingFlags == 0) { return true; } // snapshot final VirtualFilePermission[] permissions = this.permissions; final String theirName = permission.getName(); for (VirtualFilePermission ourPermission : permissions) { if (VirtualFilePermission.impliesPath(ourPermission.getName(), theirName)) { remainingFlags &= ~ourPermission.getActionFlags(); if (remainingFlags == 0) { return true; } } } return false; }