java.security.Policy#refresh ( )源码实例Demo

下面列出了java.security.Policy#refresh ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: openjdk-jdk9   文件: DefaultPolicy.java
public static void main(String[] args) throws Exception {

        // Check policy with no java.security.policy property set
        Policy p = Policy.getPolicy();
        checkPolicy(p);

        // Check policy with java.security.policy '=' option
        System.setProperty("java.security.policy", "Extra.policy");
        p.refresh();
        checkPolicy(p);

        // Check policy with java.security.policy override '==' option
        System.setProperty("java.security.policy", "=Extra.policy");
        p.refresh();
        checkPolicy(p);

        // Check Policy.getInstance
        URI policyURI = Paths.get(System.getProperty("test.src"),
                                  "Extra.policy").toUri();
        p = Policy.getInstance("JavaPolicy", new URIParameter(policyURI));
        checkPolicy(p);
    }
 
/**
 * Refresh the system policy file, to pick up eventual changes.
 */
protected void refreshPolicy() {

    try {
        // The policy file may have been modified to adjust
        // permissions, so we're reloading it when loading or
        // reloading a Context
        Policy policy = Policy.getPolicy();
        policy.refresh();
    } catch (AccessControlException e) {
        // Some policy files may restrict this, even for the core,
        // so this exception is ignored
    }

}
 
public CallbacksSecurityTests() {
	// setup security
	if (System.getSecurityManager() == null) {
		Policy policy = Policy.getPolicy();
		URL policyURL = getClass()
				.getResource(
						"/org/springframework/beans/factory/support/security/policy.all");
		System.setProperty("java.security.policy", policyURL.toString());
		System.setProperty("policy.allowSystemProperty", "true");
		policy.refresh();

		System.setSecurityManager(new SecurityManager());
	}
}
 
public CallbacksSecurityTests() {
	// setup security
	if (System.getSecurityManager() == null) {
		Policy policy = Policy.getPolicy();
		URL policyURL = getClass()
				.getResource(
						"/org/springframework/beans/factory/support/security/policy.all");
		System.setProperty("java.security.policy", policyURL.toString());
		System.setProperty("policy.allowSystemProperty", "true");
		policy.refresh();

		System.setSecurityManager(new SecurityManager());
	}
}
 
源代码5 项目: Tomcat7.0.67   文件: WebappClassLoaderBase.java
/**
 * Refresh the system policy file, to pick up eventual changes.
 */
protected void refreshPolicy() {

    try {
        // The policy file may have been modified to adjust
        // permissions, so we're reloading it when loading or
        // reloading a Context
        Policy policy = Policy.getPolicy();
        policy.refresh();
    } catch (AccessControlException e) {
        // Some policy files may restrict this, even for the core,
        // so this exception is ignored
    }

}
 
public CallbacksSecurityTests() {
	// setup security
	if (System.getSecurityManager() == null) {
		Policy policy = Policy.getPolicy();
		URL policyURL = getClass()
				.getResource(
						"/org/springframework/beans/factory/support/security/policy.all");
		System.setProperty("java.security.policy", policyURL.toString());
		System.setProperty("policy.allowSystemProperty", "true");
		policy.refresh();

		System.setSecurityManager(new SecurityManager());
	}
}
 
源代码7 项目: tomcatsrc   文件: WebappClassLoaderBase.java
/**
 * Refresh the system policy file, to pick up eventual changes.
 */
protected void refreshPolicy() {

    try {
        // The policy file may have been modified to adjust
        // permissions, so we're reloading it when loading or
        // reloading a Context
        Policy policy = Policy.getPolicy();
        policy.refresh();
    } catch (AccessControlException e) {
        // Some policy files may restrict this, even for the core,
        // so this exception is ignored
    }

}
 
源代码8 项目: tomee   文件: AbstractSecurityService.java
private static void installPolicy(String policyProvider) {
    try {
        final ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
        final Class policyClass = Class.forName(policyProvider, true, classLoader);
        final Policy policy = (Policy) policyClass.newInstance();
        policy.refresh();
        Policy.setPolicy(policy);
    } catch (final Exception e) {
        throw new IllegalStateException("Could not install JACC Policy Provider: " + policyProvider, e);
    }
}