当前位置: 首页>>代码示例>>Java>>正文


Java SecurityPermission类代码示例

本文整理汇总了Java中java.security.SecurityPermission的典型用法代码示例。如果您正苦于以下问题:Java SecurityPermission类的具体用法?Java SecurityPermission怎么用?Java SecurityPermission使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


SecurityPermission类属于java.security包,在下文中一共展示了SecurityPermission类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getRestrictedPermissions

import java.security.SecurityPermission; //导入依赖的package包/类
static PermissionCollection getRestrictedPermissions() {
    Permissions perms = new Permissions();
    // property/env access needed for parsing
    perms.add(new PropertyPermission("*", "read"));
    perms.add(new RuntimePermission("getenv.TIKA_CONFIG"));

    // add permissions for resource access:
    // classpath
    addReadPermissions(perms, JarHell.parseClassPath());
    // plugin jars
    if (TikaImpl.class.getClassLoader() instanceof URLClassLoader) {
        addReadPermissions(perms, ((URLClassLoader)TikaImpl.class.getClassLoader()).getURLs());
    }
    // jvm's java.io.tmpdir (needs read/write)
    perms.add(new FilePermission(System.getProperty("java.io.tmpdir") + System.getProperty("file.separator") + "-",
                                 "read,readlink,write,delete"));
    // current hacks needed for POI/PDFbox issues:
    perms.add(new SecurityPermission("putProviderProperty.BC"));
    perms.add(new SecurityPermission("insertProvider"));
    perms.add(new ReflectPermission("suppressAccessChecks"));
    // xmlbeans, use by POI, needs to get the context classloader
    perms.add(new RuntimePermission("getClassLoader"));
    perms.setReadOnly();
    return perms;
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:26,代码来源:TikaImpl.java

示例2: setBasicPermissions

import java.security.SecurityPermission; //导入依赖的package包/类
public void setBasicPermissions() {
    permissions.add(new SecurityPermission("getPolicy"));
    permissions.add(new SecurityPermission("setPolicy"));
    permissions.add(new RuntimePermission("getClassLoader"));
    permissions.add(new RuntimePermission("setSecurityManager"));
    permissions.add(new RuntimePermission("createSecurityManager"));
    permissions.add(new PropertyPermission("testng.show.stack.frames",
            "read"));
    permissions.add(new PropertyPermission("user.dir", "read"));
    permissions.add(new PropertyPermission("test.src", "read"));
    permissions.add(new PropertyPermission("file.separator", "read"));
    permissions.add(new PropertyPermission("line.separator", "read"));
    permissions.add(new PropertyPermission("fileStringBuffer", "read"));
    permissions.add(new PropertyPermission("dataproviderthreadcount", "read"));
    permissions.add(new FilePermission("<<ALL FILES>>", "execute"));
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:17,代码来源:PermissionTest.java

示例3: permissivePolicy

import java.security.SecurityPermission; //导入依赖的package包/类
/**
 * Returns a policy containing all the permissions we ever need.
 */
public static Policy permissivePolicy() {
    return new AdjustablePolicy
        // Permissions j.u.c. needs directly
        (new RuntimePermission("modifyThread"),
         new RuntimePermission("getClassLoader"),
         new RuntimePermission("setContextClassLoader"),
         // Permissions needed to change permissions!
         new SecurityPermission("getPolicy"),
         new SecurityPermission("setPolicy"),
         new RuntimePermission("setSecurityManager"),
         // Permissions needed by the junit test harness
         new RuntimePermission("accessDeclaredMembers"),
         new PropertyPermission("*", "read"),
         new java.io.FilePermission("<<ALL FILES>>", "read"));
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:19,代码来源:JSR166TestCase.java

示例4: permissivePolicy

import java.security.SecurityPermission; //导入依赖的package包/类
/**
     * Returns a policy containing all the permissions we ever need.
     */
    public static Policy permissivePolicy() {
        return new AdjustablePolicy
            // Permissions j.u.c. needs directly
            (new RuntimePermission("modifyThread"),
             new RuntimePermission("getClassLoader"),
             new RuntimePermission("setContextClassLoader"),
//             new RuntimePermission("modifyThreadGroup"),
//             new RuntimePermission("enableContextClassLoaderOverride"),
             // Permissions needed to change permissions!
             new SecurityPermission("getPolicy"),
             new SecurityPermission("setPolicy"),
             new RuntimePermission("setSecurityManager"),
             // Permissions needed by the junit test harness
             new RuntimePermission("accessDeclaredMembers"),
             new PropertyPermission("*", "read"),
             new java.io.FilePermission("<<ALL FILES>>", "read"));
    }
 
开发者ID:streamsupport,项目名称:streamsupport,代码行数:21,代码来源:JSR166TestCase.java

示例5: checkSecurityPermission

import java.security.SecurityPermission; //导入依赖的package包/类
protected boolean checkSecurityPermission(SecurityPermission perm) {

		String name = perm.getName();

		if (name.equals("getDomainCombiner") || name.equals("getPolicy")
				|| name.equals("printIdentity") || name.equals("getSignerPrivateKey")
				|| name.startsWith("getProperty.")) {
			return true;
		}

		/*
		 * this seems needed when analyzing classpath, but not fully sure of its consequences
		 */
		if (name.startsWith("putProviderProperty.")) {
			return true;
		}

		/*
		 * createAccessControlContext setPolicy createPolicy.{policy type} setProperty.{key} insertProvider.{provider name} removeProvider.{provider
		 * name} setSystemScope setIdentityPublicKey setIdentityInfo addIdentityCertificate removeIdentityCertificate
		 * clearProviderProperties.{provider name} putProviderProperty.{provider name} removeProviderProperty.{provider name} setSignerKeyPair
		 */
		return false;
	}
 
开发者ID:EvoSuite,项目名称:evosuite,代码行数:25,代码来源:MSecurityManager.java

示例6: test_checkGuardLjava_lang_Object

import java.security.SecurityPermission; //导入依赖的package包/类
/**
 * @tests java.security.Permission#checkGuard(java.lang.Object)
 */
@TestTargetNew(
    level = TestLevel.PARTIAL_COMPLETE,
    notes = "",
    method = "checkGuard",
    args = {java.lang.Object.class}
)
public void test_checkGuardLjava_lang_Object() {
    // test method java.security.permission.checkGuard(object)
    SecurityPermission permi = new SecurityPermission(
            "Testing the permission abstract class");
    String name = permi.getName();
    try {
        permi.checkGuard(name);
    } catch (SecurityException e) {
        fail("security not granted when it is suppose to be : " + e);
    }
}
 
开发者ID:keplersj,项目名称:In-the-Box-Fork,代码行数:21,代码来源:Permission2Test.java

示例7: test_getName

import java.security.SecurityPermission; //导入依赖的package包/类
/**
 * @tests java.security.Permission#getName()
 */
@TestTargetNew(
    level = TestLevel.COMPLETE,
    notes = "",
    method = "getName",
    args = {}
)
public void test_getName() {
    // test method java.security.permission.getName()
    SecurityPermission permi = new SecurityPermission("testing getName()");
    String name = permi.getName();
    assertEquals("getName failed to obtain the correct name",
            "testing getName()", name);

    SecurityPermission permi2 = new SecurityPermission("93048Helloworld");
    assertEquals("getName failed to obtain correct name",
            "93048Helloworld", permi2.getName());
}
 
开发者ID:keplersj,项目名称:In-the-Box-Fork,代码行数:21,代码来源:Permission2Test.java

示例8: assertCodeBasePropertyExpansion

import java.security.SecurityPermission; //导入依赖的package包/类
/**
 * Asserts codeBase property expansion in policy file
 *
 * @param codeSourceURL -
 *            code source for policy object
 * @param codeBaseURL -
 *            system propery value for expansion in policy file
 */
private void assertCodeBasePropertyExpansion(String codeSourceURL,
        String codeBaseURL) throws Exception {

    Policy.setPolicy(null); // reset policy
    System.setProperty("test.bin.dir", codeBaseURL);

    Policy p = Policy.getPolicy();
    CodeSource codeSource = new CodeSource(
            new URL("file:" + codeSourceURL),
            (java.security.cert.Certificate[]) null);

    PermissionCollection pCollection = p.getPermissions(codeSource);
    Enumeration<Permission> elements = pCollection.elements();

    SecurityPermission perm = new SecurityPermission(
            "codeBaseForPolicyTest");

    while (elements.hasMoreElements()) {
        if (elements.nextElement().equals(perm)) {
            return; // passed
        }
    }
    fail("Failed to find SecurityPermission for codeSource="
            + codeSourceURL + ", codeBase=" + codeBaseURL);
}
 
开发者ID:keplersj,项目名称:In-the-Box-Fork,代码行数:34,代码来源:PolicyTest.java

示例9: test_impliesLjava_security_Permission

import java.security.SecurityPermission; //导入依赖的package包/类
/**
 * @tests java.security.AllPermission#implies(java.security.Permission)
 */
@TestTargetNew(
    level = TestLevel.COMPLETE,
    notes = "",
    method = "implies",
    args = {java.security.Permission.class}
)
public void test_impliesLjava_security_Permission() {
    // Test for method boolean
    // java.security.AllPermission.implies(java.security.Permission)
    assertTrue("AllPermission does not imply a AllPermission.",
            new AllPermission().implies(new AllPermission()));
    assertTrue("AllPermission does not imply a SecurityPermission.",
            new AllPermission().implies(new SecurityPermission("ugh!")));
    assertTrue("SecurityPermission implies AllPermission.",
            !(new SecurityPermission("ugh!").implies(new AllPermission())));
    assertTrue("AllPermission does not imply when parametr NULL", new AllPermission().implies(null));
}
 
开发者ID:keplersj,项目名称:In-the-Box-Fork,代码行数:21,代码来源:AllPermission2Test.java

示例10: test_defineClass_defaultDomain

import java.security.SecurityPermission; //导入依赖的package包/类
/**
 * Tests that Classloader.defineClass() assigns appropriate
 * default domains to the defined classes.
 */
public void test_defineClass_defaultDomain() throws Exception {
    // Regression for HARMONY-765
    DynamicPolicy plc = new DynamicPolicy();
    Policy back = Policy.getPolicy();
    try {
        Policy.setPolicy(plc);

        Class<?> a = new Ldr().define();

        Permission p = new SecurityPermission("abc");
        assertFalse("impossible! misconfiguration?", a.getProtectionDomain().implies(p));

        plc.pc = p.newPermissionCollection();
        plc.pc.add(p);
        assertTrue("default domain is not dynamic", a.getProtectionDomain().implies(p));
    } finally {
        Policy.setPolicy(back);
    }
}
 
开发者ID:keplersj,项目名称:In-the-Box-Fork,代码行数:24,代码来源:ClassLoaderTest.java

示例11: checkPermission

import java.security.SecurityPermission; //导入依赖的package包/类
@Override
    public void checkPermission(Permission perm) {
        if (perm.equals(new RuntimePermission("createSecurityManager")) ||
//          perm.equals(new AWTPermission("accessEventQueue")) ||
            perm.equals(new RuntimePermission("createClassLoader")) ||
            perm.equals(new FilePermission(deletedFile,"delete")) ||
            perm.equals(new FilePermission(readedFile,"read")) ||
            perm.equals(new PropertyPermission("*", "read,write")) ||
            perm.equals(new PropertyPermission("key", "read")) ||
            perm.equals(new SecurityPermission("getPolicy")) ||
//          perm.equals(new AWTPermission("accessClipboard")) ||
            perm.equals(new FilePermission(writedFile,"write"))) {
            throw
            new SecurityException("Unable to create Security Manager");
        }
    }
 
开发者ID:keplersj,项目名称:In-the-Box-Fork,代码行数:17,代码来源:MockSecurityManager.java

示例12: test_isReadOnly

import java.security.SecurityPermission; //导入依赖的package包/类
/**
 * @tests java.security.PermissionCollection#isReadOnly()
 */
@TestTargetNew(
    level = TestLevel.COMPLETE,
    notes = "",
    method = "isReadOnly",
    args = {}
)
public void test_isReadOnly() {
    // test java.security.permissionCollection.isReadOnly()
    SecurityPermission permi = new SecurityPermission(
            "testing permissionCollection-isREadOnly");
    PermissionCollection permCollect = permi.newPermissionCollection();
    assertTrue("readOnly has not been set, but isReadOnly returned true",
            !permCollect.isReadOnly());
    permCollect.setReadOnly();
    assertTrue("readOnly is set, but isReadonly returned false",
            permCollect.isReadOnly());
}
 
开发者ID:keplersj,项目名称:In-the-Box-Fork,代码行数:21,代码来源:PermissionCollectionTest.java

示例13: test_setReadOnly

import java.security.SecurityPermission; //导入依赖的package包/类
/**
 * @tests java.security.PermissionCollection#setReadOnly()
 */
@TestTargetNew(
    level = TestLevel.COMPLETE,
    notes = "",
    method = "setReadOnly",
    args = {}
)
public void test_setReadOnly() {
    // test java.security.permissionCollection.setReadOnly()
    SecurityPermission permi = new SecurityPermission(
            "testing permissionCollection-setReadOnly");
    PermissionCollection permCollect = permi.newPermissionCollection();
    assertTrue("readOnly has not been set, but isReadOnly returned true",
            !permCollect.isReadOnly());
    permCollect.setReadOnly();
    assertTrue("readOnly is set, but isReadonly returned false",
            permCollect.isReadOnly());
}
 
开发者ID:keplersj,项目名称:In-the-Box-Fork,代码行数:21,代码来源:PermissionCollectionTest.java

示例14: permissivePolicy

import java.security.SecurityPermission; //导入依赖的package包/类
/** Returns a policy containing all the permissions we ever need. */
public static Policy permissivePolicy() {
  return new AdjustablePolicy
  // Permissions j.u.c. needs directly
  (
      new RuntimePermission("modifyThread"),
      new RuntimePermission("getClassLoader"),
      new RuntimePermission("setContextClassLoader"),
      // Permissions needed to change permissions!
      new SecurityPermission("getPolicy"),
      new SecurityPermission("setPolicy"),
      new RuntimePermission("setSecurityManager"),
      // Permissions needed by the junit test harness
      new RuntimePermission("accessDeclaredMembers"),
      new PropertyPermission("*", "read"),
      new java.io.FilePermission("<<ALL FILES>>", "read"));
}
 
开发者ID:google,项目名称:guava,代码行数:18,代码来源:JSR166TestCase.java

示例15: test_setPolicyLjava_security_Policy

import java.security.SecurityPermission; //导入依赖的package包/类
/**
 * @tests java.security.Policy#setPolicy(java.security.Policy)
 */
public void test_setPolicyLjava_security_Policy() {
    SecurityManager old = System.getSecurityManager();
    Policy oldPolicy = Policy.getPolicy();
    try {
        SecurityChecker checker = new SecurityChecker(
            new SecurityPermission("setPolicy"), true);
        System.setSecurityManager(checker);
        Policy custom = new TestProvider();
        Policy.setPolicy(custom);
        assertTrue(checker.checkAsserted);
        assertSame(custom, Policy.getPolicy());

        checker.reset();
        checker.enableAccess = false;
        try {
            Policy.setPolicy(new TestProvider());
            fail("SecurityException is intercepted");
        } catch (SecurityException ok) {
        }
    } finally {
        System.setSecurityManager(old);
        Policy.setPolicy(oldPolicy);
    }
}
 
开发者ID:shannah,项目名称:cn1,代码行数:28,代码来源:PolicyTest.java


注:本文中的java.security.SecurityPermission类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。