Managing Bucket Policies
If you have any questions during development, post them on the Issues page of GitHub. For details about parameters and usage of each API, see the API Reference
Besides bucket ACLs, bucket owners can use bucket policies to centrally control access to buckets and objects in buckets.
For more information, see Bucket Policy.
Setting a Bucket Policy
You can call ObsClient.setBucketPolicy to configure a bucket policy. For details about the format, see Policy Format, for bucket policies, see Introduction to OBS Permission Control, and for bucket policy examples, see Bucket Policy. The sample code is as follows:
String endPoint = "https://your-endpoint";
String ak = "*** Provide your Access Key ***";
String sk = "*** Provide your Secret Key ***";
// Create an instance of ObsClient.
ObsClient obsClient = new ObsClient(ak, sk, endPoint);
obsClient.setBucketPolicy("bucketname", "your policy");
For details about the format (JSON character string) of bucket policies, see the Object Storage Service API Reference.
The last policy configuration will overwrite the original one when you call the API for configuring a bucket policy. For example, if you have configured bucket policies A, B, C, and D and you want to add a new bucket policy E, add policy E to the file containing the existing four policies and then upload the file with all policies contained.
Likewise, if you want to delete bucket policy D, remove it from the file containing policies A, B, C, and D, and then upload the file without policy D contained.
Obtaining a Bucket Policy
You can call ObsClient.getBucketPolicy to obtain a bucket policy. Sample code is as follows:
String endPoint = "https://your-endpoint";
String ak = "*** Provide your Access Key ***";
String sk = "*** Provide your Secret Key ***";
// Create an instance of ObsClient.
ObsClient obsClient = new ObsClient(ak, sk, endPoint);
String policy = obsClient.getBucketPolicy("bucketname");
System.out.println("\t" + policy);
Deleting a Bucket Policy
You can call ObsClient.deleteBucketPolicy to delete a bucket policy. Calling this API will delete all bucket policies, instead of one single policy. To delete a single policy, see the API for configuring a bucket policy. Sample code is as follows:
String endPoint = "https://your-endpoint";
String ak = "*** Provide your Access Key ***";
String sk = "*** Provide your Secret Key ***";
// Create an instance of ObsClient.
ObsClient obsClient = new ObsClient(ak, sk, endPoint);
obsClient.deleteBucketPolicy("bucketname");
Last Article: Managing Bucket ACLs
Next Article: Obtaining a Bucket Location
Did this article solve your problem?
Thank you for your score!Your feedback would help us improve the website.