| 1 | /** |
| 2 | * Licensed to jclouds, Inc. (jclouds) under one or more |
| 3 | * contributor license agreements. See the NOTICE file |
| 4 | * distributed with this work for additional information |
| 5 | * regarding copyright ownership. jclouds licenses this file |
| 6 | * to you under the Apache License, Version 2.0 (the |
| 7 | * "License"); you may not use this file except in compliance |
| 8 | * with the License. You may obtain a copy of the License at |
| 9 | * |
| 10 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | * |
| 12 | * Unless required by applicable law or agreed to in writing, |
| 13 | * software distributed under the License is distributed on an |
| 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 15 | * KIND, either express or implied. See the License for the |
| 16 | * specific language governing permissions and limitations |
| 17 | * under the License. |
| 18 | */ |
| 19 | package org.jclouds.s3.domain; |
| 20 | |
| 21 | /** |
| 22 | * Description from Amazon's documentation: |
| 23 | * |
| 24 | * <p /> |
| 25 | * Because of restrictions in what can be sent via http headers, Amazon S3 |
| 26 | * supports the concept of canned access policies for REST. A canned access |
| 27 | * policy can be included with the x-amz-acl header as part of a PUT operation |
| 28 | * to provide shorthand representation of a full access policy. When Amazon S3 |
| 29 | * sees the x-amz-acl header as part of a PUT operation, it will assign the |
| 30 | * respective access policy to the resource created as a result of the PUT. If |
| 31 | * no x-amz-acl header is included with a PUT request, then the bucket or object |
| 32 | * is written with the private access control policy (even if, in the case of an |
| 33 | * object, the object already exists with some other pre-existing access control |
| 34 | * policy). |
| 35 | * |
| 36 | * @see <a href="http://docs.amazonwebservices.com/AmazonS3/2006-03-01/index.html? |
| 37 | * RESTAccessPolicy.html" /> |
| 38 | * @author Adrian Cole |
| 39 | * |
| 40 | */ |
| 41 | public enum CannedAccessPolicy { |
| 42 | |
| 43 | /** |
| 44 | * Owner gets FULL_CONTROL. No one else has access rights (default). |
| 45 | */ |
| 46 | PRIVATE("private"), |
| 47 | /** |
| 48 | * Owner gets FULL_CONTROL and the anonymous identity is granted READ |
| 49 | * access. If this policy is used on an object, it can be read from a |
| 50 | * browser with no authentication. |
| 51 | */ |
| 52 | PUBLIC_READ("public-read"), |
| 53 | /** |
| 54 | * Owner gets FULL_CONTROL, the anonymous identity is granted READ and |
| 55 | * WRITE access. This can be a useful policy to apply to a bucket, but is |
| 56 | * generally not recommended. |
| 57 | */ |
| 58 | PUBLIC_READ_WRITE("public-read-write"), |
| 59 | /** |
| 60 | * Owner gets FULL_CONTROL, and any identity authenticated as a registered |
| 61 | * Amazon S3 user is granted READ access. |
| 62 | */ |
| 63 | AUTHENTICATED_READ("authenticated-read"); |
| 64 | |
| 65 | private String policyName; |
| 66 | |
| 67 | CannedAccessPolicy(String policyName) { |
| 68 | this.policyName = policyName; |
| 69 | } |
| 70 | |
| 71 | @Override |
| 72 | public String toString() { |
| 73 | return policyName; |
| 74 | } |
| 75 | |
| 76 | /** |
| 77 | * @param capHeader |
| 78 | * The value of the x-amz-acl HTTP Header returned by S3 when an |
| 79 | * object has a canned access policy. |
| 80 | * |
| 81 | * @return |
| 82 | * the canned access policy object corresponding to the header value, |
| 83 | * or null if the given header value does not represent a valid canned |
| 84 | * policy. |
| 85 | */ |
| 86 | public static CannedAccessPolicy fromHeader(String capHeader) { |
| 87 | if ("private".equals(capHeader)) { |
| 88 | return CannedAccessPolicy.PRIVATE; |
| 89 | } else if ("public-read".equals(capHeader)) { |
| 90 | return CannedAccessPolicy.PUBLIC_READ; |
| 91 | } else if ("public-read-write".equals(capHeader)) { |
| 92 | return CannedAccessPolicy.PUBLIC_READ_WRITE; |
| 93 | } else if ("authenticated-read".equals(capHeader)) { |
| 94 | return CannedAccessPolicy.AUTHENTICATED_READ; |
| 95 | } else { |
| 96 | return null; |
| 97 | } |
| 98 | } |
| 99 | } |