Example usage for com.amazonaws.services.s3.model Permission Write

List of usage examples for com.amazonaws.services.s3.model Permission Write

Introduction

In this page you can find the example usage for com.amazonaws.services.s3.model Permission Write.

Prototype

Permission Write

To view the source code for com.amazonaws.services.s3.model Permission Write.

Click Source Link

Document

Grants permission to create, overwrite, and delete any objects in the bucket.

Usage

From source file:alluxio.underfs.s3a.S3AUtils.java

License:Apache License

/**
 * Translates S3 bucket ACL to Alluxio owner mode.
 *
 * @param acl the acl of S3 bucket//  ww w .  jav  a 2  s  .co m
 * @param userId the S3 user id of the Alluxio owner
 * @return the translated posix mode in short format
 */
public static short translateBucketAcl(AccessControlList acl, String userId) {
    short mode = (short) 0;
    for (Grant grant : acl.getGrantsAsList()) {
        Permission perm = grant.getPermission();
        Grantee grantee = grant.getGrantee();
        if (perm.equals(Permission.Read)) {
            if (isUserIdInGrantee(grantee, userId)) {
                // If the bucket is readable by the user, add r and x to the owner mode.
                mode |= (short) 0500;
            }
        } else if (perm.equals(Permission.Write)) {
            if (isUserIdInGrantee(grantee, userId)) {
                // If the bucket is writable by the user, +w to the owner mode.
                mode |= (short) 0200;
            }
        } else if (perm.equals(Permission.FullControl)) {
            if (isUserIdInGrantee(grantee, userId)) {
                // If the user has full control to the bucket, +rwx to the owner mode.
                mode |= (short) 0700;
            }
        }
    }
    return mode;
}

From source file:com.easarrive.aws.plugins.common.service.impl.S3Service.java

License:Open Source License

/**
 * {@inheritDoc}//from  w w w  .ja  v  a 2  s .  co m
 */
@Override
public PutObjectResult putObjectAllRW(AmazonS3 client, String bucketName, String key, File file) {
    Grant readGrant = new Grant(GroupGrantee.AllUsers, Permission.Read);
    Grant writeGrant = new Grant(GroupGrantee.AllUsers, Permission.Write);
    return this.putObject(client, bucketName, key, file, readGrant, writeGrant);
}

From source file:com.easarrive.aws.plugins.common.service.impl.S3Service.java

License:Open Source License

/**
 * {@inheritDoc}/*  w  ww.j  a va  2 s .  com*/
 */
@Override
public PutObjectResult putObjectAllRW(AmazonS3 client, String bucketName, String key, InputStream input,
        ObjectMetadata metadata) {
    Grant readGrant = new Grant(GroupGrantee.AllUsers, Permission.Read);
    Grant writeGrant = new Grant(GroupGrantee.AllUsers, Permission.Write);
    return this.putObject(client, bucketName, key, input, metadata, readGrant, writeGrant);
}

From source file:com.upplication.s3fs.S3FileSystemProvider.java

License:Open Source License

@Override
public void checkAccess(Path path, AccessMode... modes) throws IOException {
    S3Path s3Path = (S3Path) path;
    Preconditions.checkArgument(s3Path.isAbsolute(), "path must be absolute: %s", s3Path);

    AmazonS3Client client = s3Path.getFileSystem().getClient();

    // get ACL and check if the file exists as a side-effect
    AccessControlList acl = getAccessControl(s3Path);

    for (AccessMode accessMode : modes) {
        switch (accessMode) {
        case EXECUTE:
            throw new AccessDeniedException(s3Path.toString(), null, "file is not executable");
        case READ:
            if (!hasPermissions(acl, client.getS3AccountOwner(),
                    EnumSet.of(Permission.FullControl, Permission.Read))) {
                throw new AccessDeniedException(s3Path.toString(), null, "file is not readable");
            }//from   ww w .  ja v a2s.c  om
            break;
        case WRITE:
            if (!hasPermissions(acl, client.getS3AccountOwner(),
                    EnumSet.of(Permission.FullControl, Permission.Write))) {
                throw new AccessDeniedException(s3Path.toString(), null,
                        format("bucket '%s' is not writable", s3Path.getBucket()));
            }
            break;
        }
    }
}

From source file:com.upplication.s3fs.util.AmazonS3ClientMock.java

License:Open Source License

private AccessControlList createAllPermission() {
    AccessControlList res = new AccessControlList();
    res.setOwner(getS3AccountOwner());//from w ww  . java  2 s .c o  m
    Grantee grant = new Grantee() {

        @Override
        public void setIdentifier(String id) {
        }

        @Override
        public String getTypeIdentifier() {
            return getS3AccountOwner().getId();
        }

        @Override
        public String getIdentifier() {
            return getS3AccountOwner().getId();
        }
    };

    res.grantPermission(grant, Permission.FullControl);
    res.grantPermission(grant, Permission.Read);
    res.grantPermission(grant, Permission.Write);
    return res;
}

From source file:org.apache.nifi.processors.aws.s3.AbstractS3Processor.java

License:Apache License

/**
 * Create AccessControlList if appropriate properties are configured.
 *
 * @param context ProcessContext/*  ww  w.j  ava  2  s .co  m*/
 * @param flowFile FlowFile
 * @return AccessControlList or null if no ACL properties were specified
 */
protected final AccessControlList createACL(final ProcessContext context, final FlowFile flowFile) {
    // lazy-initialize ACL, as it should not be used if no properties were specified
    AccessControlList acl = null;

    final String ownerId = context.getProperty(OWNER).evaluateAttributeExpressions(flowFile).getValue();
    if (!StringUtils.isEmpty(ownerId)) {
        final Owner owner = new Owner();
        owner.setId(ownerId);
        if (acl == null) {
            acl = new AccessControlList();
        }
        acl.setOwner(owner);
    }

    for (final Grantee grantee : createGrantees(
            context.getProperty(FULL_CONTROL_USER_LIST).evaluateAttributeExpressions(flowFile).getValue())) {
        if (acl == null) {
            acl = new AccessControlList();
        }
        acl.grantPermission(grantee, Permission.FullControl);
    }

    for (final Grantee grantee : createGrantees(
            context.getProperty(READ_USER_LIST).evaluateAttributeExpressions(flowFile).getValue())) {
        if (acl == null) {
            acl = new AccessControlList();
        }
        acl.grantPermission(grantee, Permission.Read);
    }

    for (final Grantee grantee : createGrantees(
            context.getProperty(WRITE_USER_LIST).evaluateAttributeExpressions(flowFile).getValue())) {
        if (acl == null) {
            acl = new AccessControlList();
        }
        acl.grantPermission(grantee, Permission.Write);
    }

    for (final Grantee grantee : createGrantees(
            context.getProperty(READ_ACL_LIST).evaluateAttributeExpressions(flowFile).getValue())) {
        if (acl == null) {
            acl = new AccessControlList();
        }
        acl.grantPermission(grantee, Permission.ReadAcp);
    }

    for (final Grantee grantee : createGrantees(
            context.getProperty(WRITE_ACL_LIST).evaluateAttributeExpressions(flowFile).getValue())) {
        if (acl == null) {
            acl = new AccessControlList();
        }
        acl.grantPermission(grantee, Permission.WriteAcp);
    }

    return acl;
}