Java Code Examples for java.security.PermissionCollection#elements()

The following examples show how to use java.security.PermissionCollection#elements() . 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: Activation.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Prints warning message if installed Policy is the default Policy
 * implementation and globally granted permissions do not include
 * AllPermission or any ExecPermissions/ExecOptionPermissions.
 */
static void checkConfiguration() {
    Policy policy =
        AccessController.doPrivileged(new PrivilegedAction<Policy>() {
            public Policy run() {
                return Policy.getPolicy();
            }
        });
    if (!(policy instanceof PolicyFile)) {
        return;
    }
    PermissionCollection perms = getExecPermissions();
    for (Enumeration<Permission> e = perms.elements();
         e.hasMoreElements();)
    {
        Permission p = e.nextElement();
        if (p instanceof AllPermission ||
            p instanceof ExecPermission ||
            p instanceof ExecOptionPermission)
        {
            return;
        }
    }
    System.err.println(getTextResource("rmid.exec.perms.inadequate"));
}
 
Example 2
Source File: Activation.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Prints warning message if installed Policy is the default Policy
 * implementation and globally granted permissions do not include
 * AllPermission or any ExecPermissions/ExecOptionPermissions.
 */
static void checkConfiguration() {
    Policy policy =
        AccessController.doPrivileged(new PrivilegedAction<Policy>() {
            public Policy run() {
                return Policy.getPolicy();
            }
        });
    if (!(policy instanceof PolicyFile)) {
        return;
    }
    PermissionCollection perms = getExecPermissions();
    for (Enumeration<Permission> e = perms.elements();
         e.hasMoreElements();)
    {
        Permission p = e.nextElement();
        if (p instanceof AllPermission ||
            p instanceof ExecPermission ||
            p instanceof ExecOptionPermission)
        {
            return;
        }
    }
    System.err.println(getTextResource("rmid.exec.perms.inadequate"));
}
 
Example 3
Source File: DefaultLoggerTest.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
public PermissionsBuilder addAll(PermissionCollection col) {
    if (col != null) {
        for (Enumeration<Permission> e = col.elements(); e.hasMoreElements(); ) {
            perms.add(e.nextElement());
        }
    }
    return this;
}
 
Example 4
Source File: BasicPolicyConfiguration.java    From tomee with Apache License 2.0 5 votes vote down vote up
public void addToExcludedPolicy(final PermissionCollection permissions) throws PolicyContextException {
    if (state != OPEN) {
        throw new UnsupportedOperationException("Not in an open state");
    }

    final Enumeration e = permissions.elements();
    while (e.hasMoreElements()) {
        addToExcludedPolicy((Permission) e.nextElement());
    }
}
 
Example 5
Source File: ManagementPermissionAuthorizer.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
private AuthorizationResult authorize(PermissionCollection userPermissions, PermissionCollection requiredPermissions) {

        final Enumeration<Permission> enumeration = requiredPermissions.elements();
        while (enumeration.hasMoreElements()){
            Permission requiredPermission = enumeration.nextElement();
            if (!userPermissions.implies(requiredPermission)) {
                return new AuthorizationResult(AuthorizationResult.Decision.DENY,
                            new ModelNode(ControllerLogger.ROOT_LOGGER.permissionDenied()));
            }
        }
        return AuthorizationResult.PERMITTED;
    }
 
Example 6
Source File: ContextPolicy.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
void addToExcludedPolicy(PermissionCollection permissions)
   throws PolicyContextException
{
   Enumeration<Permission> iter = permissions.elements();
   while( iter.hasMoreElements() )
   {
      Permission p = iter.nextElement();
      excludedPermissions.add(p);
   }
}
 
Example 7
Source File: ContextPolicy.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
void addToUncheckedPolicy(PermissionCollection permissions)
   throws PolicyContextException
{
   Enumeration<Permission> iter = permissions.elements();
   while( iter.hasMoreElements() )
   {
      Permission p = iter.nextElement();
      uncheckedPermissions.add(p);
   }
}
 
Example 8
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 9
Source File: ClassDeclaredFieldsTest.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
public PermissionsBuilder addAll(PermissionCollection col) {
    if (col != null) {
        for (Enumeration<Permission> e = col.elements(); e.hasMoreElements(); ) {
            perms.add(e.nextElement());
        }
    }
    return this;
}
 
Example 10
Source File: ClassDeclaredFieldsTest.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
public PermissionsBuilder addAll(PermissionCollection col) {
    if (col != null) {
        for (Enumeration<Permission> e = col.elements(); e.hasMoreElements(); ) {
            perms.add(e.nextElement());
        }
    }
    return this;
}
 
Example 11
Source File: FieldSetAccessibleTest.java    From native-obfuscator with GNU General Public License v3.0 5 votes vote down vote up
public PermissionsBuilder addAll(PermissionCollection col) {
    if (col != null) {
        for (Enumeration<Permission> e = col.elements(); e.hasMoreElements(); ) {
            perms.add(e.nextElement());
        }
    }
    return this;
}
 
Example 12
Source File: DefaultLoggerBridgeTest.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
public PermissionsBuilder addAll(PermissionCollection col) {
    if (col != null) {
        for (Enumeration<Permission> e = col.elements(); e.hasMoreElements(); ) {
            perms.add(e.nextElement());
        }
    }
    return this;
}
 
Example 13
Source File: ClassDeclaredFieldsTest.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
public PermissionsBuilder addAll(PermissionCollection col) {
    if (col != null) {
        for (Enumeration<Permission> e = col.elements(); e.hasMoreElements(); ) {
            perms.add(e.nextElement());
        }
    }
    return this;
}
 
Example 14
Source File: LoggerFinderLoaderTest.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
public PermissionsBuilder addAll(PermissionCollection col) {
    if (col != null) {
        for (Enumeration<Permission> e = col.elements(); e.hasMoreElements(); ) {
            perms.add(e.nextElement());
        }
    }
    return this;
}
 
Example 15
Source File: ClassDeclaredFieldsTest.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
public PermissionsBuilder addAll(PermissionCollection col) {
    if (col != null) {
        for (Enumeration<Permission> e = col.elements(); e.hasMoreElements(); ) {
            perms.add(e.nextElement());
        }
    }
    return this;
}
 
Example 16
Source File: FieldSetAccessibleTest.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
public PermissionsBuilder addAll(PermissionCollection col) {
    if (col != null) {
        for (Enumeration<Permission> e = col.elements(); e.hasMoreElements(); ) {
            perms.add(e.nextElement());
        }
    }
    return this;
}
 
Example 17
Source File: FileHandlerPath.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
public PermissionsBuilder addAll(PermissionCollection col) {
    if (col != null) {
        for (Enumeration<Permission> e = col.elements(); e.hasMoreElements(); ) {
            perms.add(e.nextElement());
        }
    }
    return this;
}
 
Example 18
Source File: FieldSetAccessibleTest.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
public PermissionsBuilder addAll(PermissionCollection col) {
    if (col != null) {
        for (Enumeration<Permission> e = col.elements(); e.hasMoreElements(); ) {
            perms.add(e.nextElement());
        }
    }
    return this;
}
 
Example 19
Source File: DelegationPermissionCollection.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
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 vote down vote up
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");
        }
    }