예제 #1
0
  public void testGetOrCreateAcl() {
    // create ACL with name ACL.LOCAL_ACL
    ACL createdAcl = acp.getOrCreateACL();
    createdAcl.add(new ACE("john", "Sing", true));
    createdAcl.add(new ACE("anne", "Joke", false));

    // check that the ACP has already been affected by the ACL editing
    assertTrue(acp.getAccess("john", "Sing").toBoolean());
    assertFalse(acp.getAccess("anne", "Joke").toBoolean());

    // check that by fetching the acl again we get the same instance
    ACL fetchedAcl = acp.getOrCreateACL();
    assertEquals(createdAcl, fetchedAcl);
    assertTrue(acp.getAccess("john", "Sing").toBoolean());
    assertFalse(acp.getAccess("anne", "Joke").toBoolean());

    // check that setting the same ACL again does not clear it
    acp.addACL(fetchedAcl);
    assertEquals(createdAcl, fetchedAcl);
    assertTrue(acp.getAccess("john", "Sing").toBoolean());
    assertFalse(acp.getAccess("anne", "Joke").toBoolean());

    // check that setting an empty ACL with the same name clear the
    // permissions
    acp.addACL(new ACLImpl(ACL.LOCAL_ACL));
    assertFalse(acp.getAccess("john", "Sing").toBoolean());
  }
예제 #2
0
  public void testPermissionsAPI() {
    ACL acl = new ACLImpl("acl1");

    ACE bart = new ACE("bart", EVERYTHING, true);
    ACE notbart = new ACE("notbart", EVERYTHING, false);
    ACE homer = new ACE("homer", BROWSE, true);
    ACE lisa = new ACE("lisa", BROWSE, true);

    acl.add(bart);
    acl.add(notbart);
    acl.add(homer);
    acl.add(lisa);
    acp.addACL(acl);

    String[] usernames = acp.listUsernamesForPermission(BROWSE);
    assertEquals(2, usernames.length);

    usernames = acp.listUsernamesForPermission(EVERYTHING);
    assertEquals(1, usernames.length);

    Set<String> perms = new HashSet<String>(3);
    perms.add(BROWSE);
    perms.add(READ);
    perms.add(WRITE);
    usernames = acp.listUsernamesForAnyPermission(perms);
    assertEquals(2, usernames.length);
  }
예제 #3
0
  public void testCheckAccess() {
    ACL acl1 = new ACLImpl("acl1");
    ACE ace1 = new ACE("joe", EVERYTHING, true);
    acl1.add(ace1);
    acp.addACL(acl1);

    assertSame(GRANT, acp.getAccess("joe", READ));
    assertSame(UNKNOWN, acp.getAccess("joe", RESTRICTED_READ));
    assertSame(UNKNOWN, acp.getAccess("jack", READ));
  }