當前位置: 首頁>>代碼示例>>Java>>正文


Java ProtectionDomain.getPermissions方法代碼示例

本文整理匯總了Java中java.security.ProtectionDomain.getPermissions方法的典型用法代碼示例。如果您正苦於以下問題:Java ProtectionDomain.getPermissions方法的具體用法?Java ProtectionDomain.getPermissions怎麽用?Java ProtectionDomain.getPermissions使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在java.security.ProtectionDomain的用法示例。


在下文中一共展示了ProtectionDomain.getPermissions方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: testLoadingFilterPlugin

import java.security.ProtectionDomain; //導入方法依賴的package包/類
/**
 * Tests loading a class from a jar.
 */
@Test
public void testLoadingFilterPlugin() throws ClassNotFoundException, IllegalAccessException, InstantiationException {
    // Get URL to our jar
    final URL jar = getClass().getClassLoader().getResource("testDeserializer/testPlugins.jar");
    final String classPath = "examples.filter.LowOffsetFilter";

    // Create class loader
    final PluginClassLoader pluginClassLoader = new PluginClassLoader(jar, getClass().getClassLoader());

    final Class<? extends RecordFilter> filterPlugin = (Class<? extends RecordFilter>) pluginClassLoader.loadClass(classPath);
    assertNotNull("Should not be null", filterPlugin);

    // Create an instance of it and validate.
    final RecordFilter filter = filterPlugin.newInstance();
    final String topic = "MyTopic";
    final int partition = 2;
    final long offset = 2423L;
    final Object key = "key";
    final Object value = "{name='Bob', value='value'}";
    filter.includeRecord(topic, partition, offset, key, value);

    // Validate it came from our classloader, more of a sanity test.
    assertTrue("Should have our parent class loader", filter.getClass().getClassLoader() instanceof PluginClassLoader);

    // Validate permission set defined
    final ProtectionDomain protectionDomain = filter.getClass().getProtectionDomain();
    final PermissionCollection permissionCollection = protectionDomain.getPermissions();
    assertTrue("Should have read only permissions", permissionCollection.isReadOnly());
}
 
開發者ID:SourceLabOrg,項目名稱:kafka-webview,代碼行數:33,代碼來源:PluginClassLoaderTest.java

示例2: loadJar

import java.security.ProtectionDomain; //導入方法依賴的package包/類
/**
 * Loads specified JAR.
 *
 * @param jarFileInfo
 * @throws IOException
 */
private void loadJar(JarFileInfo jarFileInfo) throws IOException {
    lstJarFile.add(jarFileInfo);
    try {
        Enumeration<JarEntry> en = jarFileInfo.jarFile.entries();
        final String EXT_JAR = ".jar";
        while (en.hasMoreElements()) {
            JarEntry je = en.nextElement();
            if (je.isDirectory()) {
                continue;
            }
            String s = je.getName().toLowerCase(); // JarEntry name
            if (s.lastIndexOf(EXT_JAR) == s.length() - EXT_JAR.length()) {
                JarEntryInfo inf = new JarEntryInfo(jarFileInfo, je);
                File fileTemp = createTempFile(inf);
                logInfo(LogArea.JAR, "Loading inner JAR %s from temp file %s",
                        inf.jarEntry, getFilename4Log(fileTemp));
                // Construct ProtectionDomain for this inner JAR:
                URL url = fileTemp.toURI().toURL();
                ProtectionDomain pdParent = jarFileInfo.pd;
                // 'csParent' is never null: top JAR has it, JCL creates it for child JAR:
                CodeSource csParent = pdParent.getCodeSource();
                Certificate[] certParent = csParent.getCertificates();
                CodeSource csChild = (certParent == null ? new CodeSource(url, csParent.getCodeSigners())
                                                         : new CodeSource(url, certParent));
                ProtectionDomain pdChild = new ProtectionDomain(csChild,
                        pdParent.getPermissions(), pdParent.getClassLoader(), pdParent.getPrincipals());
                loadJar(new JarFileInfo(
                        new JarFile(fileTemp), inf.getName(), jarFileInfo, pdChild, fileTemp));
            }
        }
    } catch (JarClassLoaderException e) {
        throw new RuntimeException(
                "ERROR on loading inner JAR: " + e.getMessageAll());
    }
}
 
開發者ID:Energyxxer,項目名稱:Vanilla-Injection,代碼行數:42,代碼來源:JarClassLoader.java


注:本文中的java.security.ProtectionDomain.getPermissions方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。