using System; using System.Collections.Generic; using System.Xml.Serialization; using System.Text; namespace COSXML.Model.Tag { /// /// ACL权限 /// /// [XmlRoot] public sealed class AccessControlPolicy { /// /// Bucket 持有者信息 /// /// [XmlElement("Owner")] public Owner owner; /// /// 被授权者信息与权限信息 /// /// [XmlElement("AccessControlList")] public AccessControlList accessControlList; public string GetInfo() { StringBuilder stringBuilder = new StringBuilder("{AccessControlPolicy:\n"); if (owner != null) { stringBuilder.Append(owner.GetInfo()).Append("\n"); } if (accessControlList != null) { stringBuilder.Append(accessControlList.GetInfo()).Append("\n"); } stringBuilder.Append("}"); return stringBuilder.ToString(); } public sealed class Owner { /// /// Bucket 持有者 ID /// 格式:qcs::cam::uin/<OwnerUin>:uin/<SubUin> 如果是根帐号,<OwnerUin> 和 <SubUin> 是同一个值 /// [XmlElement("ID")] public string id; /// /// Bucket 持有者 /// [XmlElement("DisplayName")] public string displayName; public string GetInfo() { StringBuilder stringBuilder = new StringBuilder("{Owner:\n"); stringBuilder.Append("Id:").Append(id).Append("\n"); stringBuilder.Append("}"); return stringBuilder.ToString(); } } public sealed class AccessControlList { /// /// 单个 Bucket 的授权信息。一个 AccessControlList 可以拥有 100 条 Grant /// /// [XmlElement("Grant")] public List grants; public string GetInfo() { StringBuilder stringBuilder = new StringBuilder("{AccessControlList:\n"); if (grants != null) { foreach (Grant grant in grants) { if (grant != null) { stringBuilder.Append(grant.GetInfo()).Append("\n"); } } } stringBuilder.Append("}"); return stringBuilder.ToString(); } } public sealed class Grant { /// /// 说明被授权者的信息, /// /// [XmlElement("Grantee")] public Grantee grantee; /// /// 指明授予被授权者的权限信息 /// /// [XmlElement("Permission")] public string permission; public string GetInfo() { StringBuilder stringBuilder = new StringBuilder("{Grant:\n"); if (grantee != null) { stringBuilder.Append(grantee.GetInfo()).Append("\n"); } stringBuilder.Append("Permission:").Append(permission).Append("\n"); stringBuilder.Append("}"); return stringBuilder.ToString(); } } public sealed class Grantee { /// /// 用户的 ID,如果是根帐号,格式为:qcs::cam::uin/<OwnerUin>:uin/<OwnerUin> /// 如果是子帐号,格式为: qcs::cam::uin/<OwnerUin>:uin/<SubUin> /// [XmlElement("ID")] public string id; /// /// 或 http://cam.qcloud.com/groups/global/AllUsers (指代所有用户). /// [XmlElement("URI")] public string uri; /// /// 或 qcs::cam::anyone:anyone (指代所有用户). /// [XmlElement("DisplayName")] public string displayName; public string GetInfo() { StringBuilder stringBuilder = new StringBuilder("{Grantee:\n"); if (uri != null) { stringBuilder.Append("URI:").Append(uri).Append("\n"); } if (id != null) { stringBuilder.Append("Id:").Append(id).Append("\n"); } stringBuilder.Append("}"); return stringBuilder.ToString(); } } } }