Example usage for com.amazonaws.auth BasicAWSCredentials BasicAWSCredentials

List of usage examples for com.amazonaws.auth BasicAWSCredentials BasicAWSCredentials

Introduction

In this page you can find the example usage for com.amazonaws.auth BasicAWSCredentials BasicAWSCredentials.

Prototype

public BasicAWSCredentials(String accessKey, String secretKey) 

Source Link

Document

Constructs a new BasicAWSCredentials object, with the specified AWS access key and AWS secret key.

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   w w  w  . j  a v  a2s .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:cloudExplorer.Acl.java

License:Open Source License

void setACLpublic(String object, String access_key, String secret_key, String endpoint, String bucket) {
    try {/*  w  w w .j a v  a  2 s. com*/
        AWSCredentials credentials = new BasicAWSCredentials(access_key, secret_key);
        AmazonS3 s3Client = new AmazonS3Client(credentials,
                new ClientConfiguration().withSignerOverride("S3SignerType"));
        s3Client.setEndpoint(endpoint);
        s3Client.setObjectAcl(bucket, object, CannedAccessControlList.PublicRead);
    } catch (Exception setACLpublic) {
        mainFrame.jTextArea1.append("\nException occurred in ACL");
    }
}

From source file:cloudExplorer.Acl.java

License:Open Source License

void setACLprivate(String object, String access_key, String secret_key, String endpoint, String bucket) {
    try {//w  w  w.ja va  2  s  .c  o m
        AWSCredentials credentials = new BasicAWSCredentials(access_key, secret_key);
        AmazonS3 s3Client = new AmazonS3Client(credentials,
                new ClientConfiguration().withSignerOverride("S3SignerType"));
        s3Client.setEndpoint(endpoint);
        s3Client.setObjectAcl(bucket, object, CannedAccessControlList.Private);
    } catch (Exception setACLprivate) {
        mainFrame.jTextArea1.append("\nException occurred in setACLprivate");
    }
}

From source file:cloudExplorer.Acl.java

License:Open Source License

String viewACL(String object, String access_key, String secret_key, String endpoint, String bucket) {
    String message = null;//from   w  ww  .j a  v a2  s  .  c o  m
    try {
        AWSCredentials credentials = new BasicAWSCredentials(access_key, secret_key);
        AmazonS3 s3Client = new AmazonS3Client(credentials,
                new ClientConfiguration().withSignerOverride("S3SignerType"));
        s3Client.setEndpoint(endpoint);
        message = s3Client.getObjectAcl(bucket, object).toString();
    } catch (Exception viewACL) {
        mainFrame.jTextArea1.append("\nException occurred in viewACL");
    }

    return object + ":     " + message;
}

From source file:cloudExplorer.Acl.java

License:Open Source License

void setBUCKETwebsite(String object, String access_key, String secret_key, String endpoint, String bucket) {
    try {//from   w w w .j  a  va 2s .c  om
        AWSCredentials credentials = new BasicAWSCredentials(access_key, secret_key);
        AmazonS3 s3Client = new AmazonS3Client(credentials,
                new ClientConfiguration().withSignerOverride("S3SignerType"));
        s3Client.setEndpoint(endpoint);
        BucketWebsiteConfiguration bucketWebsiteConfiguration = s3Client.getBucketWebsiteConfiguration(bucket);
        s3Client.setBucketAcl(bucket, CannedAccessControlList.PublicRead);
        s3Client.setBucketWebsiteConfiguration(bucket,
                new BucketWebsiteConfiguration("index.html", "error.html"));
    } catch (Exception setACLpublic) {
        mainFrame.jTextArea1.append("\nException occurred in ACL");
    }
}

From source file:cloudExplorer.Acl.java

License:Open Source License

void removeBUCKETwebsite(String object, String access_key, String secret_key, String endpoint, String bucket) {
    try {/*from ww  w .j a  v  a  2s. c om*/
        AWSCredentials credentials = new BasicAWSCredentials(access_key, secret_key);
        AmazonS3 s3Client = new AmazonS3Client(credentials,
                new ClientConfiguration().withSignerOverride("S3SignerType"));
        s3Client.setEndpoint(endpoint);
        s3Client.deleteBucketWebsiteConfiguration(bucket);
    } catch (Exception removeBUCKETwebsite) {
        mainFrame.jTextArea1.append("\nException occurred in ACL");
    }
}

