Package com.google.feedserver.resource

Examples of com.google.feedserver.resource.Acl


  /**
   * Two authorized entities with one principal each.  Remove another principal.  Should be
   * unchanged.
   */
  public void testRemoveAcl3() {
    Acl acl = new Acl("acl0", new ResourceInfo("resourceRule0", ResourceInfo.RESOURCE_TYPE_FEED),
        new AuthorizedEntity[] {authorizedEntity_r_0, authorizedEntity_u_0});
    aclTool.removeAcl(Arrays.asList(acl), 'r', USER9);

    assertEquals(2, acl.getAuthorizedEntities().length);

    assertEquals(1, acl.getAuthorizedEntities()[0].getEntities().length);
    assertEquals(AuthorizedEntity.OPERATION_RETRIEVE, acl.getAuthorizedEntities()[0].getOperation());
    assertEquals(USER0, acl.getAuthorizedEntities()[0].getEntities()[0]);

    assertEquals(1, acl.getAuthorizedEntities()[1].getEntities().length);
    assertEquals(AuthorizedEntity.OPERATION_UPDATE, acl.getAuthorizedEntities()[1].getOperation());
    assertEquals(USER0, acl.getAuthorizedEntities()[1].getEntities()[0]);
  }
View Full Code Here


  /**
   * One authorized entity with one principal.  Remove that principal.  Should get zero authorized
   * entities.
   */
  public void testRemoveAcl4() {
    Acl acl = new Acl("acl0", new ResourceInfo("resourceRule0", ResourceInfo.RESOURCE_TYPE_FEED),
        new AuthorizedEntity[] {authorizedEntity_r_0});
    aclTool.removeAcl(Arrays.asList(acl), 'r', USER0);

    assertEquals(0, acl.getAuthorizedEntities().length);
  }
View Full Code Here

  /**
   * One authorized entity with two principals.  Remove second principal.  Should get one
   * authorized entity of first principal.
   */
  public void testRemoveAcl5() {
    Acl acl = new Acl("acl0", new ResourceInfo("resourceRule0", ResourceInfo.RESOURCE_TYPE_FEED),
        new AuthorizedEntity[] {authorizedEntity_r_0_1});
    aclTool.removeAcl(Arrays.asList(acl), 'r', USER1);

    assertEquals(1, acl.getAuthorizedEntities().length);
    assertEquals(1, acl.getAuthorizedEntities()[0].getEntities().length);
    assertEquals(USER0, acl.getAuthorizedEntities()[0].getEntities()[0]);
  }
View Full Code Here

  /**
   * One authorized entity with two principals.  Remove first principal.  Should get one
   * authorized entity of second principal.
   */
  public void testRemoveAcl6() {
    Acl acl = new Acl("acl0", new ResourceInfo("resourceRule0", ResourceInfo.RESOURCE_TYPE_FEED),
        new AuthorizedEntity[] {authorizedEntity_r_0_1});
    aclTool.removeAcl(Arrays.asList(acl), 'r', USER0);

    assertEquals(1, acl.getAuthorizedEntities().length);
    assertEquals(1, acl.getAuthorizedEntities()[0].getEntities().length);
    assertEquals(USER1, acl.getAuthorizedEntities()[0].getEntities()[0]);
  }
View Full Code Here

   * @param principalToAdd Principal of interest
   */
  protected void addAcl(List<Acl> existingAcls, char op, String principalToAdd) {
    removeAcl(existingAcls, op, principalToAdd);

    Acl firstAcl = (existingAcls.size() > 0) ? existingAcls.get(0) : new Acl();
    if (existingAcls.size() == 0) {
      existingAcls.add(firstAcl);
    }

    boolean opFound = false;
    if (firstAcl.getAuthorizedEntities() != null) {
      for (AuthorizedEntity authorizedEntity: firstAcl.getAuthorizedEntities()) {
        if (authorizedEntity.getOperation().charAt(0) == op) {
          opFound = true;
          String[] currentPrincipals = authorizedEntity.getEntities();
          if (currentPrincipals == null) {
            authorizedEntity.setEntities(new String[]{principalToAdd});
          } else {
            String[] updatedPrincipals = new String[currentPrincipals.length + 1];
            for (int i = 0; i < currentPrincipals.length; i++) {
              updatedPrincipals[i] = currentPrincipals[i];
            }
            updatedPrincipals[currentPrincipals.length] = principalToAdd;
            authorizedEntity.setEntities(updatedPrincipals);
          }
        }
      }
    }

    if (!opFound) {
      int currentLength = firstAcl.getAuthorizedEntities().length;
      AuthorizedEntity[] updatedAuthorizedEntities =
          new AuthorizedEntity[currentLength + 1];
      for (int i = 0; i < currentLength; i++) {
        updatedAuthorizedEntities[i] = firstAcl.getAuthorizedEntities()[i];
      }
     
      AuthorizedEntity authorizedEntity = new AuthorizedEntity();
      authorizedEntity.setOperation(authorizedEntity.lookupOperation(op));
      authorizedEntity.setEntities(new String[]{principalToAdd});
      updatedAuthorizedEntities[currentLength] = authorizedEntity;
      firstAcl.setAuthorizedEntities(updatedAuthorizedEntities);
    }
  }
View Full Code Here

TOP

Related Classes of com.google.feedserver.resource.Acl

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.