Java Code Examples for java.security.Permission#implies()

The following examples show how to use java.security.Permission#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: SecurityTestSupport.java    From groovy with Apache License 2.0 6 votes vote down vote up
protected void executeScript(Class scriptClass, Permission missingPermission) {
    try {
        Script script = InvokerHelper.createScript(scriptClass, new Binding());
        script.run();
        //InvokerHelper.runScript(scriptClass, null);
    } catch (AccessControlException ace) {
        if (missingPermission != null && missingPermission.implies(ace.getPermission())) {
            return;
        } else {
            fail(ace.toString());
        }
    }
    if (missingPermission != null) {
        fail("Should catch an AccessControlException");
    }
}
 
Example 2
Source File: DelegationPermission.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Check and see if this collection of permissions implies the permissions
 * expressed in "permission".
 *
 * @param permission the Permission object to compare
 *
 * @return true if "permission" is a proper subset of a permission in
 * the collection, false if not.
 */
public boolean implies(Permission permission) {
    if (! (permission instanceof DelegationPermission))
            return false;

    synchronized (this) {
        for (Permission x : perms) {
            if (x.implies(permission))
                return true;
        }
    }
    return false;

}
 
Example 3
Source File: JaccPermissionsBuilder.java    From tomee with Apache License 2.0 5 votes vote down vote up
/**
 * Removes permissions from <code>toBeChecked</code> that are implied by
 * <code>permission</code>.
 *
 * @param toBeChecked the permissions that are to be checked and possibly culled
 * @param permission  the permission that is to be used for culling
 * @return the culled set of permissions that are not implied by <code>permission</code>
 */
private PermissionCollection cullPermissions(final PermissionCollection toBeChecked, final Permission permission) {
    final PermissionCollection result = DelegatePermissionCollection.getPermissionCollection();

    for (final Enumeration e = toBeChecked.elements(); e.hasMoreElements(); ) {
        final Permission test = (Permission) e.nextElement();
        if (!permission.implies(test)) {
            result.add(test);
        }
    }

    return result;
}
 
Example 4
Source File: DcmdMBeanPermissionsTest.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
public final void checkPermission(final Permission perm) {
    for (Permission p : grantedPermissions) {
        if (p.implies(perm)) {
            return;
        }
    }
    throw new SecurityException(perm.toString());
}
 
Example 5
Source File: EqualsImplies.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[]args) throws Exception {

      Permission p1 = new A("foo");
      Permission p2 = new B("foo");

      if (p1.implies(p2) || p2.implies(p1) || p1.equals(p2)) {
          throw new Exception("Test failed");
      }

      // make sure permissions imply and equal themselves
      if (! (p1.implies(p1) && p1.equals(p1))) {
          throw new Exception("Test failed");
      }

    }
 
Example 6
Source File: SecurityTestSupport.java    From groovy with Apache License 2.0 5 votes vote down vote up
protected void executeTest(Class test, Permission missingPermission) {
    TestSuite suite = new TestSuite();
    suite.addTestSuite(test);
    TestResult result = new TestResult();
    suite.run(result);
    if (result.wasSuccessful()) {
        if (missingPermission == null) {
            return;
        } else {
            fail("Security test expected an AccessControlException on " + missingPermission + ", but did not receive one");
        }
    } else {
        if (missingPermission == null) {
            new SecurityTestResultPrinter(System.out).print(result);
            fail("Security test was expected to run successfully, but failed (results on System.out)");
        } else {
            //There may be more than 1 failure:  iterate to ensure that they all match the missingPermission.
            boolean otherFailure = false;
            for (Enumeration e = result.errors(); e.hasMoreElements();) {
                TestFailure failure = (TestFailure) e.nextElement();
                if (failure.thrownException() instanceof AccessControlException) {
                    AccessControlException ace = (AccessControlException) failure.thrownException();
                    if (missingPermission.implies(ace.getPermission())) {
                        continue;
                    }
                }
                otherFailure = true;
                break;
            }
            if (otherFailure) {
                new SecurityTestResultPrinter(System.out).print(result);
                fail("Security test expected an AccessControlException on " + missingPermission + ", but failed for other reasons (results on System.out)");
            }
        }
    }
}
 
