FileDocCategorySizeDatePackage
MyPolicy.javaAPI DocExample1641Sat Jan 13 12:16:20 GMT 2001javasec.samples.ch05

MyPolicy.java

package javasec.samples.ch05;

import java.security.*;
import java.util.*;

public class MyPolicy extends Policy {

    // This inner class defines a simple set of permissions:
    // either everything is allowed (the implies() method always
    // returns true, and the collection contains an AllPermission
    // object) or everything is prohibited (the implies()
    // method always returns false and the collection is empty).
    static class SimplePermissions extends PermissionCollection {
        boolean allow;
        Permissions perms;

        SimplePermissions(boolean b) {
            allow = b;
            perms = new Permissions();
            if (allow)
                perms.add(new AllPermission());
        }

        public void add(Permission p) {
            if (isReadOnly())
                throw new SecurityException(
                             "Can