Package com.intridea.io.vfs.operations

Examples of com.intridea.io.vfs.operations.Acl


   *
   * @return Current Access control list for a file
   * @throws FileSystemException
   */
  public Acl getAcl() throws FileSystemException {
    Acl myAcl = new Acl();
    AccessControlList s3Acl;
    try {
      s3Acl = getS3Acl();
    } catch (Exception e) {
      throw new FileSystemException(e);
    }

    // Get S3 file owner
    Owner owner = s3Acl.getOwner();
    fileOwner = owner;

    // Read S3 ACL list and build VFS ACL.
    Set<Grant> grants = s3Acl.getGrants();

    for (Grant item : grants) {
      // Map enums to jets3t ones
      Permission perm = item.getPermission();
      Acl.Permission[] rights;
      if (perm.equals(Permission.FullControl)) {
        rights = Acl.Permission.values();
      } else if (perm.equals(Permission.Read)) {
        rights = new Acl.Permission[1];
        rights[0] = Acl.Permission.READ;
      } else if (perm.equals(Permission.Write)) {
        rights = new Acl.Permission[1];
        rights[0] = Acl.Permission.WRITE;
      } else {
        // Skip unknown permission
        logger.error(String.format("Skip unknown permission %s", perm));
        continue;
      }

      // Set permissions for groups
      if (item.getGrantee() instanceof GroupGrantee) {
        GroupGrantee grantee = (GroupGrantee) item.getGrantee();
        if (GroupGrantee.AllUsers.equals(grantee)) {
          // Allow rights to GUEST
          myAcl.allow(Acl.Group.EVERYONE, rights);
        } else if (GroupGrantee.AuthenticatedUsers.equals(grantee)) {
          // Allow rights to AUTHORIZED
          myAcl.allow(Acl.Group.AUTHORIZED, rights);
        }
      } else if (item.getGrantee() instanceof CanonicalGrantee) {
        CanonicalGrantee grantee = (CanonicalGrantee) item.getGrantee();
        if (grantee.getIdentifier().equals(owner.getId())) {
          // The same owner and grantee understood as OWNER group
          myAcl.allow(Acl.Group.OWNER, rights);
        }
      }

    }

View Full Code Here


        aclSetter.process();

        // Verify
        IAclGetter aclGetter = (IAclGetter)file.getFileOperations().getOperation(IAclGetter.class);
        aclGetter.process();
        Acl changedAcl = aclGetter.getAcl();

        // Guest can read
        Assert.assertTrue(changedAcl.isAllowed(Acl.Group.EVERYONE, Acl.Permission.READ));
        // Write rules for guest not changed
        Assert.assertEquals(
            changedAcl.isAllowed(Acl.Group.EVERYONE, Acl.Permission.WRITE),
            fileAcl.isAllowed(Acl.Group.EVERYONE, Acl.Permission.WRITE)
        );
        // Read rules not spreaded to another groups
        Assert.assertEquals(
            changedAcl.isAllowed(Acl.Group.AUTHORIZED, Acl.Permission.READ),
            fileAcl.isAllowed(Acl.Group.AUTHORIZED, Acl.Permission.READ)
        );
        Assert.assertEquals(
            changedAcl.isAllowed(Acl.Group.OWNER, Acl.Permission.READ),
            fileAcl.isAllowed(Acl.Group.OWNER, Acl.Permission.READ)
        );

        fileAcl = changedAcl;
    }
View Full Code Here

        aclSetter.process();

        // Verify
        IAclGetter aclGetter = (IAclGetter)file.getFileOperations().getOperation(IAclGetter.class);
        aclGetter.process();
        Acl changedAcl = aclGetter.getAcl();

        // Authorized can do everything
        Assert.assertTrue(changedAcl.isAllowed(Acl.Group.AUTHORIZED, Acl.Permission.READ));
        Assert.assertTrue(changedAcl.isAllowed(Acl.Group.AUTHORIZED, Acl.Permission.WRITE));

        // All other rules not changed
        Assert.assertEquals(
            changedAcl.isAllowed(Acl.Group.EVERYONE, Acl.Permission.READ),
            fileAcl.isAllowed(Acl.Group.EVERYONE, Acl.Permission.READ)
        );
        Assert.assertEquals(
            changedAcl.isAllowed(Acl.Group.EVERYONE, Acl.Permission.WRITE),
            fileAcl.isAllowed(Acl.Group.EVERYONE, Acl.Permission.WRITE)
        );
        Assert.assertEquals(
            changedAcl.isAllowed(Acl.Group.OWNER, Acl.Permission.READ),
            fileAcl.isAllowed(Acl.Group.OWNER, Acl.Permission.READ)
        );
        Assert.assertEquals(
            changedAcl.isAllowed(Acl.Group.OWNER, Acl.Permission.WRITE),
            fileAcl.isAllowed(Acl.Group.OWNER, Acl.Permission.WRITE)
        );

        fileAcl = changedAcl;
    }
View Full Code Here

        aclSetter.process();

        // Verify
        IAclGetter aclGetter = (IAclGetter)file.getFileOperations().getOperation(IAclGetter.class);
        aclGetter.process();
        Acl changedAcl = aclGetter.getAcl();

        Assert.assertTrue(changedAcl.isDenied(Acl.Group.OWNER, Acl.Permission.READ));
        Assert.assertTrue(changedAcl.isDenied(Acl.Group.OWNER, Acl.Permission.WRITE));
        Assert.assertTrue(changedAcl.isDenied(Acl.Group.AUTHORIZED, Acl.Permission.READ));
        Assert.assertTrue(changedAcl.isDenied(Acl.Group.AUTHORIZED, Acl.Permission.WRITE));
        Assert.assertTrue(changedAcl.isDenied(Acl.Group.EVERYONE, Acl.Permission.READ));
        Assert.assertTrue(changedAcl.isDenied(Acl.Group.EVERYONE, Acl.Permission.WRITE));
    }
