Search in sources :

Example 6 with CannedAccessControlList

use of com.aliyun.oss.model.CannedAccessControlList in project aliyun-oss-java-sdk by aliyun.

the class ResponseParsers method parseGetBucketAcl.

/**
 * Unmarshall get bucket acl response body to ACL.
 */
public static AccessControlList parseGetBucketAcl(InputStream responseBody) throws ResponseParseException {
    try {
        Element root = getXmlRootElement(responseBody);
        AccessControlList acl = new AccessControlList();
        String id = root.getChild("Owner").getChildText("ID");
        String displayName = root.getChild("Owner").getChildText("DisplayName");
        Owner owner = new Owner(id, displayName);
        acl.setOwner(owner);
        String aclString = root.getChild("AccessControlList").getChildText("Grant");
        CannedAccessControlList cacl = CannedAccessControlList.parse(aclString);
        acl.setCannedACL(cacl);
        switch(cacl) {
            case PublicRead:
                acl.grantPermission(GroupGrantee.AllUsers, Permission.Read);
                break;
            case PublicReadWrite:
                acl.grantPermission(GroupGrantee.AllUsers, Permission.FullControl);
                break;
            default:
                break;
        }
        return acl;
    } catch (JDOMParseException e) {
        throw new ResponseParseException(e.getPartialDocument() + ": " + e.getMessage(), e);
    } catch (Exception e) {
        throw new ResponseParseException(e.getMessage(), e);
    }
}
Also used : CannedAccessControlList(com.aliyun.oss.model.CannedAccessControlList) AccessControlList(com.aliyun.oss.model.AccessControlList) JDOMParseException(org.jdom.input.JDOMParseException) Owner(com.aliyun.oss.model.Owner) Element(org.jdom.Element) ResponseParseException(com.aliyun.oss.common.parser.ResponseParseException) CannedAccessControlList(com.aliyun.oss.model.CannedAccessControlList) ParseException(java.text.ParseException) JDOMParseException(org.jdom.input.JDOMParseException) ResponseParseException(com.aliyun.oss.common.parser.ResponseParseException)

Aggregations

CannedAccessControlList (com.aliyun.oss.model.CannedAccessControlList)6 OSSException (com.aliyun.oss.OSSException)2 ResponseParseException (com.aliyun.oss.common.parser.ResponseParseException)2 AccessControlList (com.aliyun.oss.model.AccessControlList)2 Owner (com.aliyun.oss.model.Owner)2 ParseException (java.text.ParseException)2 Element (org.jdom.Element)2 JDOMParseException (org.jdom.input.JDOMParseException)2 Test (org.junit.Test)2 ClientConfiguration (com.aliyun.oss.ClientConfiguration)1 OSSClient (com.aliyun.oss.OSSClient)1 CredentialsProvider (com.aliyun.oss.common.auth.CredentialsProvider)1 RequestMessage (com.aliyun.oss.common.comm.RequestMessage)1 TestUtils.genFixedLengthInputStream (com.aliyun.oss.integrationtests.TestUtils.genFixedLengthInputStream)1 Bucket (com.aliyun.oss.model.Bucket)1 BucketInfo (com.aliyun.oss.model.BucketInfo)1 Grant (com.aliyun.oss.model.Grant)1 OSSObject (com.aliyun.oss.model.OSSObject)1 ObjectAcl (com.aliyun.oss.model.ObjectAcl)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1