本文整理匯總了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 )
)
);
}
}
示例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;
}
示例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);
}
示例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;
}
示例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;
}
示例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();
}
示例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
}
}
示例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);
}
}
示例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
}
}
示例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);
}
}
示例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");
}
}
示例12: DriverManagerPermissionsTests
import java.security.Policy; //導入方法依賴的package包/類
public DriverManagerPermissionsTests() {
policy = Policy.getPolicy();
sm = System.getSecurityManager();
}
示例13: SyncFactoryPermissionsTests
import java.security.Policy; //導入方法依賴的package包/類
public SyncFactoryPermissionsTests() {
policy = Policy.getPolicy();
sm = System.getSecurityManager();
ctx = new StubContext();
}
示例14: PermissionTest
import java.security.Policy; //導入方法依賴的package包/類
PermissionTest() {
policy = Policy.getPolicy();
sm = System.getSecurityManager();
currentHndl = ProcessHandle.current();
}
示例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!");
}
}