当前位置: 首页>>代码示例>>Java>>正文


Java Permission类代码示例

本文整理汇总了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);
}
 
开发者ID:XiaoMi,项目名称:galaxy-fds-migration-tool,代码行数:19,代码来源:S3Source.java

示例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);
	}
}
 
开发者ID:benetech,项目名称:Secure-App-Generator,代码行数:22,代码来源:AmazonS3Utils.java

示例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);
    }
}
 
开发者ID:awsdocs,项目名称:aws-doc-sdk-examples,代码行数:20,代码来源:SetAcl.java

示例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);
    }
}
 
开发者ID:awsdocs,项目名称:aws-doc-sdk-examples,代码行数:21,代码来源:SetAcl.java

示例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());
}
 
开发者ID:coding4people,项目名称:mosquito-report-api,代码行数:27,代码来源:BucketTest.java

示例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;
}
 
开发者ID:abhinavmishra14,项目名称:aws-s3-utils,代码行数:18,代码来源:AwsS3IamServiceImpl.java

示例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;
}
 
开发者ID:abhinavmishra14,项目名称:aws-s3-utils,代码行数:17,代码来源:AwsS3IamServiceImpl.java

示例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;
}
 
开发者ID:abhinavmishra14,项目名称:aws-s3-utils,代码行数:17,代码来源:AwsS3IamServiceImpl.java

示例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()));
}
 
开发者ID:abhinavmishra14,项目名称:aws-s3-utils,代码行数:13,代码来源:AwsS3IamServiceTest.java

示例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");
    }
}
 
开发者ID:gaul,项目名称:s3proxy,代码行数:27,代码来源:AwsSdkTest.java

示例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;
}
 
开发者ID:dgks0n,项目名称:milton-aws,代码行数:23,代码来源:AmazonS3ManagerImpl.java

示例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());
        }
    }
}
 
开发者ID:IBM,项目名称:ibm-cos-sdk-java,代码行数:30,代码来源:AmazonS3Client.java

示例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));
}
 
开发者ID:coding4people,项目名称:mosquito-report-api,代码行数:16,代码来源:Bucket.java

示例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();
}
 
开发者ID:coding4people,项目名称:mosquito-report-api,代码行数:30,代码来源:BucketTest.java

示例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);
}
 
开发者ID:abhinavmishra14,项目名称:aws-s3-utils,代码行数:12,代码来源:AwsS3IamServiceTest.java


注:本文中的com.amazonaws.services.s3.model.Permission类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。