Example 7
Source File: DcmdMBeanPermissionsTest.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
public final void checkPermission(final Permission perm) {
    for (Permission p : grantedPermissions) {
        if (p.implies(perm)) {
            return;
        }
    }
    throw new SecurityException(perm.toString());
}
 
Example 8
Source File: EqualsImplies.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[]args) throws Exception {

      Permission p1 = new A("foo");
      Permission p2 = new B("foo");

      if (p1.implies(p2) || p2.implies(p1) || p1.equals(p2)) {
          throw new Exception("Test failed");
      }

      // make sure permissions imply and equal themselves
      if (! (p1.implies(p1) && p1.equals(p1))) {
          throw new Exception("Test failed");
      }

    }
 
Example 9
Source File: CustomSecurityManager.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
@Override
public void checkPermission(Permission perm) {
    if (perm.implies(SecurityConstants.AWT.TOPLEVEL_WINDOW_PERMISSION)) {
        throw new SecurityException();
    }
}
 
Example 10
Source File: GetXSpace.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
public void checkPermission(Permission p, Object context) {
    if (p.implies(new RuntimePermission("getFileSystemAttributes")))
        throw new SecurityException(err);
    super.checkPermission(p, context);
}
 
Example 11
Source File: GetXSpace.java    From jdk8u-dev-jdk with GNU General Public License v2.0 4 votes vote down vote up
public void checkPermission(Permission p) {
    if (p.implies(new RuntimePermission("setSecurityManager"))
        || p.implies(new RuntimePermission("getProtectionDomain")))
      return;
    super.checkPermission(p);
}
 
Example 12
Source File: GetXSpace.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
public void checkPermission(Permission p) {
    if (p.implies(new RuntimePermission("getFileSystemAttributes")))
        throw new SecurityException(err);
    super.checkPermission(p);
}
 
Example 13
Source File: GetXSpace.java    From openjdk-8-source with GNU General Public License v2.0 4 votes vote down vote up
public void checkPermission(Permission p, Object context) {
    if (p.implies(new RuntimePermission("setSecurityManager"))
        || p.implies(new RuntimePermission("getProtectionDomain")))
      return;
    super.checkPermission(p, context);
}
 
Example 14
Source File: GetXSpace.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
public void checkPermission(Permission p, Object context) {
    if (p.implies(new RuntimePermission("setSecurityManager"))
        || p.implies(new RuntimePermission("getProtectionDomain")))
      return;
    super.checkPermission(p, context);
}
 
Example 15
Source File: GetXSpace.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
public void checkPermission(Permission p, Object context) {
    if (p.implies(new RuntimePermission("setSecurityManager"))
        || p.implies(new RuntimePermission("getProtectionDomain")))
      return;
    super.checkPermission(p, context);
}
 
Example 16
Source File: GetXSpace.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
public void checkPermission(Permission p, Object context) {
    if (p.implies(new RuntimePermission("getFileSystemAttributes")))
        throw new SecurityException(err);
    super.checkPermission(p, context);
}
 
Example 17
Source File: GetXSpace.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
public void checkPermission(Permission p) {
    if (p.implies(new RuntimePermission("getFileSystemAttributes")))
        throw new SecurityException(err);
    super.checkPermission(p);
}
 
Example 18
Source File: GetXSpace.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
public void checkPermission(Permission p) {
    if (p.implies(new RuntimePermission("setSecurityManager"))
        || p.implies(new RuntimePermission("getProtectionDomain")))
      return;
    super.checkPermission(p);
}
 
Example 19
Source File: GetXSpace.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
public void checkPermission(Permission p) {
    if (p.implies(new RuntimePermission("setSecurityManager"))
        || p.implies(new RuntimePermission("getProtectionDomain")))
      return;
    super.checkPermission(p);
}
 
Example 20
Source File: GetXSpace.java    From jdk8u_jdk with GNU General Public License v2.0 4 votes vote down vote up
public void checkPermission(Permission p) {
    if (p.implies(new RuntimePermission("getFileSystemAttributes")))
        throw new SecurityException(err);
    super.checkPermission(p);
}