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


Java Policy.getPolicy方法代碼示例

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


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

示例1: doPermissionCheckInContext

import java.security.Policy; //導入方法依賴的package包/類
private void doPermissionCheckInContext(PermissionCheckEntityInformation entityInformation, PermissibleAction action) {
	final Policy policy = Policy.getPolicy();
	final Principal[] principals = getCallerPrincipals();

	final CodeSource codeSource = entityInformation.getEntity().getClass().getProtectionDomain().getCodeSource();
	final ProtectionDomain pd = new ProtectionDomain( codeSource, null, null, principals );

	// the action is known as 'method name' in JACC
	final EJBMethodPermission jaccPermission = new EJBMethodPermission(
			entityInformation.getEntityName(),
			action.getImpliedActions()[0],
			null,
			null
	);

	if ( ! policy.implies( pd, jaccPermission) ) {
		throw new SecurityException(
				String.format(
						"JACC denied permission to [%s.%s] for [%s]",
						entityInformation.getEntityName(),
						action.getImpliedActions()[0],
						join( principals )
				)
		);
	}
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:27,代碼來源:StandardJaccServiceImpl.java

示例2: check

import java.security.Policy; //導入方法依賴的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

示例3: main

import java.security.Policy; //導入方法依賴的package包/類
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);
    }
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:23,代碼來源:DefaultPolicy.java

示例4: check

import java.security.Policy; //導入方法依賴的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:how2j,項目名稱:lazycat,代碼行數:19,代碼來源:WebappClassLoaderBase.java

示例5: ESPolicy

import java.security.Policy; //導入方法依賴的package包/類
ESPolicy(PermissionCollection dynamic, Map<String,Policy> plugins, boolean filterBadDefaults) {
    this.template = Security.readPolicy(getClass().getResource(POLICY_RESOURCE), JarHell.parseClassPath());
    this.untrusted = Security.readPolicy(getClass().getResource(UNTRUSTED_RESOURCE), new URL[0]);
    if (filterBadDefaults) {
        this.system = new SystemPolicy(Policy.getPolicy());
    } else {
        this.system = Policy.getPolicy();
    }
    this.dynamic = dynamic;
    this.plugins = plugins;
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:12,代碼來源:ESPolicy.java

示例6: setUp

import java.security.Policy; //導入方法依賴的package包/類
protected void setUp() {
    if (System.getSecurityManager() != null) {
        hasSM = true;
        System.setSecurityManager(null);
    }

    filePath = System.getProperty("test.src");
    if (filePath == null) {
        //current directory
        filePath = System.getProperty("user.dir");
    }
    origPolicy = Policy.getPolicy();

}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:15,代碼來源:TestBase.java

示例7: refreshPolicy

import java.security.Policy; //導入方法依賴的package包/類
/**
 * 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
	}

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

示例8: main

import java.security.Policy; //導入方法依賴的package包/類
public static void main(String[] args) throws IOException {

        testLoadAndStore("UTF-8", false);
        testLoadAndStore("UTF-16", false);
        testLoadAndStore("UTF-16BE", false);
        testLoadAndStore("UTF-16LE", false);
        testLoadAndStore("UTF-16BE", true);
        testLoadAndStore("UTF-16LE", true);
        testLoadWithoutEncoding();
        testLoadWithBadEncoding();
        testStoreWithBadEncoding();

        // malformed documents
        String src = System.getProperty("test.src");
        String subdir = "invalidxml";
        Path dir = (src == null) ? Paths.get(subdir) : Paths.get(src, subdir);
        testLoadWithMalformedDoc(dir);

        // re-run sanity test with security manager
        Policy orig = Policy.getPolicy();
        Policy p = new SimplePolicy(new RuntimePermission("setSecurityManager"),
                                    new PropertyPermission("line.separator", "read"));
        Policy.setPolicy(p);
        System.setSecurityManager(new SecurityManager());
        try {
            testLoadAndStore("UTF-8", false);
        } finally {
            // turn off security manager and restore policy
            System.setSecurityManager(null);
            Policy.setPolicy(orig);
        }

    }
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:34,代碼來源:LoadAndStoreXML.java

示例9: refreshPolicy

import java.security.Policy; //導入方法依賴的package包/類
/**
 * 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
    }

}
 
開發者ID:sunmingshuai,項目名稱:apache-tomcat-7.0.73-with-comment,代碼行數:18,代碼來源:WebappClassLoaderBase.java

示例10: test

import java.security.Policy; //導入方法依賴的package包/類
void test(String[] args) throws Throwable {
    // Test without a security manager
    test1();

    // Test with a security manager
    Policy defaultPolicy = Policy.getPolicy();
    Policy.setPolicy(new MyPolicy(defaultPolicy));
    System.setSecurityManager(new SecurityManager());
    try {
        test1();
    } finally {
        System.setSecurityManager(null);
        Policy.setPolicy(defaultPolicy);
    }
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:16,代碼來源:ParameterAnnotations.java

示例11: main

import java.security.Policy; //導入方法依賴的package包/類
public static void main(String[] args) throws Exception {
    Policy policy = Policy.getPolicy();
    PermissionCollection perms = policy.getPermissions((CodeSource)null);
    if (perms.elements().hasMoreElements()) {
        System.err.println(perms);
        throw new Exception("PermissionCollection is not empty");
    }
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:9,代碼來源:NullCodeSource.java

示例12: DriverManagerPermissionsTests

import java.security.Policy; //導入方法依賴的package包/類
public DriverManagerPermissionsTests() {
    policy = Policy.getPolicy();
    sm = System.getSecurityManager();
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:5,代碼來源:DriverManagerPermissionsTests.java

示例13: SyncFactoryPermissionsTests

import java.security.Policy; //導入方法依賴的package包/類
public SyncFactoryPermissionsTests() {
    policy = Policy.getPolicy();
    sm = System.getSecurityManager();
    ctx = new StubContext();
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:6,代碼來源:SyncFactoryPermissionsTests.java

示例14: PermissionTest

import java.security.Policy; //導入方法依賴的package包/類
PermissionTest() {
    policy = Policy.getPolicy();
    sm = System.getSecurityManager();
    currentHndl = ProcessHandle.current();
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:6,代碼來源:PermissionTest.java

示例15: doit

import java.security.Policy; //導入方法依賴的package包/類
private void doit() throws Exception {
    // A security manager must be installed
    SecurityManager sm=System.getSecurityManager();
    if (sm==null)
        throw new
            Exception("Test must be run with a security manager installed");

    // Instantiate and set the new policy
    DynamicPolicy dp = new DynamicPolicy();
    Policy.setPolicy(dp);

    // Verify that policy has been set
    if (dp != Policy.getPolicy())
        throw new Exception("Policy was not set!!");

    // now see this class can access user.name
    String usr = getUserName();

    if (usr != null) {
        System.out.println("Test was able to read user.name prior to refresh!");
        throw new
            Exception("Test was able to read user.name prior to refresh!");
    }

    // Now, make policy allow reading user.name
    dp.refresh();

    // now I should be able to read it
    usr = getUserName();

    if (usr == null) {
        System.out.println("Test was unable to read user.name after refresh!");
        throw new
            Exception("Test was unable to read user.name after refresh!");
    }
    // Now, take away permission to read user.name
    dp.refresh();

    // now I should not be able to read it
    usr = getUserName();

    if (usr != null) {
        System.out.println("Test was able to read user.name following 2nd refresh!");
        throw new
            Exception("Test was able to read user.name following 2nd refresh!");
    }

}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:49,代碼來源:TestDynamicPolicy.java


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