Example usage for com.amazonaws.services.s3.model CanonicalGrantee CanonicalGrantee

List of usage examples for com.amazonaws.services.s3.model CanonicalGrantee CanonicalGrantee

Introduction

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

Prototype

public CanonicalGrantee(String identifier) 

Source Link

Document

Constructs a new CanonicalGrantee object with the given canonical ID.

Usage

From source file:cloudExplorer.Acl.java

License:Open Source License

void setAccess(String id, int what, String access_key, String secret_key, String endpoint, String bucket) {
    try {/*from ww  w  .  j  a v a 2s .c  o m*/

        Collection<Grant> grantCollection = new ArrayList<Grant>();
        AWSCredentials credentials = new BasicAWSCredentials(access_key, secret_key);
        AmazonS3 s3Client = new AmazonS3Client(credentials,
                new ClientConfiguration().withSignerOverride("S3SignerType"));
        s3Client.setEndpoint(endpoint);
        AccessControlList bucketAcl = s3Client.getBucketAcl(bucket);
        Grant grant = null;
        if (what == 0) {

            grant = new Grant(new CanonicalGrantee(id), Permission.Read);
            grantCollection.add(grant);
        }

        if (what == 1) {
            grant = new Grant(new CanonicalGrantee(id), Permission.FullControl);
            grantCollection.add(grant);
        }

        if (what == 3) {
            bucketAcl.getGrants().clear();
        }

        bucketAcl.getGrants().addAll(grantCollection);
        s3Client.setBucketAcl(bucket, bucketAcl);

    } catch (AmazonServiceException ase) {
        NewJFrame.jTextArea1.append("\n\nError: " + ase.getErrorMessage());
    }
}

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

License:Open Source License

public static AccessControlList s3AclFromSyncAcl(SyncAcl syncAcl, boolean ignoreInvalid) {
    AccessControlList s3Acl = new AccessControlList();

    s3Acl.setOwner(new Owner(syncAcl.getOwner(), syncAcl.getOwner()));

    for (String user : syncAcl.getUserGrants().keySet()) {
        Grantee grantee = new CanonicalGrantee(user);
        for (String permission : syncAcl.getUserGrants().get(user)) {
            Permission perm = getS3Permission(permission, ignoreInvalid);
            if (perm != null)
                s3Acl.grantPermission(grantee, perm);
        }//from  w  ww  . j  a  v  a 2  s.  com
    }

    for (String group : syncAcl.getGroupGrants().keySet()) {
        Grantee grantee = GroupGrantee.parseGroupGrantee(group);
        if (grantee == null) {
            if (ignoreInvalid)
                log.warn("{} is not a valid S3 group", group);
            else
                throw new RuntimeException(group + " is not a valid S3 group");
        }
        for (String permission : syncAcl.getGroupGrants().get(group)) {
            Permission perm = getS3Permission(permission, ignoreInvalid);
            if (perm != null)
                s3Acl.grantPermission(grantee, perm);
        }
    }

    return s3Acl;
}

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 w  w.jav a  2 s.  com
}

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

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

License:Apache License

protected Grantee createGrantee(final String value) {
    if (StringUtils.isEmpty(value)) {
        return null;
    }// w w  w . j a v  a  2s  .  c om

    if (value.contains("@")) {
        return new EmailAddressGrantee(value);
    } else {
        return new CanonicalGrantee(value);
    }
}

From source file:org.springframework.integration.aws.s3.core.AmazonS3OperationsImpl.java

License:Apache License

/**
 * Gets the {@link AccessControlList} from the given {@link AmazonS3ObjectACL} 
 * @param acl/*  ww w .j  a v  a 2 s  . co  m*/
 * @return 
 */
private AccessControlList getAccessControlList(String bucketName, String key, AmazonS3ObjectACL acl) {
    AccessControlList accessControlList = null;
    if (acl != null) {
        if (!acl.getGrants().isEmpty()) {
            accessControlList = client.getObjectAcl(bucketName, key);
            for (ObjectGrant objGrant : acl.getGrants()) {
                Grantee grantee = objGrant.getGrantee();
                com.amazonaws.services.s3.model.Grantee awsGrantee;
                if (grantee.getGranteeType() == GranteeType.CANONICAL_GRANTEE_TYPE) {
                    awsGrantee = new CanonicalGrantee(grantee.getIdentifier());
                } else if (grantee.getGranteeType() == GranteeType.EMAIL_GRANTEE_TYPE) {
                    awsGrantee = new EmailAddressGrantee(grantee.getIdentifier());
                } else {
                    awsGrantee = GroupGrantee.parseGroupGrantee(grantee.getIdentifier());
                    if (awsGrantee == null) {
                        logger.warn("Group grantee with identifier: \"" + grantee.getIdentifier()
                                + "\" not found. skipping this grant");
                        continue;
                    }
                }
                ObjectPermissions perm = objGrant.getPermission();
                Permission permission;
                if (perm == ObjectPermissions.READ) {
                    permission = Permission.Read;
                } else if (perm == ObjectPermissions.READ_ACP) {
                    permission = Permission.ReadAcp;
                } else
                    permission = Permission.WriteAcp;

                accessControlList.grantPermission(awsGrantee, permission);
            }
        }
    }
    return accessControlList;
}