Package net.jini.security

Examples of net.jini.security.GrantPermission


import java.security.Permission;
import net.jini.security.GrantPermission;

public class Test {
    public static void main(String[] args) throws Exception {
  Permission gp1 = new GrantPermission("FooPermission"),
       gp2 = new GrantPermission("FooPermission; FooPermission"),
       gp3 = new GrantPermission(new FooPermission()),
       gp4 = new GrantPermission("FooPermission; BarPermission"),
       gp5 = new GrantPermission("BarPermission");
      
  // sanity check
  if (!(gp1.equals(gp2) && gp1.implies(gp2) &&
        gp1.hashCode() == gp2.hashCode()))
  {
      throw new Error();
  }
  // unresolved FooPerm should imply resolved FooPerm
  if (!gp1.implies(gp3)) {
      throw new Error();
  }
  // resolved FooPerm should not imply or equal unresolved FooPerm
  if (gp1.equals(gp3) || gp3.implies(gp1)) {
      throw new Error();
  }
  // original equality should still hold despite gp1 "inflation"
  if (!(gp1.equals(gp2) && gp1.implies(gp2) && gp2.implies(gp1) &&
        gp1.hashCode() == gp2.hashCode()))
  {
      throw new Error();
  }
  // unresolved FooPerm should not imply or equal unresolved FooPerm +
  // unresolved BarPerm
  if (gp1.implies(gp4) || gp1.equals(gp4)) {
      throw new Error();
  }
  // ...but unresolved FooPerm, BarPerm should imply unresolved FooPerm
  if (!gp4.implies(gp1)) {
      throw new Error();
  }
  // disjoint unresolved perms shouldn't imply or equal each other
  if (gp1.implies(gp5) || gp5.implies(gp1) || gp1.equals(gp5)) {
      throw new Error();
  }
  // sanity check
  if (!gp4.implies(gp5)) {
      throw new Error();
View Full Code Here


        /*
         * Create three GrantPermissions passing created FilePermissions
         * with "read", "write" and "read,write" actions.
         */
        GrantPermission gp01 = new GrantPermission(fp01);
        GrantPermission gp02 = new GrantPermission(fp02);
        GrantPermission gp03 = new GrantPermission(fp03);

        /*
         * Create GrantPermission passing array of two created
         * GrantPermissions for "read" and "write" actions.
         */
        Permission[] pa = { fp01, fp02 };
        GrantPermission gppa = new GrantPermission(pa);

        /*
         * Verify that last created GrantPermission implies
         * GrantPermission that was created
         * for "read,write" action.
View Full Code Here

    public static void main(String[] args) {
  Security.setProperty(
      "package.access", "sun.,net.jini.security.policy.");
  System.setSecurityManager(new SecurityManager());
  try {
      new GrantPermission(
    "net.jini.security.policy.UmbrellaGrantPermission");
      throw new Error();
  } catch (SecurityException e) {
      System.out.println("caught expected exception: " + e);
  }
  try {
      new GrantPermission("java.lang.Object");
      throw new Error();
  } catch (IllegalArgumentException e) {
      System.out.println("caught expected exception: " + e);
  }
    }
View Full Code Here

  final int MAX_NEST = 4;

  RuntimePermission rp = new RuntimePermission("foo");
  GrantPermission[] perms = new GrantPermission[MAX_NEST * 2];
  for (int i = 0; i < MAX_NEST; i++) {
      GrantPermission gp = new GrantPermission(rp);
      for (int j = 0; j < i; j++) {
    gp = new GrantPermission(gp);
      }
      perms[i * 2] = gp;
      perms[i * 2 + 1] = (GrantPermission) serializedCopy(gp);
  }
 
View Full Code Here

  testSerialize(new Permission[]{
      new Permission2("a \"quoted\" string",
    "\b\f\n\r\t \"\b\f\n\r\t\"")
  });
  testSerialize(new Permission[]{
      new GrantPermission(new Permission1("1n")),
      new Permission0a()
  });
  testSerializeUnresolved(new Permission[]{
      new UnresolvedPermission("foo", "bar", "", null),
      new Permission0()
View Full Code Here

      new Permission0()
  });
    }
   
    static void testSerialize(Permission[] grants) throws Exception {
  GrantPermission gp = new GrantPermission(grants);
  PermissionCollection gpc = gp.newPermissionCollection();
  gpc.add(gp);

  ByteArrayOutputStream bout = new ByteArrayOutputStream();
  ObjectOutputStream oout = new ObjectOutputStream(bout);
  oout.writeObject(gp);
  oout.writeObject(gpc);
  oout.close();

  ObjectInputStream oin = new ObjectInputStream(
      new ByteArrayInputStream(bout.toByteArray()));
  gp = (GrantPermission) oin.readObject();
  gpc = (PermissionCollection) oin.readObject();
  for (int i = 0; i < grants.length; i++) {
      Permission p = new GrantPermission(grants[i]);
      if (!(gp.implies(p) && gpc.implies(p))) {
    System.out.println(gp.getName());
    throw new Error();
      }
  }
View Full Code Here

      }
  }
    }

    static void testSerializeUnresolved(Permission[] grants) throws Exception {
  GrantPermission gp = new GrantPermission(grants);
  ObjectOutputStream oout =
      new ObjectOutputStream(new ByteArrayOutputStream());
  try {
      oout.writeObject(gp);
      throw new Error();
View Full Code Here

  }
  Policy policy = new PolicyFileProvider();

  checkPermissions(policy, "file:/foo.jar",
      new Permission[]{
    new GrantPermission(new RuntimePermission("A")),
    new GrantPermission(new RuntimePermission("B")),
    new GrantPermission(new RuntimePermission("C"))
      },
      new Permission[]{
    new GrantPermission(new RuntimePermission("D"))
      });
  checkPermissions(policy, "file:/bar.jar",
      new Permission[]{
    new GrantPermission(new RuntimePermission("C"))
      },
      new Permission[]{
    new GrantPermission(new RuntimePermission("A")),
    new GrantPermission(new RuntimePermission("B")),
    new GrantPermission(new RuntimePermission("D"))
      });
    }
View Full Code Here

        UnresolvedPermission foo = new UnresolvedPermission("FooPermission", null, null, null),
                             foo2 = new UnresolvedPermission("FooPermission", null, null, null),
                             bar = new UnresolvedPermission("BarPermission", null, null, null);
        Permission [] foos = {foo, foo2};
        Permission [] fooBar = {foo, bar};
  Permission gp1 = new GrantPermission(foo),
       gp2 = new GrantPermission(foos),
       gp3 = new GrantPermission(new FooPermission()),
       gp4 = new GrantPermission(fooBar),
       gp5 = new GrantPermission(bar);
      
  // sanity check
  if (!(gp1.equals(gp2) && gp1.implies(gp2) &&
        gp1.hashCode() == gp2.hashCode()))
  {
      throw new Error();
  }
  // unresolved FooPerm should imply resolved FooPerm
  if (!gp1.implies(gp3)) {
      throw new Error("GrantPermission, containing UnresolvedPermission" +
                    "identical to a resolved instance of that permission" +
                    "does not imply as expected");
  }
  // resolved FooPerm should not imply or equal unresolved FooPerm
  if (gp1.equals(gp3) || gp3.implies(gp1)) {
      throw new Error();
  }
  // original equality should still hold despite gp1 "inflation"
  if (!(gp1.equals(gp2) && gp1.implies(gp2) && gp2.implies(gp1) &&
        gp1.hashCode() == gp2.hashCode()))
  {
      throw new Error();
  }
  // unresolved FooPerm should not imply or equal unresolved FooPerm +
  // unresolved BarPerm
  if (gp1.implies(gp4) || gp1.equals(gp4)) {
      throw new Error();
  }
  // ...but unresolved FooPerm, BarPerm should imply unresolved FooPerm
  if (!gp4.implies(gp1)) {
      throw new Error();
  }
  // disjoint unresolved perms shouldn't imply or equal each other
  if (gp1.implies(gp5) || gp5.implies(gp1) || gp1.equals(gp5)) {
      throw new Error();
  }
  // sanity check
  if (!gp4.implies(gp5)) {
      throw new Error();
View Full Code Here

  Permission[] pa = new Permission[]{
      new Permission0(),
      new Permission1("1n"),
      new Permission2("2n", "2a")
  };
  Permission gp = new GrantPermission(
      "Permission0;" +
      "Permission1 \"1n\";" +
      "Permission2 \"2n\", \"2a\";"
  );
  for (int i = 0; i < pa.length; i++) {
      if (!gp.implies(new GrantPermission(pa[i]))) {
    throw new Error();
      }
  }
  if (gp.implies(new GrantPermission(new Permission1("other")))) {
      throw new Error();
  }
 
  gp = new GrantPermission(
      "delim=| " +
      "Permission0;" +
      "Permission1 |1n|;" +
      "Permission2 |2n|, |2a|;"
  );
  for (int i = 0; i < pa.length; i++) {
      if (!gp.implies(new GrantPermission(pa[i]))) {
    throw new Error();
      }
  }
  if (gp.implies(new GrantPermission(new Permission1("other")))) {
      throw new Error();
  }

 
  pa = new Permission[]{
      new Permission1(null), new Permission2(null, null)
  };
  gp = new GrantPermission("Permission1; Permission2");
  for (int i = 0; i < pa.length; i++) {
      if (!gp.implies(new GrantPermission(pa[i]))) {
    throw new Error();
      }
  }
 
  gp = new GrantPermission("Permission2 \"2n\"");
  if (!gp.implies(new GrantPermission(new Permission2("2n", null)))) {
      throw new Error();
  }
 
  gp = new GrantPermission(
      "Permission2 \"a \\\"nested\\\" quote\", \"foo\"");
  if (!gp.implies(
      new GrantPermission(new Permission2("a \"nested\" quote", "foo"))))
  {
      throw new Error();
  }
 
  gp = new GrantPermission(
      "delim=' Permission2 'a \"nested\" quote', 'foo'");
  if (!gp.implies(
      new GrantPermission(new Permission2("a \"nested\" quote", "foo"))))
  {
      throw new Error();
  }
 
  String[] illegal = new String[]{
      "",
      ";",
      "FooPermission \"a\" \"b\"",
      "FooPermission ;;",
      "FooPermission \"a\", \"b\", \"c\"",
      "\"FooPermission\"",
      "FooPermission unquoted",
      "delim=bad FooPermission",
      "delim=; FooPermission",
      "delim=|",
      "delim=| delim=% FooPermission",
      "delim=\t FooPermission",
      "delim=\n FooPermission"
  };
  for (int i = 0; i < illegal.length; i++) {
      try {
    new GrantPermission(illegal[i]);
    throw new Error();
      } catch (IllegalArgumentException ex) {
      }
  }
    }
View Full Code Here

TOP

Related Classes of net.jini.security.GrantPermission

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.