From source file:cloudExplorer.Acl.java

License:Open Source License

String setACLurl(String object, String access_key, String secret_key, String endpoint, String bucket) {
    String URL = null;//from  w  w w.  j a va 2s  . c  o  m
    try {
        AWSCredentials credentials = new BasicAWSCredentials(access_key, secret_key);
        AmazonS3 s3Client = new AmazonS3Client(credentials,
                new ClientConfiguration().withSignerOverride("S3SignerType"));
        s3Client.setEndpoint(endpoint);
        java.util.Date expiration = new java.util.Date();
        long milliSeconds = expiration.getTime();
        milliSeconds += 1000 * 60 * 1000; // Add 1 hour.
        expiration.setTime(milliSeconds);
        GeneratePresignedUrlRequest generatePresignedUrlRequest = new GeneratePresignedUrlRequest(bucket,
                object);
        generatePresignedUrlRequest.setMethod(HttpMethod.GET);
        generatePresignedUrlRequest.setExpiration(expiration);
        URL url = s3Client.generatePresignedUrl(generatePresignedUrlRequest);
        URL = ("Pre-Signed URL = " + url.toString());
        StringSelection stringSelection = new StringSelection(url.toString());
        Clipboard clpbrd = Toolkit.getDefaultToolkit().getSystemClipboard();
        clpbrd.setContents(stringSelection, null);
    } catch (Exception setACLpublic) {
        mainFrame.jTextArea1.append("\nException occured in ACL");
    }
    return URL;
}

From source file:cloudExplorer.BucketClass.java

License:Open Source License

Boolean VersioningStatus(String access_key, String secret_key, String bucket, String endpoint, String region,
        Boolean enable) {//  w w  w  .  j  av  a2  s  .c  o m
    String message = null;
    boolean result = false;
    AWSCredentials credentials = new BasicAWSCredentials(access_key, secret_key);
    AmazonS3 s3Client = new AmazonS3Client(credentials,
            new ClientConfiguration().withSignerOverride("S3SignerType"));
    s3Client.setEndpoint(endpoint);
    try {
        message = s3Client.getBucketVersioningConfiguration(bucket).getStatus().toString();
        if (message.contains("Enabled") || message.contains("Suspended")) {
            result = true;
        } else {
            result = false;
        }
    } catch (Exception versioning) {
    }

    return result;
}

From source file:cloudExplorer.BucketClass.java

License:Open Source License

Boolean LifeCycleStatus(String access_key, String secret_key, String bucket, String endpoint, String region,
        Boolean enable) {/*from ww w  . j  a  v  a2 s .  co m*/
    String message = null;
    boolean result = false;
    AWSCredentials credentials = new BasicAWSCredentials(access_key, secret_key);
    AmazonS3 s3Client = new AmazonS3Client(credentials,
            new ClientConfiguration().withSignerOverride("S3SignerType"));
    s3Client.setEndpoint(endpoint);
    try {
        message = s3Client.getBucketLifecycleConfiguration(bucket).getRules().toString();
        if (message == null) {
            result = false;
        } else {
            result = true;
        }
    } catch (Exception lifecyclestatus) {
    }

    return result;
}

From source file:cloudExplorer.BucketClass.java

License:Open Source License

String controlVersioning(String access_key, String secret_key, String bucket, String endpoint, String region,
        Boolean enable) {/* www  . ja v a  2s  .com*/

    String message = null;
    AWSCredentials credentials = new BasicAWSCredentials(access_key, secret_key);
    AmazonS3 s3Client = new AmazonS3Client(credentials,
            new ClientConfiguration().withSignerOverride("S3SignerType"));
    s3Client.setEndpoint(endpoint);
    try {
        SetBucketVersioningConfigurationRequest request;
        if (enable) {
            request = new SetBucketVersioningConfigurationRequest(bucket,
                    new BucketVersioningConfiguration(BucketVersioningConfiguration.ENABLED));
        } else {
            request = new SetBucketVersioningConfigurationRequest(bucket,
                    new BucketVersioningConfiguration(BucketVersioningConfiguration.SUSPENDED));
        }
        s3Client.setBucketVersioningConfiguration(request);
        message = "\nBucket Versioning is:" + request.getVersioningConfiguration().getStatus();
    } catch (Exception versioning) {
        message = "\n" + versioning.getMessage();
    }
    if (message == null) {
        message = "\nVersioning failed.";
    }
    return message;

}