Search in sources :

Example 1 with GroupGrantee

use of com.qcloud.cos.model.GroupGrantee in project cos-java-sdk-v5 by tencentyun.

the class AclTest method GetAclForNewPubReadBucket.

@Test
public void GetAclForNewPubReadBucket() throws InterruptedException {
    if (!judgeUserInfoValid()) {
        return;
    }
    String aclTestBucketName = null;
    try {
        aclTestBucketName = "javasdkacltest-" + appid;
        CreateBucketRequest createBucketRequest = new CreateBucketRequest(aclTestBucketName);
        createBucketRequest.setCannedAcl(CannedAccessControlList.PublicRead);
        cosclient.createBucket(createBucketRequest);
        AccessControlList aclGet = cosclient.getBucketAcl(aclTestBucketName);
        assertEquals(aclGet.getCannedAccessControl(), CannedAccessControlList.PublicRead);
        assertNotNull(aclGet.getOwner());
        assertNotNull(aclGet.getOwner().getId());
        assertNotNull(aclGet.getOwner().getDisplayName());
        assertEquals(2, aclGet.getGrantsAsList().size());
        Grant firstGrant = aclGet.getGrantsAsList().get(0);
        assertEquals(Permission.Read.toString(), firstGrant.getPermission().toString());
        assertTrue(firstGrant.getGrantee() instanceof GroupGrantee);
        Grant secondGrant = aclGet.getGrantsAsList().get(1);
        assertEquals(Permission.FullControl.toString(), secondGrant.getPermission().toString());
        assertTrue(secondGrant.getGrantee() instanceof UinGrantee);
        // set to PublicReadWrite acl and get canned acl compare
        Thread.sleep(5000);
        cosclient.setBucketAcl(aclTestBucketName, CannedAccessControlList.PublicReadWrite);
        aclGet = cosclient.getBucketAcl(aclTestBucketName);
        assertEquals(aclGet.getCannedAccessControl(), CannedAccessControlList.PublicReadWrite);
        // set to private and get canned acl compare
        Thread.sleep(5000);
        cosclient.setBucketAcl(aclTestBucketName, CannedAccessControlList.Private);
        aclGet = cosclient.getBucketAcl(aclTestBucketName);
        assertEquals(aclGet.getCannedAccessControl(), CannedAccessControlList.Private);
    } finally {
        if (aclTestBucketName != null) {
            cosclient.deleteBucket(aclTestBucketName);
            aclTestBucketName = null;
        }
    }
}
Also used : CannedAccessControlList(com.qcloud.cos.model.CannedAccessControlList) AccessControlList(com.qcloud.cos.model.AccessControlList) UinGrantee(com.qcloud.cos.model.UinGrantee) Grant(com.qcloud.cos.model.Grant) GroupGrantee(com.qcloud.cos.model.GroupGrantee) CreateBucketRequest(com.qcloud.cos.model.CreateBucketRequest) Test(org.junit.Test)

Aggregations

AccessControlList (com.qcloud.cos.model.AccessControlList)1 CannedAccessControlList (com.qcloud.cos.model.CannedAccessControlList)1 CreateBucketRequest (com.qcloud.cos.model.CreateBucketRequest)1 Grant (com.qcloud.cos.model.Grant)1 GroupGrantee (com.qcloud.cos.model.GroupGrantee)1 UinGrantee (com.qcloud.cos.model.UinGrantee)1 Test (org.junit.Test)1