Example usage for com.amazonaws.services.s3.model GroupGrantee parseGroupGrantee

List of usage examples for com.amazonaws.services.s3.model GroupGrantee parseGroupGrantee

Introduction

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

Prototype

public static GroupGrantee parseGroupGrantee(String groupUri) 

Source Link

Document

Gets the GroupGrantee enumeration value with the specified Amazon S3 group URI (eg.

Usage

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);
        }// w  ww .  j  av  a  2s  .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:com.wowza.wms.plugin.s3upload.ModuleS3Upload.java

License:Open Source License

public void onAppStart(IApplicationInstance appInstance) {
    logger = WMSLoggerFactory.getLoggerObj(appInstance);
    this.appInstance = appInstance;

    try {/*  ww w . j  a  v  a  2 s . c o m*/
        WMSProperties props = appInstance.getProperties();
        accessKey = props.getPropertyStr("s3UploadAccessKey", accessKey);
        secretKey = props.getPropertyStr("s3UploadSecretKey", secretKey);
        bucketName = props.getPropertyStr("s3UploadBucketName", bucketName);
        endpoint = props.getPropertyStr("s3UploadEndpoint", endpoint);
        resumeUploads = props.getPropertyBoolean("s3UploadResumeUploads", resumeUploads);
        deleteOriginalFiles = props.getPropertyBoolean("s3UploadDeletOriginalFiles", deleteOriginalFiles);
        // fix typo in property name
        deleteOriginalFiles = props.getPropertyBoolean("s3UploadDeleteOriginalFiles", deleteOriginalFiles);

        // This value should be the URI representation of the "Group Grantee" found here http://docs.aws.amazon.com/AmazonS3/latest/dev/acl-overview.html under "Amazon S3 Predefined Groups"
        aclGroupGranteeUri = props.getPropertyStr("s3UploadACLGroupGranteeUri", aclGroupGranteeUri);
        // This should be a string that represents the level of permissions we want to grant to the "Group Grantee" access to the file to be uploaded
        aclPermissionRule = props.getPropertyStr("s3UploadACLPermissionRule", aclPermissionRule);

        // With the passed property, check if it maps to a specified GroupGrantee
        GroupGrantee grantee = GroupGrantee.parseGroupGrantee(aclGroupGranteeUri);
        // In order for the parsing to work correctly, we will go ahead and force uppercase on the string passed
        Permission permission = Permission.parsePermission(aclPermissionRule.toUpperCase());

        // If we have properties for specifying permisions on the file upload, create the AccessControlList object and set the Grantee and Permissions
        if (grantee != null && permission != null) {
            acl = new AccessControlList();
            acl.grantPermission(grantee, permission);
        }

        if (StringUtils.isEmpty(accessKey) || StringUtils.isEmpty(secretKey)) {
            logger.warn(
                    MODULE_NAME + ".onAppStart: [" + appInstance.getContextStr() + "] missing S3 credentials",
                    WMSLoggerIDs.CAT_application, WMSLoggerIDs.EVT_comment);
            return;
        }

        AmazonS3 s3Client = new AmazonS3Client(new BasicAWSCredentials(accessKey, secretKey));

        if (!StringUtils.isEmpty(endpoint))
            s3Client.setEndpoint(endpoint);

        if (!StringUtils.isEmpty(bucketName)) {
            boolean hasBucket = false;
            List<Bucket> buckets = s3Client.listBuckets();
            for (Bucket bucket : buckets) {
                if (bucket.getName().equals(bucketName)) {
                    hasBucket = true;
                    break;
                }
            }
            if (!hasBucket) {
                logger.warn(MODULE_NAME + ".onAppStart: [" + appInstance.getContextStr()
                        + "] missing S3 bucket: " + bucketName, WMSLoggerIDs.CAT_application,
                        WMSLoggerIDs.EVT_comment);
                return;
            }
        }

        logger.info(MODULE_NAME + ".onAppStart [" + appInstance.getContextStr() + "] S3 Bucket Name: "
                + bucketName + ", Resume Uploads: " + resumeUploads + ", Delete Original Files: "
                + deleteOriginalFiles, WMSLoggerIDs.CAT_application, WMSLoggerIDs.EVT_comment);
        transferManager = new TransferManager(s3Client);
        resumeUploads();

        appInstance.addMediaWriterListener(new WriteListener());
    } catch (AmazonS3Exception ase) {
        logger.error(MODULE_NAME + ".onAppStart [" + appInstance.getContextStr() + "] AmazonS3Exception: "
                + ase.getMessage());
    } catch (Exception e) {
        logger.error(
                MODULE_NAME + ".onAppStart [" + appInstance.getContextStr() + "] exception: " + e.getMessage(),
                e);
    } catch (Throwable t) {
        logger.error(MODULE_NAME + ".onAppStart [" + appInstance.getContextStr() + "] throwable exception: "
                + t.getMessage(), t);
    }
}

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