本文整理匯總了Java中java.security.PermissionCollection.elements方法的典型用法代碼示例。如果您正苦於以下問題:Java PermissionCollection.elements方法的具體用法?Java PermissionCollection.elements怎麽用?Java PermissionCollection.elements使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類java.security.PermissionCollection
的用法示例。
在下文中一共展示了PermissionCollection.elements方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: addAllPermissions
import java.security.PermissionCollection; //導入方法依賴的package包/類
/**
* Copies all permissions from <tt>src</tt> into <tt>target</tt>
*
* @param target To where put permissions
* @param src From where take paermissions
*/
private static void addAllPermissions(PermissionCollection target, PermissionCollection src) {
Enumeration e = src.elements();
while (e.hasMoreElements()) {
target.add((Permission) e.nextElement());
}
}
示例2: addAll
import java.security.PermissionCollection; //導入方法依賴的package包/類
public PermissionsBuilder addAll(PermissionCollection col) {
if (col != null) {
for (Enumeration<Permission> e = col.elements(); e.hasMoreElements(); ) {
perms.add(e.nextElement());
}
}
return this;
}
示例3: 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");
}
}