本文整理汇总了Java中com.amazonaws.services.s3.model.Permission类的典型用法代码示例。如果您正苦于以下问题:Java Permission类的具体用法?Java Permission怎么用?Java Permission使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Permission类属于com.amazonaws.services.s3.model包,在下文中一共展示了Permission类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: init
import com.amazonaws.services.s3.model.Permission; //导入依赖的package包/类
@Override
public void init(Configuration conf, String keyPrefix) {
bucketName = conf.get(keyPrefix + S3_BUCKET_NAME);
String endpoint = conf.get(keyPrefix + S3_ENDPOINT_NAME);
String key = conf.get(keyPrefix + S3_ACCESS_KEY);
String secret = conf.get(keyPrefix + S3_ACCESS_SECRET);
System.setProperty(SDKGlobalConfiguration.ACCESS_KEY_SYSTEM_PROPERTY, key);
System.setProperty(SDKGlobalConfiguration.SECRET_KEY_SYSTEM_PROPERTY, secret);
AWSCredentialsProvider provider = new SystemPropertiesCredentialsProvider();
client = new AmazonS3Client(provider);
client.setEndpoint(endpoint);
override = conf.getBoolean(keyPrefix + "override", true);
acls = new AccessControlList();
acls.grantPermission(GroupGrantee.AllUsers, Permission.FullControl);
acls.grantPermission(GroupGrantee.AllUsers, Permission.Read);
acls.grantPermission(GroupGrantee.AllUsers, Permission.Write);
}
示例2: uploadToAmazonS3
import com.amazonaws.services.s3.model.Permission; //导入依赖的package包/类
static public void uploadToAmazonS3(HttpSession session, File fileToUpload) throws S3Exception
{
try
{
AmazonS3 s3client = getS3();
String bucketName = getDownloadS3Bucket();
if(!s3client.doesBucketExist(bucketName))
SagLogger.logError(session, "Does not exist? S3 Bucket :" + bucketName);
AccessControlList acl = new AccessControlList();
acl.grantPermission(GroupGrantee.AllUsers, Permission.Read);
s3client.putObject(new PutObjectRequest(bucketName, getAPKDownloadFilePathWithFile(fileToUpload.getName()), fileToUpload).withAccessControlList(acl));
SagLogger.logInfo(session, "Finished uploading to S3");
}
catch (Exception e)
{
SagLogger.logException(session, e);
throw new S3Exception(e);
}
}
示例3: setBucketAcl
import com.amazonaws.services.s3.model.Permission; //导入依赖的package包/类
public static void setBucketAcl(String bucket_name, String email, String access)
{
System.out.format("Setting %s access for %s\n", access, email);
System.out.println("on bucket: " + bucket_name);
final AmazonS3 s3 = AmazonS3ClientBuilder.defaultClient();
try {
// get the current ACL
AccessControlList acl = s3.getBucketAcl(bucket_name);
// set access for the grantee
EmailAddressGrantee grantee = new EmailAddressGrantee(email);
Permission permission = Permission.valueOf(access);
acl.grantPermission(grantee, permission);
s3.setBucketAcl(bucket_name, acl);
} catch (AmazonServiceException e) {
System.err.println(e.getErrorMessage());
System.exit(1);
}
}
示例4: setObjectAcl
import com.amazonaws.services.s3.model.Permission; //导入依赖的package包/类
public static void setObjectAcl(String bucket_name, String object_key, String email, String access)
{
System.out.format("Setting %s access for %s\n", access, email);
System.out.println("for object: " + object_key);
System.out.println(" in bucket: " + bucket_name);
final AmazonS3 s3 = AmazonS3ClientBuilder.defaultClient();
try {
// get the current ACL
AccessControlList acl = s3.getObjectAcl(bucket_name, object_key);
// set access for the grantee
EmailAddressGrantee grantee = new EmailAddressGrantee(email);
Permission permission = Permission.valueOf(access);
acl.grantPermission(grantee, permission);
s3.setObjectAcl(bucket_name, object_key, acl);
} catch (AmazonServiceException e) {
System.err.println(e.getErrorMessage());
System.exit(1);
}
}
示例5: testPut
import com.amazonaws.services.s3.model.Permission; //导入依赖的package包/类
@Test
public void testPut() {
ModelBucket bucket = getService(ModelBucket.class);
InputStream stream = new ByteArrayInputStream("file content".getBytes());
ArgumentCaptor<PutObjectRequest> requestCaptor = ArgumentCaptor.forClass(PutObjectRequest.class);
PutObjectResult expected = new PutObjectResult();
when(amazonS3Client.putObject(requestCaptor.capture())).thenReturn(expected);
assertEquals(expected, bucket.put("path", stream, 12L));
PutObjectRequest request = requestCaptor.getValue();
assertEquals("model-bucket", request.getBucketName());
assertEquals("path", request.getKey());
assertEquals(stream, request.getInputStream());
assertEquals(12L, request.getMetadata().getContentLength());
List<Grant> grants = request.getAccessControlList().getGrantsAsList();
assertEquals(1, grants.size());
assertEquals(GroupGrantee.AllUsers, grants.get(0).getGrantee());
assertEquals(Permission.Read, grants.get(0).getPermission());
}
示例6: hasFullControlPermission
import com.amazonaws.services.s3.model.Permission; //导入依赖的package包/类
@Override
public boolean hasFullControlPermission(final String bucketName)
throws AmazonClientException, AmazonServiceException,
AmazonS3Exception {
LOGGER.info("Checking full controll permission on bucket..");
boolean hasFullControl = false;
final AccessControlList acl = getBucketAccessControlList(bucketName);
final List<Grant> grantList = acl.getGrantsAsList();
for (final Grant grant : grantList) {
if(Permission.FullControl.equals(grant.getPermission())){
hasFullControl = true;
LOGGER.info("Permissions validated, hasFullControl: {}", hasFullControl);
break;
}
}
return hasFullControl;
}
示例7: checkBucketPermission
import com.amazonaws.services.s3.model.Permission; //导入依赖的package包/类
@Override
public boolean checkBucketPermission(final String bucketName, final Permission permission)
throws AmazonClientException, AmazonServiceException, AmazonS3Exception {
LOGGER.info("Checking bucket permission..");
boolean hasPermission = false;
final AccessControlList acl = getBucketAccessControlList(bucketName);
final List<Grant> grantList = acl.getGrantsAsList();
for (final Grant grant : grantList) {
if(permission.equals(grant.getPermission())){
hasPermission = true;
LOGGER.info("Permissions validated,hasPermission: {}",hasPermission);
break;
}
}
return hasPermission;
}
示例8: checkObjectPermission
import com.amazonaws.services.s3.model.Permission; //导入依赖的package包/类
@Override
public boolean checkObjectPermission(final String bucketName, final String key, final Permission permission)
throws AmazonClientException, AmazonServiceException, AmazonS3Exception {
LOGGER.info("Checking object permission..");
boolean hasPermission = false;
final AccessControlList objectAcl = s3client.getObjectAcl(bucketName, key);
final List<Grant> grantList = objectAcl.getGrantsAsList();
for (final Grant grant : grantList) {
if(permission.equals(grant.getPermission())){
hasPermission = true;
LOGGER.info("Permissions validated,hasPermission: {}",hasPermission);
break;
}
}
return hasPermission;
}
示例9: testGetBucketPermissions
import com.amazonaws.services.s3.model.Permission; //导入依赖的package包/类
/**
* Test method for {@link com.github.abhinavmishra14.aws.s3.service.AwsS3IamService#getBucketPermissions(java.lang.String)}.
*
* @throws Exception the exception
*/
@Test
public void testGetBucketPermissions() throws Exception{
//Create bucket for test
awsS3IamService.createBucket(AWS_S3_BUCKET);
List<Grant> bucketAcl = awsS3IamService.getBucketPermissions(AWS_S3_BUCKET);
assertEquals(true, Permission.FullControl.equals(bucketAcl.get(0).getPermission()));
}
示例10: testUpdateBlobXmlAcls
import com.amazonaws.services.s3.model.Permission; //导入依赖的package包/类
@Test
public void testUpdateBlobXmlAcls() throws Exception {
assumeTrue(!Quirks.NO_BLOB_ACCESS_CONTROL.contains(blobStoreType));
String blobName = "testUpdateBlobXmlAcls-blob";
ObjectMetadata metadata = new ObjectMetadata();
metadata.setContentLength(BYTE_SOURCE.size());
client.putObject(containerName, blobName, BYTE_SOURCE.openStream(),
metadata);
AccessControlList acl = client.getObjectAcl(containerName, blobName);
acl.grantPermission(GroupGrantee.AllUsers, Permission.Read);
client.setObjectAcl(containerName, blobName, acl);
assertThat(client.getObjectAcl(containerName, blobName)).isEqualTo(acl);
acl.revokeAllPermissions(GroupGrantee.AllUsers);
client.setObjectAcl(containerName, blobName, acl);
assertThat(client.getObjectAcl(containerName, blobName)).isEqualTo(acl);
acl.grantPermission(GroupGrantee.AllUsers, Permission.Write);
try {
client.setObjectAcl(containerName, blobName, acl);
Fail.failBecauseExceptionWasNotThrown(AmazonS3Exception.class);
} catch (AmazonS3Exception e) {
assertThat(e.getErrorCode()).isEqualTo("NotImplemented");
}
}
示例11: isPublicEntity
import com.amazonaws.services.s3.model.Permission; //导入依赖的package包/类
@Override
public boolean isPublicEntity(String bucketName, String keyName) {
LOG.info("Gets the AccessControlList (ACL) for the specified object "
+ keyName + " in the specified bucket " + bucketName);
final String GROUPS_USERS = "http://acs.amazonaws.com/groups/global/AllUsers";
try {
AccessControlList accessControlList = amazonS3Client.getObjectAcl(bucketName, keyName);
for (Iterator<Grant> iterator = accessControlList.getGrants().iterator(); iterator.hasNext();) {
Grant grant = iterator.next();
if (grant.getPermission().equals(Permission.Read)
&& grant.getGrantee().getIdentifier().equals(GROUPS_USERS)) {
return true;
}
}
} catch (AmazonServiceException ase) {
LOG.warn(ase.getMessage(), ase);
} catch (AmazonClientException ace) {
LOG.warn(ace.getMessage(), ace);
}
return false;
}
示例12: addAclHeaders
import com.amazonaws.services.s3.model.Permission; //导入依赖的package包/类
/**
* Sets the access control headers for the request given.
*/
private static void addAclHeaders(Request<? extends AmazonWebServiceRequest> request, AccessControlList acl) {
List<Grant> grants = acl.getGrantsAsList();
Map<Permission, Collection<Grantee>> grantsByPermission = new HashMap<Permission, Collection<Grantee>>();
for ( Grant grant : grants ) {
if ( !grantsByPermission.containsKey(grant.getPermission()) ) {
grantsByPermission.put(grant.getPermission(), new LinkedList<Grantee>());
}
grantsByPermission.get(grant.getPermission()).add(grant.getGrantee());
}
for ( Permission permission : Permission.values() ) {
if ( grantsByPermission.containsKey(permission) ) {
Collection<Grantee> grantees = grantsByPermission.get(permission);
boolean seenOne = false;
StringBuilder granteeString = new StringBuilder();
for ( Grantee grantee : grantees ) {
if ( !seenOne )
seenOne = true;
else
granteeString.append(", ");
granteeString.append(grantee.getTypeIdentifier()).append("=").append("\"")
.append(grantee.getIdentifier()).append("\"");
}
request.addHeader(permission.getHeaderName(), granteeString.toString());
}
}
}
示例13: put
import com.amazonaws.services.s3.model.Permission; //导入依赖的package包/类
public Object put(String path, InputStream fileInputStream, Long contentLenght) {
if (contentLenght == null || contentLenght <= 0) {
FindContentLengthResult result = findContentLength(fileInputStream);
contentLenght = result.getContentLength();
fileInputStream = result.getFileInputStream();
}
ObjectMetadata meta = new ObjectMetadata();
meta.setContentLength(contentLenght);
AccessControlList acl = new AccessControlList();
acl.grantPermission(GroupGrantee.AllUsers, Permission.Read);
return amazonS3Client.putObject(new PutObjectRequest(getBucketName(), path, fileInputStream, meta).withAccessControlList(acl));
}
示例14: testPutWithoutContentLenght
import com.amazonaws.services.s3.model.Permission; //导入依赖的package包/类
@Test
public void testPutWithoutContentLenght() {
ModelBucket bucket = getService(ModelBucket.class);
InputStream stream = new ByteArrayInputStream("file content".getBytes());
ArgumentCaptor<PutObjectRequest> requestCaptor = ArgumentCaptor.forClass(PutObjectRequest.class);
PutObjectResult expected = new PutObjectResult();
when(amazonS3Client.putObject(requestCaptor.capture())).thenReturn(expected);
assertEquals(expected, bucket.put("path", stream, null));
PutObjectRequest request = requestCaptor.getValue();
Scanner scanner = new Scanner(request.getInputStream());
assertEquals("model-bucket", request.getBucketName());
assertEquals("path", request.getKey());
assertEquals("file content", scanner.useDelimiter("\\A").next());
assertEquals(12L, request.getMetadata().getContentLength());
List<Grant> grants = request.getAccessControlList().getGrantsAsList();
assertEquals(1, grants.size());
assertEquals(GroupGrantee.AllUsers, grants.get(0).getGrantee());
assertEquals(Permission.Read, grants.get(0).getPermission());
scanner.close();
}
示例15: testCheckBucketPermission
import com.amazonaws.services.s3.model.Permission; //导入依赖的package包/类
/**
* Test method for {@link com.github.abhinavmishra14.aws.s3.service.AwsS3IamService#checkBucketPermission(java.lang.String,com.amazonaws.services.s3.model.Permission)}.
*
* @throws Exception the exception
*/
@Test
public void testCheckBucketPermission() throws Exception {
awsS3IamService.createBucket(AWS_S3_BUCKET);//create bucket for test
boolean checkPermission = awsS3IamService.checkBucketPermission(AWS_S3_BUCKET,Permission.FullControl);
assertEquals(true, checkPermission);
}