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


Java PermissionCollection類代碼示例

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


PermissionCollection類屬於java.security包,在下文中一共展示了PermissionCollection類的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);

}
 
開發者ID:how2j,項目名稱:lazycat,代碼行數:30,代碼來源:WebappClassLoaderBase.java

示例2: assertExactPermissions

import java.security.PermissionCollection; //導入依賴的package包/類
/**
 * checks exact file permissions, meaning those and only those for that path.
 */
static void assertExactPermissions(FilePermission expected, PermissionCollection actual) {
    String target = expected.getName(); // see javadocs
    Set<String> permissionSet = asSet(expected.getActions().split(","));
    boolean read = permissionSet.remove("read");
    boolean readlink = permissionSet.remove("readlink");
    boolean write = permissionSet.remove("write");
    boolean delete = permissionSet.remove("delete");
    boolean execute = permissionSet.remove("execute");
    assertTrue("unrecognized permission: " + permissionSet, permissionSet.isEmpty());
    assertEquals(read, actual.implies(new FilePermission(target, "read")));
    assertEquals(readlink, actual.implies(new FilePermission(target, "readlink")));
    assertEquals(write, actual.implies(new FilePermission(target, "write")));
    assertEquals(delete, actual.implies(new FilePermission(target, "delete")));
    assertEquals(execute, actual.implies(new FilePermission(target, "execute")));
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:19,代碼來源:EvilSecurityTests.java

示例3: 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);

}
 
開發者ID:liaokailin,項目名稱:tomcat7,代碼行數:30,代碼來源:WebappClassLoaderBase.java

示例4: getExecPermissions

import java.security.PermissionCollection; //導入依賴的package包/類
private static PermissionCollection getExecPermissions() {
    /*
     * The approach used here is taken from the similar method
     * getLoaderAccessControlContext() in the class
     * sun.rmi.server.LoaderHandler.
     */

    // obtain permissions granted to all code in current policy
    PermissionCollection perms = AccessController.doPrivileged(
        new PrivilegedAction<PermissionCollection>() {
            public PermissionCollection run() {
                CodeSource codesource =
                    new CodeSource(null, (Certificate[]) null);
                Policy p = Policy.getPolicy();
                if (p != null) {
                    return p.getPermissions(codesource);
                } else {
                    return new Permissions();
                }
            }
        });

    return perms;
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:25,代碼來源:Activation.java

示例5: getPermissions

import java.security.PermissionCollection; //導入依賴的package包/類
/**
 * Get the Permissions for a CodeSource.  If this instance
 * of StandardClassLoader is for a web application context,
 * add read FilePermissions 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 final PermissionCollection getPermissions(CodeSource codeSource) {
    if (!policy_refresh) {
        // Refresh the security policies
        Policy policy = Policy.getPolicy();
        policy.refresh();
        policy_refresh = true;
    }
    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);

}
 
開發者ID:c-rainstorm,項目名稱:jerrydog,代碼行數:33,代碼來源:StandardClassLoader.java

示例6: 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);

    }
 
開發者ID:c-rainstorm,項目名稱:jerrydog,代碼行數:29,代碼來源:WebappClassLoader.java

示例7: 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;
}
 
開發者ID:sunmingshuai,項目名稱:apache-tomcat-7.0.73-with-comment,代碼行數:20,代碼來源:WebappClassLoaderBase.java

示例8: checkConfiguration

import java.security.PermissionCollection; //導入依賴的package包/類
/**
 * Prints warning message if installed Policy is the default Policy
 * implementation and globally granted permissions do not include
 * AllPermission or any ExecPermissions/ExecOptionPermissions.
 */
static void checkConfiguration() {
    Policy policy =
        AccessController.doPrivileged(new PrivilegedAction<Policy>() {
            public Policy run() {
                return Policy.getPolicy();
            }
        });
    if (!(policy instanceof PolicyFile)) {
        return;
    }
    PermissionCollection perms = getExecPermissions();
    for (Enumeration<Permission> e = perms.elements();
         e.hasMoreElements();)
    {
        Permission p = e.nextElement();
        if (p instanceof AllPermission ||
            p instanceof ExecPermission ||
            p instanceof ExecOptionPermission)
        {
            return;
        }
    }
    System.err.println(getTextResource("rmid.exec.perms.inadequate"));
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:30,代碼來源:Activation.java

示例9: 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;
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:9,代碼來源:HandlersOnComplexUpdate.java

示例10: permissions

import java.security.PermissionCollection; //導入依賴的package包/類
public PermissionCollection permissions() {
    PermissionsBuilder builder = new PermissionsBuilder();
    if (allowAll.get().get()) {
        builder.addAll(all);
    } else {
        builder.addAll(basic);
        if (allowControl.get().get()) {
            builder.addAll(control);
        }
    }
    return builder.toPermissions();
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:13,代碼來源:SimpleUpdateConfigurationTest.java

示例11: getPermissions

import java.security.PermissionCollection; //導入依賴的package包/類
protected PermissionCollection getPermissions(CodeSource codesource) {
    Permissions permissions = new Permissions();
    permissions.add(new AllPermission());
    permissions.setReadOnly();
    
    return permissions;
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:8,代碼來源:DriverClassLoader.java

示例12: getPermissions

import java.security.PermissionCollection; //導入依賴的package包/類
@Override
protected PermissionCollection getPermissions(CodeSource codeSource) {
    Permissions perms = new Permissions();
    perms.add(new AllPermission());
    perms.setReadOnly();
    return perms;
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:8,代碼來源:CustomClassLoader.java

示例13: testNullLocation

import java.security.PermissionCollection; //導入依賴的package包/類
/**
 * test with null location
 * <p>
 * its unclear when/if this happens, see https://bugs.openjdk.java.net/browse/JDK-8129972
 */
public void testNullLocation() throws Exception {
    assumeTrue("test cannot run with security manager", System.getSecurityManager() == null);
    PermissionCollection noPermissions = new Permissions();
    ESPolicy policy = new ESPolicy(noPermissions, Collections.emptyMap(), true);
    assertFalse(policy.implies(new ProtectionDomain(new CodeSource(null, (Certificate[]) null), noPermissions),
            new FilePermission("foo", "read")));
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:13,代碼來源:ESPolicyUnitTests.java

示例14: getPermissions

import java.security.PermissionCollection; //導入依賴的package包/類
@Override
public PermissionCollection getPermissions(CodeSource codesource) {
    // code should not rely on this method, or at least use it correctly:
    // https://bugs.openjdk.java.net/browse/JDK-8014008
    // return them a new empty permissions object so jvisualvm etc work
    for (StackTraceElement element : Thread.currentThread().getStackTrace()) {
        if ("sun.rmi.server.LoaderHandler".equals(element.getClassName()) &&
                "loadClass".equals(element.getMethodName())) {
            return new Permissions();
        }
    }
    // return UNSUPPORTED_EMPTY_COLLECTION since it is safe.
    return super.getPermissions(codesource);
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:15,代碼來源:ESPolicy.java

示例15: 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 });
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:44,代碼來源:RegistryImpl.java


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