Esempio n. 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());
        }
Esempio n. 2
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()));
        }
Esempio n. 3
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));
        }