View Full Code Here

     *
     * @return Current Access control list for a file
     * @throws FileSystemException
     */
    public Acl getAcl () throws FileSystemException {
        Acl myAcl = new Acl();
        AccessControlList s3Acl;
        try {
            s3Acl = getS3Acl();
        } catch (AmazonServiceException e) {
            throw new FileSystemException(e);
        }

        // Get S3 file owner
        Owner owner = s3Acl.getOwner();
        fileOwner = owner;

        // Read S3 ACL list and build VFS ACL.
        Set<Grant> grants = s3Acl.getGrants();

        for (Grant item : grants) {
            // Map enums to jets3t ones
            Permission perm = item.getPermission();
            Acl.Permission[] rights;
            if (perm.equals(Permission.FullControl)) {
                rights = Acl.Permission.values();
            } else if (perm.equals(Permission.Read)) {
                rights = new Acl.Permission[1];
                rights[0] = READ;
            } else if (perm.equals(Permission.Write)) {
                rights = new Acl.Permission[1];
                rights[0] = WRITE;
            } else {
                // Skip unknown permission
                logger.error(String.format("Skip unknown permission %s", perm));
                continue;
            }

            // Set permissions for groups
            if (item.getGrantee() instanceof GroupGrantee) {
                GroupGrantee grantee = (GroupGrantee)item.getGrantee();
                if (GroupGrantee.AllUsers.equals(grantee)) {
                    // Allow rights to GUEST
                    myAcl.allow(Acl.Group.EVERYONE, rights);
                } else if (GroupGrantee.AuthenticatedUsers.equals(grantee)) {
                    // Allow rights to AUTHORIZED
                    myAcl.allow(Acl.Group.AUTHORIZED, rights);
                }
            } else if (item.getGrantee() instanceof CanonicalGrantee) {
                CanonicalGrantee grantee = (CanonicalGrantee)item.getGrantee();
                if (grantee.getIdentifier().equals(owner.getId())) {
                    // The same owner and grantee understood as OWNER group
                    myAcl.allow(Acl.Group.OWNER, rights);
                }
            }

        }

View Full Code Here

import com.intridea.io.vfs.operations.Acl;

@Test(groups="storage")
public class AclTest {
    public void testOperations () {
        Acl acl = new Acl(null);
        acl.denyAll();

        // Allow single right
        acl.allow(Acl.Group.OWNER, Acl.Permission.WRITE);
        Assert.assertTrue(acl.isAllowed(Acl.Group.OWNER, Acl.Permission.WRITE));

        // Deny single right
        acl.deny(Acl.Group.OWNER, Acl.Permission.WRITE);
        Assert.assertTrue(acl.isDenied(Acl.Group.OWNER, Acl.Permission.WRITE));

        // Allow rights
        Acl.Permission[] rights = {Acl.Permission.READ, Acl.Permission.WRITE};
        acl.allow(Acl.Group.AUTHORIZED, rights);
        Assert.assertTrue(acl.isAllowed(Acl.Group.AUTHORIZED, Acl.Permission.WRITE));
        Assert.assertTrue(acl.isAllowed(Acl.Group.AUTHORIZED, Acl.Permission.READ));

        // Deny rights
        acl.deny(Acl.Group.AUTHORIZED, rights);
        Assert.assertTrue(acl.isDenied(Acl.Group.AUTHORIZED, Acl.Permission.WRITE));
        Assert.assertTrue(acl.isDenied(Acl.Group.AUTHORIZED, Acl.Permission.READ));

        // Allow all to group
        acl.allow(Acl.Group.AUTHORIZED);
        Assert.assertTrue(acl.isAllowed(Acl.Group.AUTHORIZED, Acl.Permission.WRITE));
        Assert.assertTrue(acl.isAllowed(Acl.Group.AUTHORIZED, Acl.Permission.READ));

        // Deny all to group
        acl.deny(Acl.Group.AUTHORIZED);
        Assert.assertTrue(acl.isDenied(Acl.Group.AUTHORIZED, Acl.Permission.WRITE));
        Assert.assertTrue(acl.isDenied(Acl.Group.AUTHORIZED, Acl.Permission.READ));

        // Allow all to all
        acl.allowAll();
        Assert.assertTrue(acl.isAllowed(Acl.Group.AUTHORIZED, Acl.Permission.WRITE));
        Assert.assertTrue(acl.isAllowed(Acl.Group.EVERYONE, Acl.Permission.WRITE));
        Assert.assertTrue(acl.isAllowed(Acl.Group.OWNER, Acl.Permission.WRITE));

        // Deny all to all
        acl.denyAll();
        Assert.assertTrue(acl.isDenied(Acl.Group.AUTHORIZED, Acl.Permission.WRITE));
        Assert.assertTrue(acl.isDenied(Acl.Group.EVERYONE, Acl.Permission.WRITE));
        Assert.assertTrue(acl.isDenied(Acl.Group.OWNER, Acl.Permission.WRITE));
    }
View Full Code Here

TOP

Related Classes of com.intridea.io.vfs.operations.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.