本文整理匯總了Java中java.security.PermissionCollection.implies方法的典型用法代碼示例。如果您正苦於以下問題:Java PermissionCollection.implies方法的具體用法?Java PermissionCollection.implies怎麽用?Java PermissionCollection.implies使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類java.security.PermissionCollection
的用法示例。
在下文中一共展示了PermissionCollection.implies方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: check
import java.security.PermissionCollection; //導入方法依賴的package包/類
@Override
public boolean check(Permission permission) {
if (!Globals.IS_SECURITY_ENABLED) {
return true;
}
Policy currentPolicy = Policy.getPolicy();
if (currentPolicy != null) {
ResourceEntry entry = findResourceInternal("/", "/", false);
if (entry != null) {
CodeSource cs = new CodeSource(
entry.codeBase, (java.security.cert.Certificate[]) null);
PermissionCollection pc = currentPolicy.getPermissions(cs);
if (pc.implies(permission)) {
return true;
}
}
}
return false;
}
示例2: check
import java.security.PermissionCollection; //導入方法依賴的package包/類
@Override
public boolean check(Permission permission) {
if (!Globals.IS_SECURITY_ENABLED) {
return true;
}
Policy currentPolicy = Policy.getPolicy();
if (currentPolicy != null) {
ResourceEntry entry = findResourceInternal("/", "/", false);
if (entry != null) {
CodeSource cs = new CodeSource(entry.codeBase, (java.security.cert.Certificate[]) null);
PermissionCollection pc = currentPolicy.getPermissions(cs);
if (pc.implies(permission)) {
return true;
}
}
}
return false;
}
示例3: checkPermission
import java.security.PermissionCollection; //導入方法依賴的package包/類
private static void checkPermission(PermissionCollection perms,
Permission p)
throws AccessControlException
{
if (!perms.implies(p)) {
throw new AccessControlException(
"access denied " + p.toString());
}
}
示例4: main
import java.security.PermissionCollection; //導入方法依賴的package包/類
public static void main(String[] args) throws Exception {
String userDir = System.getProperty("user.dir");
String jarURL = "jar:file:" + userDir + File.separator + "foo.jar!/";
URL codeSourceURL = new URL(jarURL);
CodeSource cs = new CodeSource(codeSourceURL, new Certificate[0]);
PermissionCollection perms = Policy.getPolicy().getPermissions(cs);
if (!perms.implies(new AllPermission()))
throw new Exception("FAILED: " + codeSourceURL
+ " not granted AllPermission");
}
示例5: main
import java.security.PermissionCollection; //導入方法依賴的package包/類
public static void main(String[] args) throws Exception {
int testFail = 0;
TestPermission perm = new TestPermission("foo");
PermissionCollection perms = perm.newPermissionCollection();
// test 1
System.out.println("test 1: add throws IllegalArgumentExc");
try {
perms.add(new SecurityPermission("createAccessControlContext"));
System.err.println("Expected IllegalArgumentException");
testFail++;
} catch (IllegalArgumentException iae) {}
// test 2
System.out.println("test 2: implies returns false for wrong class");
if (perms.implies(new SecurityPermission("getPolicy"))) {
System.err.println("Expected false, returned true");
testFail++;
}
// test 3
System.out.println("test 3: implies returns true for match on name");
perms.add(new TestPermission("foo"));
if (!perms.implies(new TestPermission("foo"))) {
System.err.println("Expected true, returned false");
testFail++;
}
// test 4
System.out.println("test 4: implies returns true for wildcard match");
perms.add(new TestPermission("bar.*"));
if (!perms.implies(new TestPermission("bar.foo"))) {
System.err.println("Expected true, returned false");
testFail++;
}
// test 5
System.out.println
("test 5: implies returns false for invalid wildcard");
perms.add(new TestPermission("baz*"));
if (perms.implies(new TestPermission("baz.foo"))) {
System.err.println("Expected false, returned true");
testFail++;
}
// test 6
System.out.println
("test 6: implies returns true for deep wildcard match");
if (!perms.implies(new TestPermission("bar.foo.baz"))) {
System.err.println("Expected true, returned false");
testFail++;
}
// test 7
System.out.println
("test 7: implies returns true for all wildcard match");
perms.add(new TestPermission("*"));
if (!perms.implies(new TestPermission("yes"))) {
System.err.println("Expected true, returned false");
testFail++;
}
// test 8
System.out.println("test 8: elements returns correct number of perms");
int numPerms = 0;
Enumeration<Permission> e = perms.elements();
while (e.hasMoreElements()) {
numPerms++;
System.out.println(e.nextElement());
}
if (numPerms != 4) {
System.err.println("Expected 4, got " + numPerms);
testFail++;
}
if (testFail > 0) {
throw new Exception(testFail + " test(s) failed");
}
}
示例6: main
import java.security.PermissionCollection; //導入方法依賴的package包/類
public static void main(String[] args) throws Exception {
int testFail = 0;
DelegationPermission perm = new DelegationPermission(FOO + " " + TGT);
PermissionCollection perms = perm.newPermissionCollection();
// test 1
System.out.println
("test 1: add throws IllegalArgException for wrong perm type");
try {
perms.add(new SecurityPermission("createAccessControlContext"));
System.err.println("Expected IllegalArgumentException");
testFail++;
} catch (IllegalArgumentException iae) {}
// test 2
System.out.println("test 2: implies returns false for wrong perm type");
if (perms.implies(new SecurityPermission("getPolicy"))) {
System.err.println("Expected false, returned true");
testFail++;
}
// test 3
System.out.println("test 3: implies returns true for match on name");
perms.add(new DelegationPermission(FOO + " " + TGT));
if (!perms.implies(new DelegationPermission(FOO + " " + TGT))) {
System.err.println("Expected true, returned false");
testFail++;
}
// test 4
System.out.println
("test 4: implies returns false for non-match on name");
if (perms.implies(new DelegationPermission(BAR + " " + TGT))) {
System.err.println("Expected false, returned true");
testFail++;
}
// test 5
System.out.println("test 5: elements returns correct number of perms");
int numPerms = 0;
Enumeration<Permission> e = perms.elements();
while (e.hasMoreElements()) {
numPerms++;
System.out.println(e.nextElement());
}
if (numPerms != 1) {
System.err.println("Expected 1, got " + numPerms);
testFail++;
}
if (testFail > 0) {
throw new Exception(testFail + " test(s) failed");
}
}