Ejemplo n.º 1
0
        /// <exception cref="System.IO.IOException"/>
        private static IDictionary <string, object> ToJsonMap(XAttr xAttr, XAttrCodec encoding
                                                              )
        {
            if (xAttr == null)
            {
                return(null);
            }
            IDictionary <string, object> m = new SortedDictionary <string, object>();

            m["name"]  = XAttrHelper.GetPrefixName(xAttr);
            m["value"] = xAttr.GetValue() != null?XAttrCodec.EncodeValue(xAttr.GetValue(),
                                                                         encoding) : null;

            return(m);
        }
Ejemplo n.º 2
0
        /// <exception cref="Org.Apache.Hadoop.Security.AccessControlException"/>
        internal static void CheckPermissionForApi(FSPermissionChecker pc, XAttr xAttr, bool
                                                   isRawPath)
        {
            bool isSuperUser = pc.IsSuperUser();

            if (xAttr.GetNameSpace() == XAttr.NameSpace.User || (xAttr.GetNameSpace() == XAttr.NameSpace
                                                                 .Trusted && isSuperUser))
            {
                return;
            }
            if (xAttr.GetNameSpace() == XAttr.NameSpace.Raw && isRawPath && isSuperUser)
            {
                return;
            }
            if (XAttrHelper.GetPrefixName(xAttr).Equals(HdfsServerConstants.SecurityXattrUnreadableBySuperuser
                                                        ))
            {
                if (xAttr.GetValue() != null)
                {
                    throw new AccessControlException("Attempt to set a value for '" + HdfsServerConstants
                                                     .SecurityXattrUnreadableBySuperuser + "'. Values are not allowed for this xattr."
                                                     );
                }
                return;
            }
            throw new AccessControlException("User doesn't have permission for xattr: " + XAttrHelper
                                             .GetPrefixName(xAttr));
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Verifies that the combined size of the name and value of an xattr is within
        /// the configured limit.
        /// </summary>
        /// <remarks>
        /// Verifies that the combined size of the name and value of an xattr is within
        /// the configured limit. Setting a limit of zero disables this check.
        /// </remarks>
        private static void CheckXAttrSize(FSDirectory fsd, XAttr xAttr)
        {
            if (fsd.GetXattrMaxSize() == 0)
            {
                return;
            }
            int size = Sharpen.Runtime.GetBytesForString(xAttr.GetName(), Charsets.Utf8).Length;

            if (xAttr.GetValue() != null)
            {
                size += xAttr.GetValue().Length;
            }
            if (size > fsd.GetXattrMaxSize())
            {
                throw new HadoopIllegalArgumentException("The XAttr is too big. The maximum combined size of the"
                                                         + " name and value is " + fsd.GetXattrMaxSize() + ", but the total size is " +
                                                         size);
            }
        }
Ejemplo n.º 4
0
        /// <summary>Get value of first xattr from <code>XAttr</code> list</summary>
        public static byte[] GetFirstXAttrValue(IList <XAttr> xAttrs)
        {
            byte[] value = null;
            XAttr  xAttr = GetFirstXAttr(xAttrs);

            if (xAttr != null)
            {
                value = xAttr.GetValue();
                if (value == null)
                {
                    value = new byte[0];
                }
            }
            // xattr exists, but no value.
            return(value);
        }