Package gabriel

Examples of gabriel.Principal


   * ACL lists by name with one default list "Default".
   */
  public AccessManagerImpl(AclStore store) {
    this.store = store;

    owner = new Principal("owner");
    acl = store.getAcl(owner, "access");
  }
View Full Code Here


  }

  private Acl parse(Principal owner, String name, String input) {
    boolean negative = false;

    Principal principal = null;
    List permissions = new ArrayList();

    Acl acl = new Acl(owner, name);

    int PERMISSIONS = 1;
    int PRINCIPAL = 2;

    int state = PRINCIPAL;

    for (StringTokenizer stringTokenizer = new StringTokenizer(input, " \n{}", true);
         stringTokenizer.hasMoreTokens();) {

      String t = stringTokenizer.nextToken();

      if (" ".equals(t) || "\n".equals(t)) {
        // do nothing
      } else if ("{".equals(t)) {
        state = PERMISSIONS;
         } else if ("}".equals(t)) {
        state = PRINCIPAL;

        AclEntry entry = new AclEntry(principal);
        Iterator iterator = permissions.iterator();
        while (iterator.hasNext()) {
          Permission permission = (Permission) iterator.next();
          entry.addPermission(permission);
        }
        if (negative) {
          entry.setNegativePermissions();
          negative = false;
        }
        acl.addEntry(owner, entry);
        permissions = new ArrayList();
        principal = null;
      } else if (state == PRINCIPAL) {
        if (t.startsWith("-")) {
          negative = true;
          t = t.substring(1);
        }
        // handle "- principal" and "-principal"
        if (!"".equals(t)) {
          principal = new Principal(t);
        }
      } else if (state == PERMISSIONS) {
        permissions.add(new Permission(t));
      }
    }
View Full Code Here

    }
    System.out.println("object.name = " + object.getName());

    System.out.println("Adding \"ExampleUser\" to our principals.");
    // We are now member of group "ExampleUser
    principals.add(new Principal("ExampleUser"));
    // We have to set the principals again as they are copied not referenced
    // inside subject.
    subject.setPrincipals(principals);
    System.out.print("We try to call setName() on \""+object.getName()+"\" ... ");
    object.setName("changed!");
View Full Code Here

   */
  public boolean checkPermission(Set principals, Permission permission) {
    boolean hasPermission = false;
    Iterator iterator = principals.iterator();
    while (iterator.hasNext()) {
      Principal principal = (Principal) iterator.next();
      hasPermission = hasPermission || (checkPermission(principal, permission) != -1);
    }
    return hasPermission;
  }
View Full Code Here

      }
    });
  }

  public void testCheckPermission() {
    Principal principal = new Principal("TestPrincipal");
    Permission permission = new Permission("TestPermission");
    accessManager.addPermission(principal, permission);
    Set principals = new HashSet();
    principals.add(principal);
    assertTrue("TestPrincipal has TestPermission.",
View Full Code Here

  }

  public void testCheckPermission() {

    Permission permission = new Permission("TestPermission");
    Principal principal = new Principal("TestPrincipal");
    Set principals = new HashSet();
    principals.add(principal);
    mockAccessManager.expects(once()).method("checkPermission").with(same(principals), same(permission)).will(returnValue(true));
    mockMethodStore.expects(once()).method("getMap").will(returnValue(new HashMap()));
    callManager.addMethods(permission, new String[]{"TestClass.method1"});
View Full Code Here

    return new TestSuite(AclStoreTest.class);
  }

  protected void setUp() throws Exception {
    super.setUp();
    owner = new Principal("Owner");
    name = "TestName";
  }
View Full Code Here

        "            PP2 { PM1 }";

    Acl acl = manager.parse(owner, name, new StringReader(source));

    assertEquals("PP1 has PM1",
        1, acl.checkPermission(new Principal("PP1"), new Permission("PM1")));
    assertEquals("PP1 has PM2",
        1, acl.checkPermission(new Principal("PP1"), new Permission("PM2")));
    assertEquals("PP1 has PM3",
        1, acl.checkPermission(new Principal("PP1"), new Permission("PM3")));
    assertEquals("PP2 has PM1",
        1, acl.checkPermission(new Principal("PP2"), new Permission("PM1")));
  }
View Full Code Here

    String source = "-PP1 { PM1 }";

    Acl acl = manager.parse(owner, name, new StringReader(source));

    assertEquals("PP1 is denied PM1",
        -1, acl.checkPermission(new Principal("PP1"), new Permission("PM1")));

  }
View Full Code Here

  }


  public void testCallsModifyOnContext() {
    Permission permission = new Permission("TestPermission");
    Principal principal = new Principal("TestPrincipal");
    Set principals = new HashSet();
    principals.add(principal);

    mockContext.expects(once()).method("modifyPrincipal").with(same(principals));
View Full Code Here

TOP

Related Classes of gabriel.Principal

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.