コード例 #1
0
ファイル: JsonUtil.cs プロジェクト: orf53975/hadoop.net
        /// <summary>Convert a Json map to a AclStatus object.</summary>
        public static AclStatus ToAclStatus <_T0>(IDictionary <_T0> json)
        {
            if (json == null)
            {
                return(null);
            }
            IDictionary <object, object> m = (IDictionary <object, object>)json[typeof(AclStatus
                                                                                       ).Name];

            AclStatus.Builder aclStatusBuilder = new AclStatus.Builder();
            aclStatusBuilder.Owner((string)m["owner"]);
            aclStatusBuilder.Group((string)m["group"]);
            aclStatusBuilder.StickyBit((bool)m["stickyBit"]);
            string permString = (string)m["permission"];

            if (permString != null)
            {
                FsPermission permission = ToFsPermission(permString, (bool)m["aclBit"], (bool)m["encBit"
                                                         ]);
                aclStatusBuilder.SetPermission(permission);
            }
            IList <object>   entries      = (IList <object>)m["entries"];
            IList <AclEntry> aclEntryList = new AList <AclEntry>();

            foreach (object entry in entries)
            {
                AclEntry aclEntry = AclEntry.ParseAclEntry((string)entry, true);
                aclEntryList.AddItem(aclEntry);
            }
            aclStatusBuilder.AddEntries(aclEntryList);
            return(aclStatusBuilder.Build());
        }
コード例 #2
0
        /// <summary>Return the JSON formatted ACL status of the specified file.</summary>
        /// <param name="path">a path specifies a file</param>
        /// <returns>JSON formatted AclStatus</returns>
        /// <exception cref="System.IO.IOException">if failed to serialize fileStatus to JSON.
        ///     </exception>
        internal virtual string GetAclStatus(string path)
        {
            PermissionStatus p            = GetPermissionStatus(path);
            IList <AclEntry> aclEntryList = GetAclEntryList(path);
            FsPermission     permission   = p.GetPermission();

            AclStatus.Builder builder = new AclStatus.Builder();
            builder.Owner(p.GetUserName()).Group(p.GetGroupName()).AddEntries(aclEntryList).SetPermission
                (permission).StickyBit(permission.GetStickyBit());
            AclStatus aclStatus = builder.Build();

            return(JsonUtil.ToJsonString(aclStatus));
        }
コード例 #3
0
ファイル: TestJsonUtil.cs プロジェクト: orf53975/hadoop.net
        public virtual void TestToJsonFromAclStatus()
        {
            string jsonString = "{\"AclStatus\":{\"entries\":[\"user:user1:rwx\",\"group::rw-\"],\"group\":\"supergroup\",\"owner\":\"testuser\",\"stickyBit\":false}}";

            AclStatus.Builder aclStatusBuilder = new AclStatus.Builder();
            aclStatusBuilder.Owner("testuser");
            aclStatusBuilder.Group("supergroup");
            aclStatusBuilder.StickyBit(false);
            IList <AclEntry> aclSpec = Lists.NewArrayList(AclTestHelpers.AclEntry(AclEntryScope
                                                                                  .Access, AclEntryType.User, "user1", FsAction.All), AclTestHelpers.AclEntry(AclEntryScope
                                                                                                                                                              .Access, AclEntryType.Group, FsAction.ReadWrite));

            aclStatusBuilder.AddEntries(aclSpec);
            NUnit.Framework.Assert.AreEqual(jsonString, JsonUtil.ToJsonString(aclStatusBuilder
                                                                              .Build()));
        }
コード例 #4
0
ファイル: TestJsonUtil.cs プロジェクト: orf53975/hadoop.net
        public virtual void TestToAclStatus()
        {
            string       jsonString              = "{\"AclStatus\":{\"entries\":[\"user::rwx\",\"user:user1:rw-\",\"group::rw-\",\"other::r-x\"],\"group\":\"supergroup\",\"owner\":\"testuser\",\"stickyBit\":false}}";
            ObjectReader reader                  = new ObjectMapper().Reader(typeof(IDictionary));
            IDictionary <object, object> json    = reader.ReadValue(jsonString);
            IList <AclEntry>             aclSpec = Lists.NewArrayList(AclTestHelpers.AclEntry(AclEntryScope
                                                                                              .Access, AclEntryType.User, FsAction.All), AclTestHelpers.AclEntry(AclEntryScope
                                                                                                                                                                 .Access, AclEntryType.User, "user1", FsAction.ReadWrite), AclTestHelpers.AclEntry
                                                                          (AclEntryScope.Access, AclEntryType.Group, FsAction.ReadWrite), AclTestHelpers.AclEntry
                                                                          (AclEntryScope.Access, AclEntryType.Other, FsAction.ReadExecute));

            AclStatus.Builder aclStatusBuilder = new AclStatus.Builder();
            aclStatusBuilder.Owner("testuser");
            aclStatusBuilder.Group("supergroup");
            aclStatusBuilder.AddEntries(aclSpec);
            aclStatusBuilder.StickyBit(false);
            NUnit.Framework.Assert.AreEqual("Should be equal", aclStatusBuilder.Build(), JsonUtil
                                            .ToAclStatus(json));
        }