Example #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());
  }
Example #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);
  }
Example #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));
  }
Example #4
0
  public QueueMessage() {
    this._modifiedColumns = new ArrayList<String>();
    this._modifiedColumns.add("createdAt");
    this._modifiedColumns.add("updatedAt");
    this._modifiedColumns.add("ACL");
    this._modifiedColumns.add("expires");
    this._modifiedColumns.add("timeout");
    this._modifiedColumns.add("delay");
    this._modifiedColumns.add("message");

    this.acl = new ACL();
    document = new JSONObject();
    try {
      document.put("_id", JSONObject.NULL);
      document.put("timeout", timeout);
      document.put("delay", JSONObject.NULL);

      document.put("_type", type);
      document.put("ACL", acl.getACL());
      document.put("expires", JSONObject.NULL);
      document.put("_modifiedColumns", this._modifiedColumns);
      document.put("_isModified", true);
      document.put("message", message);

    } catch (JSONException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
  }
Example #5
0
  /**
   * The note class based on the API documentation (NOTE_CLASS_xxx). This includes deprecated and
   * virtual types.
   */
  public static enum NoteClass {
    DOCUMENT(0x0001),
    DATA(DOCUMENT),
    INFO(0x0002),
    FORM(0x0004),
    VIEW(0x0008),
    ICON(0x0010),
    DESIGN(0x0020),
    ACL(0x0040),
    HELP_INDEX(0x0080),
    HELP(0x0100),
    FILTER(0x0200),
    FIELD(0x0400),
    REPLFORMULA(0x0800),
    PRIVATE(0x1000),
    DEFAULT(0x8000),
    NOTIFYDELETION(DEFAULT),
    ALL(0x7fff),
    ALLNONDATA(0x7ffe),
    NONE(0x000),
    SINGLE_INSTANCE(
        DESIGN.getValue()
            | ACL.getValue()
            | INFO.getValue()
            | ICON.getValue()
            | HELP_INDEX.getValue()
            | 0),
    HELPUSINGDOCUMENT(HELP_INDEX),
    HELPABOUTDOCUMENT(HELP),
    SHAREDFIELD(FORM);

    private final int value_;
    private final boolean alias_;

    private NoteClass(final int value) {
      value_ = value;
      alias_ = false;
    }

    private NoteClass(final NoteClass aliased) {
      value_ = aliased.getValue();
      alias_ = true;
    }

    public int getValue() {
      return value_;
    }

    public boolean isAlias() {
      return alias_;
    }

    public boolean isDesign() {
      return this != DOCUMENT && this != DATA;
    }
  }
Example #6
0
 private void collectGranteeIdsOnACL(ACL acl, Set<String>[] idHolders) {
   if (acl != null) {
     for (ACL.Grant grant : acl.getGrants()) {
       int idx = getGranteeBucket(grant.getGranteeType());
       if (idx != -1) {
         if (idHolders[idx] == null) {
           idHolders[idx] = new HashSet<String>();
         }
         idHolders[idx].add(grant.getGranteeId());
       }
     }
   }
 }
 public void setACL(ACL acl) throws Exception {
   aclents = acl.toACLEntries();
 }