Java Code Examples for java.security.PermissionCollection#implies()
The following examples show how to use
java.security.PermissionCollection#implies() .
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: HostConfig.java From Tomcat8-Source-Read with MIT License | 6 votes |
private boolean isDeployThisXML(File docBase, ContextName cn) { boolean deployThisXML = isDeployXML(); if (Globals.IS_SECURITY_ENABLED && !deployThisXML) { // When running under a SecurityManager, deployXML may be overridden // on a per Context basis by the granting of a specific permission Policy currentPolicy = Policy.getPolicy(); if (currentPolicy != null) { URL contextRootUrl; try { contextRootUrl = docBase.toURI().toURL(); CodeSource cs = new CodeSource(contextRootUrl, (Certificate[]) null); PermissionCollection pc = currentPolicy.getPermissions(cs); Permission p = new DeployXmlPermission(cn.getBaseName()); if (pc.implies(p)) { deployThisXML = true; } } catch (MalformedURLException e) { // Should never happen log.warn("hostConfig.docBaseUrlInvalid", e); } } } return deployThisXML; }
Example 2
Source File: BundleImpl.java From knopflerfish.org with BSD 3-Clause "New" or "Revised" License | 6 votes |
/** * Determine whether the bundle has the requested permission. * * @see org.osgi.framework.Bundle#hasPermission */ public boolean hasPermission(Object permission) { final BundleGeneration fix = current(); checkUninstalled(); if (permission instanceof Permission) { if (secure.checkPermissions()) { // get the current status from permission admin final PermissionCollection pc = fix.getProtectionDomain().getPermissions(); return pc != null ? pc.implies((Permission)permission) : false; } else { return true; } } else { return false; } }
Example 3
Source File: WebappClassLoaderBase.java From tomcatsrc with Apache License 2.0 | 6 votes |
@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; }
Example 4
Source File: SecurePermissionOps.java From knopflerfish.org with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Override boolean okFragmentBundlePerm(BundleImpl b) { final PermissionCollection pc = ph.getPermissionCollection(new Long(b.id)); return pc.implies(new BundlePermission(b.getSymbolicName(), BundlePermission.FRAGMENT)); }
Example 5
Source File: JarURL.java From jdk8u-jdk with GNU General Public License v2.0 | 5 votes |
public static void main(String[] args) throws Exception { String userDir = System.getProperty("user.dir"); String jarURL = "jar:file:" + userDir + File.separator + "foo.jar!/"; URL codeSourceURL = new URL(jarURL); CodeSource cs = new CodeSource(codeSourceURL, new Certificate[0]); PermissionCollection perms = Policy.getPolicy().getPermissions(cs); if (!perms.implies(new AllPermission())) throw new Exception("FAILED: " + codeSourceURL + " not granted AllPermission"); }
Example 6
Source File: SecurePermissionOps.java From knopflerfish.org with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Override boolean hasExportPackagePermission(ExportPkg ep) { final BundleImpl b = ep.bpkgs.bg.bundle; if (b.id != 0) { final PermissionCollection pc = ph .getPermissionCollection(new Long(b.id)); return pc.implies(new PackagePermission(ep.name, PackagePermission.EXPORTONLY)); } return true; }
Example 7
Source File: Activation.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 5 votes |
private static void checkPermission(PermissionCollection perms, Permission p) throws AccessControlException { if (!perms.implies(p)) { throw new AccessControlException( "access denied " + p.toString()); } }
Example 8
Source File: Activation.java From jdk8u-jdk with GNU General Public License v2.0 | 5 votes |
private static void checkPermission(PermissionCollection perms, Permission p) throws AccessControlException { if (!perms.implies(p)) { throw new AccessControlException( "access denied " + p.toString()); } }
Example 9
Source File: BasicPolicyConfiguration.java From tomee with Apache License 2.0 | 5 votes |
public boolean implies(final ProtectionDomain domain, final Permission permission) { if (excluded != null && excluded.implies(permission)) { return false; } if (unchecked != null && unchecked.implies(permission)) { return true; } final Principal[] principals = domain.getPrincipals(); if (principals.length == 0) { return false; } final RoleResolver roleResolver = SystemInstance.get().getComponent(RoleResolver.class); final Set<String> roles = roleResolver.getLogicalRoles(principals, rolePermissionsMap.keySet()); for (final String role : roles) { final PermissionCollection permissions = rolePermissionsMap.get(role); if (permissions != null && permissions.implies(permission)) { return true; } } return false; }
Example 10
Source File: PackageAdminTestSuite.java From knopflerfish.org with BSD 3-Clause "New" or "Revised" License | 5 votes |
public boolean implyCheck (Object _out, boolean expected, PermissionCollection p1, Permission p2) { boolean result = true; if (p1.implies(p2) == expected) { result = true; } else { out.println("framework test bundle, ...Permission implies method failed"); out.println("Permission p1: " + p1.toString()); out.println("Permission p2: " + p2.toString()); result = false; } return result; }
Example 11
Source File: JarURL.java From TencentKona-8 with GNU General Public License v2.0 | 5 votes |
public static void main(String[] args) throws Exception { String userDir = System.getProperty("user.dir"); String jarURL = "jar:file:" + userDir + File.separator + "foo.jar!/"; URL codeSourceURL = new URL(jarURL); CodeSource cs = new CodeSource(codeSourceURL, new Certificate[0]); PermissionCollection perms = Policy.getPolicy().getPermissions(cs); if (!perms.implies(new AllPermission())) throw new Exception("FAILED: " + codeSourceURL + " not granted AllPermission"); }
Example 12
Source File: SecurePermissionOps.java From knopflerfish.org with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Override boolean hasImportPackagePermission(BundleImpl b, ExportPkg ep) { if (b.id != 0) { final PermissionCollection pc = ph .getPermissionCollection(new Long(b.id)); return pc.implies(new PackagePermission(ep.name, ep.bpkgs.bg.bundle, PackagePermission.IMPORT)); } return true; }
Example 13
Source File: Activation.java From hottub with GNU General Public License v2.0 | 5 votes |
private static void checkPermission(PermissionCollection perms, Permission p) throws AccessControlException { if (!perms.implies(p)) { throw new AccessControlException( "access denied " + p.toString()); } }
Example 14
Source File: StatefulSecurityPermissionsTest.java From tomee with Apache License 2.0 | 5 votes |
public boolean implies(final ProtectionDomain domain, final Permission permission) { if (excluded != null && excluded.implies(permission)) { actual.set("Excluded"); return false; } if (unchecked != null && unchecked.implies(permission)) { actual.set("Unchecked"); return true; } final Principal[] principals = domain.getPrincipals(); if (principals.length == 0) return false; final RoleResolver roleResolver = SystemInstance.get().getComponent(RoleResolver.class); final Set<String> roles = roleResolver.getLogicalRoles(principals, rolePermissionsMap.keySet()); for (final String role : roles) { final PermissionCollection permissions = rolePermissionsMap.get(role); if (permissions != null && permissions.implies(permission)) { actual.set(role); return true; } } actual.set("Denied"); return false; }
Example 15
Source File: Activation.java From dragonwell8_jdk with GNU General Public License v2.0 | 5 votes |
private static void checkPermission(PermissionCollection perms, Permission p) throws AccessControlException { if (!perms.implies(p)) { throw new AccessControlException( "access denied " + p.toString()); } }
Example 16
Source File: ExitVM.java From openjdk-jdk9 with GNU General Public License v2.0 | 4 votes |
public static void main(String[]args) throws Exception { RuntimePermission newWildcard = new RuntimePermission("exitVM.*"); RuntimePermission oldWildcard = new RuntimePermission("exitVM"); RuntimePermission other = new RuntimePermission("exitVM.23"); System.out.println("Testing RuntimePermission(\"exitVM.*\")"); System.out.println(" testing getName()"); if (!newWildcard.getName().equals("exitVM.*")) { throw new Exception ("expected: exitVM.* received:" + newWildcard.getName()); } System.out.println (" testing equals(new RuntimePermission(\"exitVM.*\"))"); if (!newWildcard.equals(new RuntimePermission("exitVM.*"))) { throw new Exception("expected true, received false"); } System.out.println (" testing equals(new RuntimePermission(\"exitVM.23\"))"); if (newWildcard.equals(other)) { throw new Exception("expected false, received true"); } System.out.println (" testing implies(new RuntimePermission(\"exitVM.23\"))"); if (!newWildcard.implies(other)) { throw new Exception("expected true, received false"); } System.out.println (" testing implies(new RuntimePermission(\"exitVM.*\"))"); if (!newWildcard.implies(new RuntimePermission("exitVM.*"))) { throw new Exception("expected true, received false"); } System.out.println (" testing implies(new RuntimePermission(\"exitVM\"))"); if (!newWildcard.implies(oldWildcard)) { throw new Exception("expected true, received false"); } System.out.println("Testing RuntimePermission(\"exitVM\")"); System.out.println (" testing implies(new RuntimePermission(\"exitVM.*\"))"); if (!oldWildcard.implies(newWildcard)) { throw new Exception("expected true, received false"); } System.out.println (" testing implies(new RuntimePermission(\"exitVM\"))"); if (!oldWildcard.implies(new RuntimePermission("exitVM"))) { throw new Exception("expected true, received false"); } System.out.println (" testing implies(new RuntimePermission(\"exitVM.23\"))"); if (!oldWildcard.implies(other)) { throw new Exception("expected true, received false"); } // now test permission collections System.out.println("Testing PermissionCollection containing " + "RuntimePermission(\"exitVM.*\")"); PermissionCollection newPC = newWildcard.newPermissionCollection(); newPC.add(newWildcard); System.out.println (" testing implies(new RuntimePermission(\"exitVM.23\"))"); if (!newPC.implies(other)) { throw new Exception("expected true, received false"); } System.out.println (" testing implies(new RuntimePermission(\"exitVM.*\"))"); if (!newPC.implies(new RuntimePermission("exitVM.*"))) { throw new Exception("expected true, received false"); } System.out.println (" testing implies(new RuntimePermission(\"exitVM\"))"); if (!newPC.implies(oldWildcard)) { throw new Exception("expected true, received false"); } System.out.println("Testing PermissionCollection containing " + "RuntimePermission(\"exitVM\")"); PermissionCollection oldPC = oldWildcard.newPermissionCollection(); oldPC.add(oldWildcard); System.out.println (" testing implies(new RuntimePermission(\"exitVM.23\"))"); if (!oldPC.implies(other)) { throw new Exception("expected true, received false"); } System.out.println (" testing implies(new RuntimePermission(\"exitVM.*\"))"); if (!oldPC.implies(new RuntimePermission("exitVM.*"))) { throw new Exception("expected true, received false"); } System.out.println (" testing implies(new RuntimePermission(\"exitVM\"))"); if (!oldPC.implies(oldWildcard)) { throw new Exception("expected true, received false"); } }
Example 17
Source File: ExitVM.java From jdk8u60 with GNU General Public License v2.0 | 4 votes |
public static void main(String[]args) throws Exception { RuntimePermission newWildcard = new RuntimePermission("exitVM.*"); RuntimePermission oldWildcard = new RuntimePermission("exitVM"); RuntimePermission other = new RuntimePermission("exitVM.23"); System.out.println("Testing RuntimePermission(\"exitVM.*\")"); System.out.println(" testing getName()"); if (!newWildcard.getName().equals("exitVM.*")) { throw new Exception ("expected: exitVM.* received:" + newWildcard.getName()); } System.out.println (" testing equals(new RuntimePermission(\"exitVM.*\"))"); if (!newWildcard.equals(new RuntimePermission("exitVM.*"))) { throw new Exception("expected true, received false"); } System.out.println (" testing equals(new RuntimePermission(\"exitVM.23\"))"); if (newWildcard.equals(other)) { throw new Exception("expected false, received true"); } System.out.println (" testing implies(new RuntimePermission(\"exitVM.23\"))"); if (!newWildcard.implies(other)) { throw new Exception("expected true, received false"); } System.out.println (" testing implies(new RuntimePermission(\"exitVM.*\"))"); if (!newWildcard.implies(new RuntimePermission("exitVM.*"))) { throw new Exception("expected true, received false"); } System.out.println (" testing implies(new RuntimePermission(\"exitVM\"))"); if (!newWildcard.implies(oldWildcard)) { throw new Exception("expected true, received false"); } System.out.println("Testing RuntimePermission(\"exitVM\")"); System.out.println (" testing implies(new RuntimePermission(\"exitVM.*\"))"); if (!oldWildcard.implies(newWildcard)) { throw new Exception("expected true, received false"); } System.out.println (" testing implies(new RuntimePermission(\"exitVM\"))"); if (!oldWildcard.implies(new RuntimePermission("exitVM"))) { throw new Exception("expected true, received false"); } System.out.println (" testing implies(new RuntimePermission(\"exitVM.23\"))"); if (!oldWildcard.implies(other)) { throw new Exception("expected true, received false"); } // now test permission collections System.out.println("Testing PermissionCollection containing " + "RuntimePermission(\"exitVM.*\")"); PermissionCollection newPC = newWildcard.newPermissionCollection(); newPC.add(newWildcard); System.out.println (" testing implies(new RuntimePermission(\"exitVM.23\"))"); if (!newPC.implies(other)) { throw new Exception("expected true, received false"); } System.out.println (" testing implies(new RuntimePermission(\"exitVM.*\"))"); if (!newPC.implies(new RuntimePermission("exitVM.*"))) { throw new Exception("expected true, received false"); } System.out.println (" testing implies(new RuntimePermission(\"exitVM\"))"); if (!newPC.implies(oldWildcard)) { throw new Exception("expected true, received false"); } System.out.println("Testing PermissionCollection containing " + "RuntimePermission(\"exitVM\")"); PermissionCollection oldPC = oldWildcard.newPermissionCollection(); oldPC.add(oldWildcard); System.out.println (" testing implies(new RuntimePermission(\"exitVM.23\"))"); if (!oldPC.implies(other)) { throw new Exception("expected true, received false"); } System.out.println (" testing implies(new RuntimePermission(\"exitVM.*\"))"); if (!oldPC.implies(new RuntimePermission("exitVM.*"))) { throw new Exception("expected true, received false"); } System.out.println (" testing implies(new RuntimePermission(\"exitVM\"))"); if (!oldPC.implies(oldWildcard)) { throw new Exception("expected true, received false"); } }
Example 18
Source File: ExitVM.java From jdk8u_jdk with GNU General Public License v2.0 | 4 votes |
public static void main(String[]args) throws Exception { RuntimePermission newWildcard = new RuntimePermission("exitVM.*"); RuntimePermission oldWildcard = new RuntimePermission("exitVM"); RuntimePermission other = new RuntimePermission("exitVM.23"); System.out.println("Testing RuntimePermission(\"exitVM.*\")"); System.out.println(" testing getName()"); if (!newWildcard.getName().equals("exitVM.*")) { throw new Exception ("expected: exitVM.* received:" + newWildcard.getName()); } System.out.println (" testing equals(new RuntimePermission(\"exitVM.*\"))"); if (!newWildcard.equals(new RuntimePermission("exitVM.*"))) { throw new Exception("expected true, received false"); } System.out.println (" testing equals(new RuntimePermission(\"exitVM.23\"))"); if (newWildcard.equals(other)) { throw new Exception("expected false, received true"); } System.out.println (" testing implies(new RuntimePermission(\"exitVM.23\"))"); if (!newWildcard.implies(other)) { throw new Exception("expected true, received false"); } System.out.println (" testing implies(new RuntimePermission(\"exitVM.*\"))"); if (!newWildcard.implies(new RuntimePermission("exitVM.*"))) { throw new Exception("expected true, received false"); } System.out.println (" testing implies(new RuntimePermission(\"exitVM\"))"); if (!newWildcard.implies(oldWildcard)) { throw new Exception("expected true, received false"); } System.out.println("Testing RuntimePermission(\"exitVM\")"); System.out.println (" testing implies(new RuntimePermission(\"exitVM.*\"))"); if (!oldWildcard.implies(newWildcard)) { throw new Exception("expected true, received false"); } System.out.println (" testing implies(new RuntimePermission(\"exitVM\"))"); if (!oldWildcard.implies(new RuntimePermission("exitVM"))) { throw new Exception("expected true, received false"); } System.out.println (" testing implies(new RuntimePermission(\"exitVM.23\"))"); if (!oldWildcard.implies(other)) { throw new Exception("expected true, received false"); } // now test permission collections System.out.println("Testing PermissionCollection containing " + "RuntimePermission(\"exitVM.*\")"); PermissionCollection newPC = newWildcard.newPermissionCollection(); newPC.add(newWildcard); System.out.println (" testing implies(new RuntimePermission(\"exitVM.23\"))"); if (!newPC.implies(other)) { throw new Exception("expected true, received false"); } System.out.println (" testing implies(new RuntimePermission(\"exitVM.*\"))"); if (!newPC.implies(new RuntimePermission("exitVM.*"))) { throw new Exception("expected true, received false"); } System.out.println (" testing implies(new RuntimePermission(\"exitVM\"))"); if (!newPC.implies(oldWildcard)) { throw new Exception("expected true, received false"); } System.out.println("Testing PermissionCollection containing " + "RuntimePermission(\"exitVM\")"); PermissionCollection oldPC = oldWildcard.newPermissionCollection(); oldPC.add(oldWildcard); System.out.println (" testing implies(new RuntimePermission(\"exitVM.23\"))"); if (!oldPC.implies(other)) { throw new Exception("expected true, received false"); } System.out.println (" testing implies(new RuntimePermission(\"exitVM.*\"))"); if (!oldPC.implies(new RuntimePermission("exitVM.*"))) { throw new Exception("expected true, received false"); } System.out.println (" testing implies(new RuntimePermission(\"exitVM\"))"); if (!oldPC.implies(oldWildcard)) { throw new Exception("expected true, received false"); } }
Example 19
Source File: DelegationPermissionCollection.java From openjdk-jdk9 with GNU General Public License v2.0 | 4 votes |
public static void main(String[] args) throws Exception { int testFail = 0; DelegationPermission perm = new DelegationPermission(FOO + " " + TGT); PermissionCollection perms = perm.newPermissionCollection(); // test 1 System.out.println ("test 1: add throws IllegalArgException for wrong perm type"); try { perms.add(new SecurityPermission("createAccessControlContext")); System.err.println("Expected IllegalArgumentException"); testFail++; } catch (IllegalArgumentException iae) {} // test 2 System.out.println("test 2: implies returns false for wrong perm type"); if (perms.implies(new SecurityPermission("getPolicy"))) { System.err.println("Expected false, returned true"); testFail++; } // test 3 System.out.println("test 3: implies returns true for match on name"); perms.add(new DelegationPermission(FOO + " " + TGT)); if (!perms.implies(new DelegationPermission(FOO + " " + TGT))) { System.err.println("Expected true, returned false"); testFail++; } // test 4 System.out.println ("test 4: implies returns false for non-match on name"); if (perms.implies(new DelegationPermission(BAR + " " + TGT))) { System.err.println("Expected false, returned true"); testFail++; } // test 5 System.out.println("test 5: elements returns correct number of perms"); int numPerms = 0; Enumeration<Permission> e = perms.elements(); while (e.hasMoreElements()) { numPerms++; System.out.println(e.nextElement()); } if (numPerms != 1) { System.err.println("Expected 1, got " + numPerms); testFail++; } if (testFail > 0) { throw new Exception(testFail + " test(s) failed"); } }
Example 20
Source File: BasicPermissionCollection.java From openjdk-jdk9 with GNU General Public License v2.0 | 4 votes |
public static void main(String[] args) throws Exception { int testFail = 0; TestPermission perm = new TestPermission("foo"); PermissionCollection perms = perm.newPermissionCollection(); // test 1 System.out.println("test 1: add throws IllegalArgumentExc"); try { perms.add(new SecurityPermission("createAccessControlContext")); System.err.println("Expected IllegalArgumentException"); testFail++; } catch (IllegalArgumentException iae) {} // test 2 System.out.println("test 2: implies returns false for wrong class"); if (perms.implies(new SecurityPermission("getPolicy"))) { System.err.println("Expected false, returned true"); testFail++; } // test 3 System.out.println("test 3: implies returns true for match on name"); perms.add(new TestPermission("foo")); if (!perms.implies(new TestPermission("foo"))) { System.err.println("Expected true, returned false"); testFail++; } // test 4 System.out.println("test 4: implies returns true for wildcard match"); perms.add(new TestPermission("bar.*")); if (!perms.implies(new TestPermission("bar.foo"))) { System.err.println("Expected true, returned false"); testFail++; } // test 5 System.out.println ("test 5: implies returns false for invalid wildcard"); perms.add(new TestPermission("baz*")); if (perms.implies(new TestPermission("baz.foo"))) { System.err.println("Expected false, returned true"); testFail++; } // test 6 System.out.println ("test 6: implies returns true for deep wildcard match"); if (!perms.implies(new TestPermission("bar.foo.baz"))) { System.err.println("Expected true, returned false"); testFail++; } // test 7 System.out.println ("test 7: implies returns true for all wildcard match"); perms.add(new TestPermission("*")); if (!perms.implies(new TestPermission("yes"))) { System.err.println("Expected true, returned false"); testFail++; } // test 8 System.out.println("test 8: elements returns correct number of perms"); int numPerms = 0; Enumeration<Permission> e = perms.elements(); while (e.hasMoreElements()) { numPerms++; System.out.println(e.nextElement()); } if (numPerms != 4) { System.err.println("Expected 4, got " + numPerms); testFail++; } if (testFail > 0) { throw new Exception(testFail + " test(s) failed"); } }