示例#1
0
        /// <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
        public virtual void TestAclStatusProto()
        {
            AclEntry e = new AclEntry.Builder().SetName("test").SetPermission(FsAction.ReadExecute
                                                                              ).SetScope(AclEntryScope.Default).SetType(AclEntryType.Other).Build();
            AclStatus s = new AclStatus.Builder().Owner("foo").Group("bar").AddEntry(e).Build
                              ();

            NUnit.Framework.Assert.AreEqual(s, PBHelper.Convert(PBHelper.Convert(s)));
        }
示例#3
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));
        }
示例#4
0
        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()));
        }
示例#5
0
        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));
        }