Example usage for com.amazonaws.services.s3 AmazonS3Client getS3AccountOwner

List of usage examples for com.amazonaws.services.s3 AmazonS3Client getS3AccountOwner

Introduction

In this page you can find the example usage for com.amazonaws.services.s3 AmazonS3Client getS3AccountOwner.

Prototype

@Override
    public Owner getS3AccountOwner() throws SdkClientException, AmazonServiceException 

Source Link

Usage

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   w w w .j a v  a2 s . 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;
        }
    }
}