static void GetObjectACL()
        {
            try
            {
                GetObjectAclRequest request = new GetObjectAclRequest()
                {
                    BucketName = bucketName,
                    ObjectKey  = objectName
                };
                GetObjectAclResponse response = client.GetObjectAcl(request);

                Console.WriteLine("Get object acl response: {0}.", response.StatusCode);

                foreach (Grant grant in response.AccessControlList.Grants)
                {
                    CanonicalGrantee grantee = (CanonicalGrantee)grant.Grantee;
                    Console.WriteLine("Grantee canonical user id: {0}", grantee.Id);
                    Console.WriteLine("Grantee canonical user display name: {0}", grantee.DisplayName);
                    Console.WriteLine("Grant permission: {0}", grant.Permission);
                }
            }
            catch (ObsException ex)
            {
                Console.WriteLine("Exception errorcode: {0}, when get object acl.", ex.ErrorCode);
                Console.WriteLine("Exception errormessage: {0}", ex.ErrorMessage);
            }
        }
Ejemplo n.º 2
0
        public override GetBucketLoggingResponse ParseGetBucketLoggingResponse(HttpResponse httpResponse)
        {
            GetBucketLoggingResponse response = new GetBucketLoggingResponse();

            using (XmlReader xmlReader = XmlReader.Create(httpResponse.Content))
            {
                Grant currentGrant = null;
                while (xmlReader.Read())
                {
                    if ("BucketLoggingStatus".Equals(xmlReader.Name))
                    {
                        if (xmlReader.IsStartElement())
                        {
                            response.Configuration = new LoggingConfiguration();
                        }
                    }
                    else if ("Agency".Equals(xmlReader.Name))
                    {
                        response.Configuration.Agency = xmlReader.ReadString();
                    }
                    else if ("TargetBucket".Equals(xmlReader.Name))
                    {
                        response.Configuration.TargetBucketName = xmlReader.ReadString();
                    }
                    else if ("TargetPrefix".Equals(xmlReader.Name))
                    {
                        response.Configuration.TargetPrefix = xmlReader.ReadString();
                    }
                    else if ("Grant".Equals(xmlReader.Name))
                    {
                        if (xmlReader.IsStartElement())
                        {
                            currentGrant = new Grant();
                            response.Configuration.Grants.Add(currentGrant);
                        }
                    }
                    else if ("ID".Equals(xmlReader.Name))
                    {
                        CanonicalGrantee grantee = new CanonicalGrantee();
                        grantee.Id           = xmlReader.ReadString();
                        currentGrant.Grantee = grantee;
                    }
                    else if ("Canned".Equals(xmlReader.Name))
                    {
                        GroupGrantee grantee = new GroupGrantee();
                        grantee.GroupGranteeType = this.ParseGroupGrantee(xmlReader.ReadString());
                        currentGrant.Grantee     = grantee;
                    }
                    else if ("Permission".Equals(xmlReader.Name))
                    {
                        currentGrant.Permission = this.ParsePermission(xmlReader.ReadString());
                    }
                }
            }
            return(response);
        }
Ejemplo n.º 3
0
        private static string ConvertCanonicalGrantee(CanonicalGrantee grantee)
        {
            var builder = new StringBuilder();

            builder.Append($"<Grantee xmlns:xsi=\"{xmlns}\" xsi:type=\"CanonicalUser\">");
            builder.Append($"<DisplayName>{ grantee.DisplayName }</DisplayName>");
            builder.Append($"<ID>{grantee.GetIdentifier()}</ID>");
            builder.Append("</Grantee>");

            return(builder.ToString());
        }
Ejemplo n.º 4
0
        private static String convertCanonicalGrantee(CanonicalGrantee grantee)
        {
            StringBuilder builder = new StringBuilder();

            builder.Append("<Grantee xmlns:xsi=\"" + xmlns + "\" xsi:type=\"CanonicalUser\">");
            builder.Append("<DisplayName>" + grantee.getDisplayName() + "</DisplayName>");
            builder.Append("<ID>" + grantee.getIdentifier() + "</ID>");
            builder.Append("</Grantee>");

            return(builder.ToString());
        }
Ejemplo n.º 5
0
        public override bool Equals(object obj)
        {
            if (obj == null)
            {
                return(false);
            }

            if (obj.GetType().Equals(GetType()))
            {
                CanonicalGrantee other = (CanonicalGrantee)obj;
                return(_id.Equals(other._id));
            }
            return(false);
        }
        private void TransGrants(XmlWriter xmlWriter, IList <Grant> grants, bool isBucket, string startElementName)
        {
            xmlWriter.WriteStartElement(startElementName);
            foreach (Grant grant in grants)
            {
                if (grant.Grantee != null && grant.Permission.HasValue)
                {
                    xmlWriter.WriteStartElement("Grant");

                    if (grant.Grantee is GroupGrantee)
                    {
                        GroupGrantee groupGrantee = grant.Grantee as GroupGrantee;
                        if (groupGrantee.GroupGranteeType == GroupGranteeEnum.AllUsers)
                        {
                            xmlWriter.WriteStartElement("Grantee");
                            xmlWriter.WriteElementString("Canned", "Everyone");
                            xmlWriter.WriteEndElement();
                        }
                    }
                    else if (grant.Grantee is CanonicalGrantee)
                    {
                        xmlWriter.WriteStartElement("Grantee");
                        CanonicalGrantee canonicalGrantee = grant.Grantee as CanonicalGrantee;
                        xmlWriter.WriteElementString("ID", canonicalGrantee.Id);
                        xmlWriter.WriteEndElement();
                    }
                    xmlWriter.WriteElementString("Permission", EnumAdaptor.GetStringValue(grant.Permission));
                    if (isBucket)
                    {
                        xmlWriter.WriteElementString("Delivered", grant.Delivered.ToString().ToLower());
                    }
                    xmlWriter.WriteEndElement();
                }
            }
            xmlWriter.WriteEndElement();
        }
