• Object Storage Service

obs
  1. Help Center
  2. Object Storage Service
  3. Developer Guide (Android SDK)
  4. Object Management
  5. Managing Object ACLs

Managing Object ACLs

Object ACLs, similar to bucket ACLs, support pre-defined access control policies and direct configuration. For details, see Managing Bucket ACLs.

An object ACL can be configured in three modes:

  1. Specify a pre-defined access control policy during object upload.
  2. Call ObsClient.setObjectAcl to specify a pre-defined access control policy.
  3. Call ObsClient.setObjectAcl to set the ACL directly.

Specifying a Pre-defined Access Control Policy During Object Upload

Sample code:

String endPoint = "yourdomainname";
String ak = "*** Provide your Access Key ***";
String sk = "*** Provide your Secret Key ***";

// Create an instance of ObsClient.
final ObsClient obsClient = new ObsClient(ak, sk, endPoint);

PutObjectRequest request = new PutObjectRequest();
request.setBucketName("bucketname");
request.setObjectKey("objectkey");
request.setFile(new File("localfile"));
// Set the object ACL to public-read.
request.setAcl(AccessControlList.REST_CANNED_PUBLIC_READ);
obsClient.putObject(request);

// Close obsClient.
obsClient.close();

Setting a Pre-defined Access Control Policy for an Object

Sample code:

String endPoint = "yourdomainname";
String ak = "*** Provide your Access Key ***";
String sk = "*** Provide your Secret Key ***";

// Create an instance of ObsClient.
final ObsClient obsClient = new ObsClient(ak, sk, endPoint);

// Set the object ACL to private. 
obsClient.setObjectAcl("bucketname", "objectkey", AccessControlList.REST_CANNED_PRIVATE);

// Close obsClient.
obsClient.close();

Directly Setting an Object ACL

Sample code:

String endPoint = "yourdomainname";
String ak = "*** Provide your Access Key ***";
String sk = "*** Provide your Secret Key ***";

// Create an instance of ObsClient.
final ObsClient obsClient = new ObsClient(ak, sk, endPoint);

AccessControlList acl = new AccessControlList();
Owner owner = new Owner();
owner.setId("ownerid");
acl.setOwner(owner);
// Grant the FULL_CONTROL permission to a specified user.
acl.grantPermission(new CanonicalGrantee("userid"), Permission.PERMISSION_FULL_CONTROL);
// Grant the READ permission to all users.
acl.grantPermission(GroupGrantee.ALL_USERS, Permission.PERMISSION_READ);
// Grant the WRITE permission to authorized users. 
acl.grantPermission(GroupGrantee.AUTHENTICATED_USERS, Permission.PERMISSION_WRITE);
obsClient.setObjectAcl("bucketname", "objectkey", acl);

// Close obsClient.
obsClient.close();
NOTE:

The owner or grantee ID needed in the ACL indicates the account ID, which can be viewed on the My Credential page of OBS Console.

Obtaining an Object ACL

You can call ObsClient.getObjectAcl to obtain an object ACL. Sample code is as follows:

String endPoint = "yourdomainname";
String ak = "*** Provide your Access Key ***";
String sk = "*** Provide your Secret Key ***";

// Create an instance of ObsClient.
final ObsClient obsClient = new ObsClient(ak, sk, endPoint);

AccessControlList acl = obsClient.getObjectAcl("bucketname", "objectkey");
Log.i("GetObjectAcl", acl);

// Close obsClient.
obsClient.close();