diff --git a/README.md b/README.md
index 814ba6757..2c8f336f3 100644
--- a/README.md
+++ b/README.md
@@ -132,6 +132,8 @@ The full API Reference is available here.
* [`removeBucket`](https://docs.minio.io/docs/java-client-api-reference#removeBucket)
* [`listObjects`](https://docs.minio.io/docs/java-client-api-reference#listObjects)
* [`listIncompleteUploads`](https://docs.minio.io/docs/java-client-api-reference#listIncompleteUploads)
+* [`getBucketPolicy`](https://docs.minio.io/docs/java-client-api-reference#getBucketPolicy)
+* [`setBucketPolicy`](https://docs.minio.io/docs/java-client-api-reference#setBucketPolicy)
### API Reference : Object Operations
@@ -163,6 +165,8 @@ The full API Reference is available here.
* [PutObject.java](https://github.com/minio/minio-java/tree/master/examples/PutObject.java)
* [GetObject.Java](https://github.com/minio/minio-java/tree/master/examples/GetObject.java)
+* [PutBucketPolicy.java](https://github.com/minio/minio-java/tree/master/examples/PutBucketPolicy.java)
+* [GetBucketPolicy.Java](https://github.com/minio/minio-java/tree/master/examples/GetBucketPolicy.java)
* [GetPartialObject.java](https://github.com/minio/minio-java/tree/master/examples/GetPartialObject.java)
* [RemoveObject.java](https://github.com/minio/minio-java/tree/master/examples/RemoveObject.java)
* [StatObject.java](https://github.com/minio/minio-java/tree/master/examples/StatObject.java)
diff --git a/docs/API.md b/docs/API.md
index 86f758c8d..076be1acf 100644
--- a/docs/API.md
+++ b/docs/API.md
@@ -26,6 +26,8 @@ MinioClient s3Client = new MinioClient("https://s3.amazonaws.com", "YOUR-ACCESSK
| [`removeBucket`](#removeBucket) | [`removeObject`](#removeObject) | |
| [`listObjects`](#listObjects) | [`removeIncompleteUpload`](#removeIncompleteUpload) | |
|[`listIncompleteUploads`](#listIncompleteUploads) | |
+| [`getBucketPolicy`](#getBucketPolicy) | |
+| [`setBucketPolicy`](#setBucketPolicy) | |
## 1. Constructors
@@ -588,6 +590,115 @@ try {
```
+
+### getBucketPolicy(String bucketName, String objectPrefix)
+`public BucketPolicy getBucketPolicy(String bucketName, String objectPrefix)`
+
+Get bucket policy at given objectPrefix.
+
+[View Javadoc](http://minio.github.io/minio-java/io/minio/MinioClient.html#getBucketPolicy-java.lang.String-java.lang.String-)
+
+__Parameters__
+
+|Param | Type | Description |
+|:--- |:--- |:--- |
+| ``bucketName`` | *String* | Name of the bucket. |
+| ``objectPrefix`` | *String* | Policy applies to objects with prefix. |
+
+
+
+
+ Return Type |
+ Exceptions |
+
+
+
+
+ BucketPolicy : The current bucket policy for given bucket and objectPrefix.
+ |
+
+
+ InvalidBucketNameException : upon invalid bucket name.
+ InvalidObjectPrefixException : upon invalid object prefix.
+ -
NoSuchAlgorithmException : upon requested algorithm was not found during signature calculation.
+ -
InsufficientDataException : Thrown to indicate that reading given InputStream gets EOFException before reading given length..
+ IOException : upon connection error.
+ -
InvalidKeyException : upon an invalid access key or secret key.
+ -
NoResponseException : upon no response from server.
+ org.xmlpull.v1.XmlPullParserException : upon parsing response XML.
+ ErrorResponseException : upon unsuccessful execution.
+ InternalException : upon internal library error.
+
+ |
+
+
+
+
+__Example__
+
+```java
+try {
+ System.out.println("Current policy: " + minioClient.getBucketPolicy("myBucket", "downloads"));
+ } catch (MinioException e) {
+ System.out.println("Error occured: " + e);
+}
+```
+
+
+### setBucketPolicy(String bucketName, String objectPrefix, BucketPolicy bucketPolicy)
+`public void setBucketPolicy(String bucketName, String objectPrefix, BucketPolicy bucketPolicy)`
+
+Set policy on bucket and object prefix.
+
+[View Javadoc](http://minio.github.io/minio-java/io/minio/MinioClient.html#setBucketPolicy-java.lang.String-java.lang.String-io.minio.BucketPolicy-)
+
+__Parameters__
+
+|Param | Type | Description |
+|:--- |:--- |:--- |
+| ``bucketName`` | *String* | Name of the bucket. |
+| ``objectPrefix`` | *String* | Policy applies to objects with prefix. |
+| ``bucketPolicy`` | *BucketPolicy* | Policy to apply. |
+
+
+
+
+ Return Type |
+ Exceptions |
+
+
+
+
+ None
+ |
+
+
+ InvalidBucketNameException : upon invalid bucket name.
+ InvalidObjectPrefixException : upon invalid object prefix.
+ -
NoSuchAlgorithmException : upon requested algorithm was not found during signature calculation.
+ -
InsufficientDataException : Thrown to indicate that reading given InputStream gets EOFException before reading given length..
+ IOException : upon connection error.
+ -
InvalidKeyException : upon an invalid access key or secret key.
+ -
NoResponseException : upon no response from server.
+ org.xmlpull.v1.XmlPullParserException : upon parsing response XML.
+ ErrorResponseException : upon unsuccessful execution.
+ InternalException : upon internal library error.
+ NoSuchBucketPolicyException : Thrown to indicate that given bucket has no bucket policy set.
+
+ |
+
+
+
+
+__Example__
+
+```java
+try {
+ minioClient.setBucketPolicy("myBucket", "uploads", BucketPolicy.WriteOnly);
+ } catch (MinioException e) {
+ System.out.println("Error occured: " + e);
+}
+```
## 3. Object operations
diff --git a/examples/GetBucketPolicy.java b/examples/GetBucketPolicy.java
new file mode 100644
index 000000000..0490e7d32
--- /dev/null
+++ b/examples/GetBucketPolicy.java
@@ -0,0 +1,42 @@
+/*
+ * Minio Java Library for Amazon S3 Compatible Cloud Storage, (C) 2015 Minio, Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import java.io.IOException;
+import java.security.NoSuchAlgorithmException;
+import java.security.InvalidKeyException;
+
+import org.xmlpull.v1.XmlPullParserException;
+
+import io.minio.MinioClient;
+import io.minio.BucketPolicy;
+import io.minio.errors.MinioException;
+
+public class GetBucketPolicy {
+ public static void main(String[] args)
+ throws IOException, NoSuchAlgorithmException, InvalidKeyException, XmlPullParserException {
+ // Note: YOUR-ACCESSKEYID, YOUR-SECRETACCESSKEY and my-bucketname are
+ // dummy values, please replace them with original values.
+ // For Amazon S3 endpoint, region is calculated automatically
+ try {
+ MinioClient minioClient = new MinioClient("https://play.minio.io:9000", "YOUR-ACCESSKEYID", "YOUR-SECRETACCESSKEY");
+
+ BucketPolicy policy = minioClient.getBucketPolicy("my-bucketname", "downloads");
+ System.out.println("Current policy: " + policy.toString());
+ } catch (MinioException e) {
+ System.out.println("Error occured: " + e);
+ }
+ }
+}
diff --git a/examples/SetBucketPolicy.java b/examples/SetBucketPolicy.java
new file mode 100644
index 000000000..5628bd14c
--- /dev/null
+++ b/examples/SetBucketPolicy.java
@@ -0,0 +1,41 @@
+/*
+ * Minio Java Library for Amazon S3 Compatible Cloud Storage, (C) 2015 Minio, Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import java.io.IOException;
+import java.security.NoSuchAlgorithmException;
+import java.security.InvalidKeyException;
+
+import org.xmlpull.v1.XmlPullParserException;
+
+import io.minio.MinioClient;
+import io.minio.BucketPolicy;
+import io.minio.errors.MinioException;
+
+public class SetBucketPolicy {
+ public static void main(String[] args)
+ throws IOException, NoSuchAlgorithmException, InvalidKeyException, XmlPullParserException {
+ // Note: YOUR-ACCESSKEYID, YOUR-SECRETACCESSKEY and my-bucketname are
+ // dummy values, please replace them with original values.
+ // For Amazon S3 endpoint, region is calculated automatically
+ try {
+ MinioClient minioClient = new MinioClient("https://play.minio.io:9000", "YOUR-ACCESSKEYID", "YOUR-SECRETACCESSKEY");
+
+ minioClient.setBucketPolicy("my-bucketname", "downloads", BucketPolicy.ReadOnly);
+ } catch (MinioException e) {
+ System.out.println("Error occured: " + e);
+ }
+ }
+}