Ejemplo n.º 7
0
 private AccessControlList ParseAccessControlList(HttpResponse httpResponse, bool isBucket)
 {
     using (XmlReader xmlReader = XmlReader.Create(httpResponse.Content))
     {
         AccessControlList acl = new AccessControlList();
         bool  innerOwner      = false;
         Grant currentGrant    = null;
         while (xmlReader.Read())
         {
             if ("Owner".Equals(xmlReader.Name))
             {
                 if (xmlReader.IsStartElement())
                 {
                     acl.Owner = new Owner();
                 }
                 innerOwner = xmlReader.IsStartElement();
             }
             else if ("ID".Equals(xmlReader.Name))
             {
                 if (innerOwner)
                 {
                     acl.Owner.Id = xmlReader.ReadString();
                 }
                 else
                 {
                     CanonicalGrantee grantee = new CanonicalGrantee();
                     grantee.Id           = xmlReader.ReadString();
                     currentGrant.Grantee = grantee;
                 }
             }
             else if ("Grant".Equals(xmlReader.Name))
             {
                 if (xmlReader.IsStartElement())
                 {
                     currentGrant = new Grant();
                     acl.Grants.Add(currentGrant);
                 }
             }
             else if ("Canned".Equals(xmlReader.Name))
             {
                 GroupGrantee grantee = new GroupGrantee();
                 grantee.GroupGranteeType = this.ParseGroupGrantee(xmlReader.ReadString());
                 currentGrant.Grantee     = grantee;
             }
             else if ("Permission".Equals(xmlReader.Name))
             {
                 currentGrant.Permission = this.ParsePermission(xmlReader.ReadString());
             }
             else if ("Delivered".Equals(xmlReader.Name))
             {
                 if (isBucket)
                 {
                     currentGrant.Delivered = Convert.ToBoolean(xmlReader.ReadString());
                 }
                 else
                 {
                     acl.Delivered = Convert.ToBoolean(xmlReader.ReadString());
                 }
             }
         }
         return(acl);
     }
 }
Ejemplo n.º 8
0
        public AccessControlList unmarshall(Stream inputStream)
        {
            AccessControlList acl              = new AccessControlList();
            Owner             owner            = null;
            String            ownerId          = null;
            String            ownerDisplayName = null;
            Grantee           grantee          = null;
            String            granteeType      = null;
            String            userId           = null;
            String            userDisplayName  = null;
            String            groupUri         = null;
            String            permission       = null;
            bool          insideGrant          = false;
            StringBuilder currText             = new StringBuilder();

            XmlReader xr = XmlReader.Create(new BufferedStream(inputStream));

            while (xr.Read())
            {
                if (xr.NodeType.Equals(XmlNodeType.Element))
                {
                    if (xr.Name.Equals("Grant"))
                    {
                        insideGrant = true;
                    }
                    else if (xr.Name.Equals("Grantee"))
                    {
                        granteeType = xr.GetAttribute("xsi:type");
                    }
                }
                else if (xr.NodeType.Equals(XmlNodeType.EndElement))
                {
                    if (xr.Name.Equals("DisplayName"))
                    {
                        if (!insideGrant)
                        {
                            ownerId = currText.ToString();
                        }
                        else
                        {
                            userId = currText.ToString();
                        }
                    }
                    else if (xr.Name.Equals("ID"))
                    {
                        if (!insideGrant)
                        {
                            ownerDisplayName = currText.ToString();
                        }
                        else
                        {
                            userDisplayName = currText.ToString();
                        }
                    }
                    else if (xr.Name.Equals("URI"))
                    {
                        groupUri = currText.ToString();
                    }
                    else if (xr.Name.Equals("Owner"))
                    {
                        owner = new Owner(ownerId, ownerDisplayName);
                        acl.setOwner(owner);
                    }
                    else if (xr.Name.Equals("Grantee"))
                    {
                        if (granteeType.Equals("CanonicalUser"))
                        {
                            grantee = new CanonicalGrantee(userId, userDisplayName);
                        }
                        else if (granteeType.Equals("Group"))
                        {
                            grantee = new GroupGrantee(groupUri);
                        }
                    }
                    else if (xr.Name.Equals("Permission"))
                    {
                        permission = currText.ToString();
                    }
                    else if (xr.Name.Equals("Grant"))
                    {
                        acl.grantPermission(grantee, permission);
                        insideGrant = false;
                    }

                    currText.Clear();
                }
                else if (xr.NodeType.Equals(XmlNodeType.Text))
                {
                    currText.Append(xr.Value);
                }
            } // end while

            return(acl);
        } // end of unmarshall