本文整理匯總了Java中java.security.PermissionCollection.add方法的典型用法代碼示例。如果您正苦於以下問題:Java PermissionCollection.add方法的具體用法?Java PermissionCollection.add怎麽用?Java PermissionCollection.add使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類java.security.PermissionCollection
的用法示例。
在下文中一共展示了PermissionCollection.add方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: getPermissions
import java.security.PermissionCollection; //導入方法依賴的package包/類
/**
* Get the Permissions for a CodeSource. If this instance of
* WebappClassLoaderBase is for a web application context, add read
* FilePermission or JndiPermissions for the base directory (if unpacked),
* the context URL, and jar file resources.
*
* @param codeSource
* where the code was loaded from
* @return PermissionCollection for CodeSource
*/
@Override
protected PermissionCollection getPermissions(CodeSource codeSource) {
String codeUrl = codeSource.getLocation().toString();
PermissionCollection pc;
if ((pc = loaderPC.get(codeUrl)) == null) {
pc = super.getPermissions(codeSource);
if (pc != null) {
Iterator<Permission> perms = permissionList.iterator();
while (perms.hasNext()) {
Permission p = perms.next();
pc.add(p);
}
loaderPC.put(codeUrl, pc);
}
}
return (pc);
}
示例2: getPermissions
import java.security.PermissionCollection; //導入方法依賴的package包/類
/**
* Get the Permissions for a CodeSource. If this instance
* of WebappClassLoader is for a web application context,
* add read FilePermission or JndiPermissions for the base
* directory (if unpacked),
* the context URL, and jar file resources.
*
// * @param CodeSource where the code was loaded from
* @return PermissionCollection for CodeSource
*/
protected PermissionCollection getPermissions(CodeSource codeSource) {
String codeUrl = codeSource.getLocation().toString();
PermissionCollection pc;
if ((pc = (PermissionCollection)loaderPC.get(codeUrl)) == null) {
pc = super.getPermissions(codeSource);
if (pc != null) {
Iterator perms = permissionList.iterator();
while (perms.hasNext()) {
Permission p = (Permission)perms.next();
pc.add(p);
}
loaderPC.put(codeUrl,pc);
}
}
return (pc);
}
示例3: main
import java.security.PermissionCollection; //導入方法依賴的package包/類
public static void main(String... args) throws Exception {
if (args.length > 0 && args[0].equals("sm")) {
PermissionCollection perms = new Permissions();
perms.add(new RuntimePermission("getStackWalkerWithClassReference"));
Policy.setPolicy(new Policy() {
@Override
public boolean implies(ProtectionDomain domain, Permission p) {
return perms.implies(p);
}
});
System.setSecurityManager(new SecurityManager());
}
new GetCallerClassTest(StackWalker.getInstance(), true).test();
new GetCallerClassTest(StackWalker.getInstance(RETAIN_CLASS_REFERENCE), false).test();
new GetCallerClassTest(StackWalker.getInstance(EnumSet.of(RETAIN_CLASS_REFERENCE,
SHOW_HIDDEN_FRAMES)), false).test();
}
示例4: 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());
}
}
示例5: getPermissions
import java.security.PermissionCollection; //導入方法依賴的package包/類
/**
* allow any classes loaded from classpath to exit the VM.
*/
protected PermissionCollection getPermissions(CodeSource codesource)
{
PermissionCollection perms = super.getPermissions(codesource);
perms.add(new RuntimePermission("exitVM"));
return perms;
}
示例6: testPermissionCollection
import java.security.PermissionCollection; //導入方法依賴的package包/類
public void testPermissionCollection() {
ClassPermission math = new ClassPermission("java.lang.Math");
PermissionCollection collection = math.newPermissionCollection();
collection.add(math);
assertTrue(collection.implies(new ClassPermission("java.lang.Math")));
assertFalse(collection.implies(new ClassPermission("pkg.MyClass")));
}
示例7: getAccessControlContext
import java.security.PermissionCollection; //導入方法依賴的package包/類
/**
* Generates an AccessControlContext with minimal permissions.
* The approach used here is taken from the similar method
* getAccessControlContext() in the sun.applet.AppletPanel class.
*/
private static AccessControlContext getAccessControlContext(int port) {
// begin with permissions granted to all code in current policy
PermissionCollection perms = AccessController.doPrivileged(
new java.security.PrivilegedAction<PermissionCollection>() {
public PermissionCollection run() {
CodeSource codesource = new CodeSource(null,
(java.security.cert.Certificate[]) null);
Policy p = java.security.Policy.getPolicy();
if (p != null) {
return p.getPermissions(codesource);
} else {
return new Permissions();
}
}
});
/*
* Anyone can connect to the registry and the registry can connect
* to and possibly download stubs from anywhere. Downloaded stubs and
* related classes themselves are more tightly limited by RMI.
*/
perms.add(new SocketPermission("*", "connect,accept"));
perms.add(new SocketPermission("localhost:"+port, "listen,accept"));
perms.add(new RuntimePermission("accessClassInPackage.sun.jvmstat.*"));
perms.add(new RuntimePermission("accessClassInPackage.sun.jvm.hotspot.*"));
perms.add(new FilePermission("<<ALL FILES>>", "read"));
/*
* Create an AccessControlContext that consists of a single
* protection domain with only the permissions calculated above.
*/
ProtectionDomain pd = new ProtectionDomain(
new CodeSource(null,
(java.security.cert.Certificate[]) null), perms);
return new AccessControlContext(new ProtectionDomain[] { pd });
}
示例8: testPermissionCollectionWildcards
import java.security.PermissionCollection; //導入方法依賴的package包/類
public void testPermissionCollectionWildcards() {
ClassPermission lang = new ClassPermission("java.lang.*");
PermissionCollection collection = lang.newPermissionCollection();
collection.add(lang);
assertTrue(collection.implies(new ClassPermission("java.lang.Math")));
assertFalse(collection.implies(new ClassPermission("pkg.MyClass")));
}
示例9: main
import java.security.PermissionCollection; //導入方法依賴的package包/類
public static void main(String... args) throws Throwable {
boolean sm = false;
if (args.length > 0 && args[0].equals("sm")) {
sm = true;
PermissionCollection perms = new Permissions();
perms.add(new RuntimePermission("getStackWalkerWithClassReference"));
Policy.setPolicy(new Policy() {
@Override
public boolean implies(ProtectionDomain domain, Permission p) {
return perms.implies(p);
}
});
System.setSecurityManager(new SecurityManager());
}
System.err.format("Test %s security manager.%n",
sm ? "with" : "without");
CallerSensitiveTest cstest = new CallerSensitiveTest();
// test static call to java.util.CSM::caller and CSM::getCallerClass
cstest.staticMethodCall();
// test java.lang.reflect.Method call
cstest.reflectMethodCall();
// test java.lang.invoke.MethodHandle
cstest.invokeMethodHandle(Lookup1.lookup);
cstest.invokeMethodHandle(Lookup2.lookup);
// test method ref
cstest.lambda();
LambdaTest.lambda();
if (failed > 0) {
throw new RuntimeException(failed + " test cases failed.");
}
}
示例10: createPermissions
import java.security.PermissionCollection; //導入方法依賴的package包/類
protected PermissionCollection createPermissions(CodeSource cs, InputOutput io) {
PermissionCollection allPerms = new Permissions();
allPerms.add(new AllPermission());
allPerms.setReadOnly();
return allPerms;
}
示例11: getPermissions
import java.security.PermissionCollection; //導入方法依賴的package包/類
@Override
protected PermissionCollection getPermissions(CodeSource codesource) {
final PermissionCollection p = super.getPermissions(codesource);
p.add(new AllPermission());
return p;
}
示例12: getPermissions
import java.security.PermissionCollection; //導入方法依賴的package包/類
protected PermissionCollection getPermissions(CodeSource codesource)
{
PermissionCollection perms = super.getPermissions(codesource);
perms.add(new AllPermission());
return perms;
}
示例13: getPermissions
import java.security.PermissionCollection; //導入方法依賴的package包/類
protected PermissionCollection getPermissions(CodeSource codesource) {
PermissionCollection perms = super.getPermissions(codesource);
perms.add(new AllPermission());
return perms;
}
示例14: getLoaderAccessControlContext
import java.security.PermissionCollection; //導入方法依賴的package包/類
/**
* Return the access control context that a loader for the given
* codebase URL path should execute with.
*/
private static AccessControlContext getLoaderAccessControlContext(
URL[] urls)
{
/*
* The approach used here is taken from the similar method
* getAccessControlContext() in the sun.applet.AppletPanel class.
*/
// begin with permissions granted to all code in current policy
PermissionCollection perms =
java.security.AccessController.doPrivileged(
new java.security.PrivilegedAction<PermissionCollection>() {
public PermissionCollection run() {
CodeSource codesource = new CodeSource(null,
(java.security.cert.Certificate[]) null);
Policy p = java.security.Policy.getPolicy();
if (p != null) {
return p.getPermissions(codesource);
} else {
return new Permissions();
}
}
});
// createClassLoader permission needed to create loader in context
perms.add(new RuntimePermission("createClassLoader"));
// add permissions to read any "java.*" property
perms.add(new java.util.PropertyPermission("java.*","read"));
// add permissions reuiqred to load from codebase URL path
addPermissionsForURLs(urls, perms, true);
/*
* Create an AccessControlContext that consists of a single
* protection domain with only the permissions calculated above.
*/
ProtectionDomain pd = new ProtectionDomain(
new CodeSource((urls.length > 0 ? urls[0] : null),
(java.security.cert.Certificate[]) null),
perms);
return new AccessControlContext(new ProtectionDomain[] { pd });
}
示例15: 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");
}
}