コード例 #1
0
 public static void SetUp()
 {
     // named user
     AclEntry.Builder aclEntryBuilder = new AclEntry.Builder().SetType(AclEntryType.User
                                                                       ).SetName("user1").SetPermission(FsAction.All);
     Entry1 = aclEntryBuilder.Build();
     Entry2 = aclEntryBuilder.Build();
     // named group
     Entry3 = new AclEntry.Builder().SetType(AclEntryType.Group).SetName("group2").SetPermission
                  (FsAction.ReadWrite).Build();
     // default other
     Entry4 = new AclEntry.Builder().SetType(AclEntryType.Other).SetPermission(FsAction
                                                                               .None).SetScope(AclEntryScope.Default).Build();
     // owner
     Entry5 = new AclEntry.Builder().SetType(AclEntryType.User).SetPermission(FsAction
                                                                              .All).Build();
     // default named group
     Entry6 = new AclEntry.Builder().SetType(AclEntryType.Group).SetName("group3").SetPermission
                  (FsAction.ReadWrite).SetScope(AclEntryScope.Default).Build();
     // other
     Entry7 = new AclEntry.Builder().SetType(AclEntryType.Other).SetPermission(FsAction
                                                                               .None).Build();
     // default named user
     Entry8 = new AclEntry.Builder().SetType(AclEntryType.User).SetName("user3").SetPermission
                  (FsAction.All).SetScope(AclEntryScope.Default).Build();
     // mask
     Entry9 = new AclEntry.Builder().SetType(AclEntryType.Mask).SetPermission(FsAction
                                                                              .Read).Build();
     // default mask
     Entry10 = new AclEntry.Builder().SetType(AclEntryType.Mask).SetPermission(FsAction
                                                                               .ReadExecute).SetScope(AclEntryScope.Default).Build();
     // group
     Entry11 = new AclEntry.Builder().SetType(AclEntryType.Group).SetPermission(FsAction
                                                                                .Read).Build();
     // default group
     Entry12 = new AclEntry.Builder().SetType(AclEntryType.Group).SetPermission(FsAction
                                                                                .Read).SetScope(AclEntryScope.Default).Build();
     // default owner
     Entry13 = new AclEntry.Builder().SetType(AclEntryType.User).SetPermission(FsAction
                                                                               .All).SetScope(AclEntryScope.Default).Build();
     AclStatus.Builder aclStatusBuilder = new AclStatus.Builder().Owner("owner1").Group
                                              ("group1").AddEntry(Entry1).AddEntry(Entry3).AddEntry(Entry4);
     Status1 = aclStatusBuilder.Build();
     Status2 = aclStatusBuilder.Build();
     Status3 = new AclStatus.Builder().Owner("owner2").Group("group2").StickyBit(true)
               .Build();
     Status4 = new AclStatus.Builder().AddEntry(Entry1).AddEntry(Entry3).AddEntry(Entry4
                                                                                  ).AddEntry(Entry5).AddEntry(Entry6).AddEntry(Entry7).AddEntry(Entry8).AddEntry(Entry9
                                                                                                                                                                 ).AddEntry(Entry10).AddEntry(Entry11).AddEntry(Entry12).AddEntry(Entry13).Build(
         );
 }
コード例 #2
0
ファイル: AclEntry.cs プロジェクト: orf53975/hadoop.net
        /// <summary>Parses a string representation of an ACL into a AclEntry object.<br /></summary>
        /// <param name="aclStr">
        /// String representation of an ACL.<br />
        /// Example: "user:foo:rw-"
        /// </param>
        /// <param name="includePermission">
        /// for setAcl operations this will be true. i.e. Acl should include
        /// permissions.<br />
        /// But for removeAcl operation it will be false. i.e. Acl should not
        /// contain permissions.<br />
        /// Example: "user:foo,group:bar,mask::"
        /// </param>
        /// <returns>
        /// Returns an
        /// <see cref="AclEntry"/>
        /// object
        /// </returns>
        public static AclEntry ParseAclEntry(string aclStr, bool includePermission)
        {
            AclEntry.Builder builder = new AclEntry.Builder();
            // Here "::" represent one empty string.
            // StringUtils.getStringCollection() will ignore this.
            string[] split = aclStr.Split(":");
            if (split.Length == 0)
            {
                throw new HadoopIllegalArgumentException("Invalid <aclSpec> : " + aclStr);
            }
            int index = 0;

            if ("default".Equals(split[0]))
            {
                // default entry
                index++;
                builder.SetScope(AclEntryScope.Default);
            }
            if (split.Length <= index)
            {
                throw new HadoopIllegalArgumentException("Invalid <aclSpec> : " + aclStr);
            }
            AclEntryType aclType = null;

            try
            {
                aclType = Enum.ValueOf <AclEntryType>(StringUtils.ToUpperCase(split[index]));
                builder.SetType(aclType);
                index++;
            }
            catch (ArgumentException)
            {
                throw new HadoopIllegalArgumentException("Invalid type of acl in <aclSpec> :" + aclStr
                                                         );
            }
            if (split.Length > index)
            {
                string name = split[index];
                if (!name.IsEmpty())
                {
                    builder.SetName(name);
                }
                index++;
            }
            if (includePermission)
            {
                if (split.Length <= index)
                {
                    throw new HadoopIllegalArgumentException("Invalid <aclSpec> : " + aclStr);
                }
                string   permission = split[index];
                FsAction fsAction   = FsAction.GetFsAction(permission);
                if (null == fsAction)
                {
                    throw new HadoopIllegalArgumentException("Invalid permission in <aclSpec> : " + aclStr
                                                             );
                }
                builder.SetPermission(fsAction);
                index++;
            }
            if (split.Length > index)
            {
                throw new HadoopIllegalArgumentException("Invalid <aclSpec> : " + aclStr);
            }
            AclEntry aclEntry = builder.Build();

            return(aclEntry);
        }