Java Code Examples for java.security.Policy#getPolicy()
The following examples show how to use
java.security.Policy#getPolicy() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TestBase.java From openjdk-8 with GNU General Public License v2.0 | 5 votes |
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(); }
Example 2
Source File: TestBase.java From hottub with GNU General Public License v2.0 | 5 votes |
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(); }
Example 3
Source File: TestBase.java From openjdk-jdk8u with GNU General Public License v2.0 | 5 votes |
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(); }
Example 4
Source File: TestBase.java From TencentKona-8 with GNU General Public License v2.0 | 5 votes |
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(); }
Example 5
Source File: TestBase.java From openjdk-8-source with GNU General Public License v2.0 | 5 votes |
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(); }
Example 6
Source File: NullCodeSource.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
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"); } }
Example 7
Source File: ParameterAnnotations.java From hottub with GNU General Public License v2.0 | 5 votes |
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); } }
Example 8
Source File: TestBase.java From dragonwell8_jdk with GNU General Public License v2.0 | 5 votes |
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(); }
Example 9
Source File: TestBase.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 5 votes |
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(); }
Example 10
Source File: NullCodeSource.java From dragonwell8_jdk with GNU General Public License v2.0 | 5 votes |
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"); } }
Example 11
Source File: Plugin.java From rapidminer-studio with GNU Affero General Public License v3.0 | 5 votes |
/** * Returns whether this extension is signed or not. * This will return {@code false} if there is no init class defined or can not be loaded, there is no certificate present * or the certificate is not sufficient. * * @return {@code true} if the extension is properly signed, {@code false} otherwise * @since 9.0.0 */ public boolean isSigned() { if (pluginInitClassName == null) { return false; } try { Policy policy = Policy.getPolicy(); if (!(policy instanceof PluginSandboxPolicy)) { return false; } Class<?> initClass = Class.forName(pluginInitClassName, false, classLoader); ProtectionDomain protectionDomain = initClass.getProtectionDomain(); Certificate[] certificates = protectionDomain.getCodeSource().getCertificates(); if (certificates == null || certificates.length == 0) { return false; } Enumeration<Permission> elements = policy.getPermissions(protectionDomain).elements(); while (elements.hasMoreElements()) { if (elements.nextElement() instanceof AllPermission) { return true; } } } catch (ClassNotFoundException | SecurityException e) { return false; } return false; }
Example 12
Source File: ParameterAnnotations.java From dragonwell8_jdk with GNU General Public License v2.0 | 5 votes |
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); } }
Example 13
Source File: TestBase.java From jdk8u-dev-jdk with GNU General Public License v2.0 | 5 votes |
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(); }
Example 14
Source File: SecurityActions.java From pro-grade with Apache License 2.0 | 5 votes |
/** * Returns the installed policy object. * * @return */ static Policy getPolicy() { final SecurityManager sm = System.getSecurityManager(); if (sm != null) { return AccessController.doPrivileged(new PrivilegedAction<Policy>() { public Policy run() { return Policy.getPolicy(); } }); } else { return Policy.getPolicy(); } }
Example 15
Source File: TestBase.java From hottub with GNU General Public License v2.0 | 5 votes |
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(); }
Example 16
Source File: TestDynamicPolicy.java From hottub with GNU General Public License v2.0 | 4 votes |
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!"); } }
Example 17
Source File: TestDynamicPolicy.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 4 votes |
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!"); } }
Example 18
Source File: TestDynamicPolicy.java From TencentKona-8 with GNU General Public License v2.0 | 4 votes |
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!"); } }
Example 19
Source File: SyncFactoryPermissionsTests.java From hottub with GNU General Public License v2.0 | 4 votes |
public SyncFactoryPermissionsTests() { policy = Policy.getPolicy(); sm = System.getSecurityManager(); ctx = new StubContext(); }
Example 20
Source File: SyncFactoryPermissionsTests.java From openjdk-jdk8u with GNU General Public License v2.0 | 4 votes |
public SyncFactoryPermissionsTests() { policy = Policy.getPolicy(); sm = System.getSecurityManager(); ctx = new StubContext(); }