Example usage for com.amazonaws.services.s3.model AccessControlList getOwner

List of usage examples for com.amazonaws.services.s3.model AccessControlList getOwner

Introduction

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

Prototype

public Owner getOwner() 

Source Link

Document

Gets the owner of the AccessControlList .

Usage

From source file:com.emc.ecs.sync.util.AwsS3Util.java

License:Open Source License

public static SyncAcl syncAclFromS3Acl(AccessControlList s3Acl) {
    SyncAcl syncAcl = new SyncAcl();
    syncAcl.setOwner(s3Acl.getOwner().getId());
    for (Grant grant : s3Acl.getGrantsAsList()) {
        Grantee grantee = grant.getGrantee();
        if (grantee instanceof GroupGrantee || grantee.getTypeIdentifier().equals(AwsS3Util.ACL_GROUP_TYPE))
            syncAcl.addGroupGrant(grantee.getIdentifier(), grant.getPermission().toString());
        else if (grantee instanceof CanonicalGrantee
                || grantee.getTypeIdentifier().equals(AwsS3Util.ACL_CANONICAL_USER_TYPE))
            syncAcl.addUserGrant(grantee.getIdentifier(), grant.getPermission().toString());
    }//from  w ww.ja v  a  2  s .co  m
    return syncAcl;
}

From source file:com.eucalyptus.images.ImageManifests.java

License:Open Source License

static boolean verifyBucketAcl(String bucketName) {
    Context ctx = Contexts.lookup();
    try {/*from   ww w  .j a  v a2s  . c om*/
        EucaS3Client s3Client = EucaS3ClientFactory.getEucaS3Client(Accounts.lookupSystemAdmin());
        AccessControlList acl = s3Client.getBucketAcl(bucketName);
        String ownerId = acl.getOwner().getId();
        return ctx.getUserFullName().getAccountNumber().equals(ownerId)
                || ctx.getUserFullName().getUserId().equals(ownerId);
    } catch (Exception ex) {
        LOG.trace(ex, ex);
        LOG.debug("Failed verifying bucket acl for bucket " + bucketName, ex);
    }
    return false;
}

From source file:com.eucalyptus.imaging.manifest.DownloadManifestFactory.java

License:Open Source License

private static boolean checkManifestsBucket(EucaS3Client s3Client) {
    try {//from   w w  w  . ja  va  2  s .c o m
        //Since we're using the eucalyptus admin, which has access to all buckets, check the bucket owner explicitly
        AccessControlList acl = s3Client.getBucketAcl(DOWNLOAD_MANIFEST_BUCKET_NAME);
        if (!acl.getOwner().getId().equals(getDownloadManifestS3User().getAccount().getCanonicalId())) {
            //Bucket exists, but is owned by another account
            LOG.warn("Found existence of download manifest bucket: " + DOWNLOAD_MANIFEST_BUCKET_NAME
                    + " but it is owned by another account: " + acl.getOwner().getId() + ", "
                    + acl.getOwner().getDisplayName());
            return false;
        }

        BucketLifecycleConfiguration config = s3Client
                .getBucketLifecycleConfiguration(DOWNLOAD_MANIFEST_BUCKET_NAME);

        return (config.getRules() != null && config.getRules().size() == 1
                && config.getRules().get(0).getExpirationInDays() == 1
                && "enabled".equalsIgnoreCase(config.getRules().get(0).getStatus())
                && DOWNLOAD_MANIFEST_PREFIX.equals(config.getRules().get(0).getPrefix()));
    } catch (AmazonServiceException e) {
        //Expected possible path if doesn't exist.
        return false;
    } catch (Exception e) {
        LOG.warn("Unexpected error checking for download manifest bucket", e);
        return false;
    }
}

From source file:io.druid.storage.s3.S3Utils.java

License:Apache License

static AccessControlList grantFullControlToBucketOwner(AmazonS3 s3Client, String bucket) {
    final AccessControlList acl = s3Client.getBucketAcl(bucket);
    acl.grantAllPermissions(new Grant(new CanonicalGrantee(acl.getOwner().getId()), Permission.FullControl));
    return acl;//from w ww  .j ava2  s.  c  om
}

From source file:org.apache.druid.storage.s3.S3Utils.java

License:Apache License

static AccessControlList grantFullControlToBucketOwner(ServerSideEncryptingAmazonS3 s3Client, String bucket) {
    final AccessControlList acl = s3Client.getBucketAcl(bucket);
    acl.grantAllPermissions(new Grant(new CanonicalGrantee(acl.getOwner().getId()), Permission.FullControl));
    return acl;/*from  ww  w.j  av  a  2s.  co m*/
}

From source file:org.exem.flamingo.web.filesystem.s3.S3BrowserController.java

License:Apache License

private Collection<S3Grant> generateGrants(AccessControlList acl) {
    List<Grant> grants = acl.getGrantsAsList();
    Map<String, S3Grant> s3Grants = new HashMap<>();
    String name = "";
    S3Grant grant;// w w  w .  ja  v a 2  s .c o  m

    for (Grant g : grants) {
        if (S3Constansts.CANONICAL_GRANTEE_TYPE_ID.equals(g.getGrantee().getTypeIdentifier())) {
            CanonicalGrantee grantee = (CanonicalGrantee) g.getGrantee();
            name = grantee.getDisplayName();
            if (StringUtils.isEmpty(name) && acl.getOwner().getId().equals(grantee.getIdentifier())) {
                name = acl.getOwner().getDisplayName();
            }
        } else if (S3Constansts.GROUP_GRANTEE_TYPE_ID.equals(g.getGrantee().getTypeIdentifier())) {
            GroupGrantee groupGrantee = (GroupGrantee) g.getGrantee();
            name = groupGrantee.name();
        }

        if (s3Grants.containsKey(name)) {
            grant = s3Grants.get(name);
        } else {
            grant = new S3Grant();
            grant.setName(name);
        }

        grant.setPermission(g.getPermission().name());
        s3Grants.put(name, grant);
    }
    return s3Grants.values();
}

From source file:org.exem.flamingo.web.filesystem.s3.S3BrowserServiceImpl.java

License:Apache License

@Override
public S3ObjectInfo getObjectProperty(String bucketName, String key) {
    ObjectMetadata metadata = this.s3.getObjectMetadata(bucketName, key);

    S3ObjectInfo object = new S3ObjectInfo();
    object.setBucketName(bucketName);//from ww  w  .j a v  a  2s . com
    object.setKey(key);
    object.setName(getName(key));
    object.setLastModified(metadata.getLastModified());
    object.setContentType(metadata.getContentType());
    object.seteTag(metadata.getETag());

    URL url = this.s3.getUrl(bucketName, key);
    object.setUri(url.toString());

    AccessControlList acl = this.s3.getObjectAcl(bucketName, key);
    object.setOwner(acl.getOwner().getDisplayName());

    return object;
}