Java Code Examples for org.apache.hadoop.fs.XAttr#getNameSpace()

The following examples show how to use org.apache.hadoop.fs.XAttr#getNameSpace() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: XAttrPermissionFilter.java    From hadoop with Apache License 2.0 6 votes vote down vote up
static void checkPermissionForApi(FSPermissionChecker pc, XAttr xAttr,
    boolean isRawPath)
    throws AccessControlException {
  final boolean 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(SECURITY_XATTR_UNREADABLE_BY_SUPERUSER)) {
    if (xAttr.getValue() != null) {
      throw new AccessControlException("Attempt to set a value for '" +
          SECURITY_XATTR_UNREADABLE_BY_SUPERUSER +
          "'. Values are not allowed for this xattr.");
    }
    return;
  }
  throw new AccessControlException("User doesn't have permission for xattr: "
      + XAttrHelper.getPrefixName(xAttr));
}
 
Example 2
Source File: FSDirXAttrOp.java    From hadoop with Apache License 2.0 6 votes vote down vote up
private static void checkXAttrChangeAccess(
    FSDirectory fsd, INodesInPath iip, XAttr xAttr,
    FSPermissionChecker pc)
    throws AccessControlException {
  if (fsd.isPermissionEnabled() && xAttr.getNameSpace() == XAttr.NameSpace
      .USER) {
    final INode inode = iip.getLastINode();
    if (inode != null &&
        inode.isDirectory() &&
        inode.getFsPermission().getStickyBit()) {
      if (!pc.isSuperUser()) {
        fsd.checkOwner(pc, iip);
      }
    } else {
      fsd.checkPathAccess(pc, iip, FsAction.WRITE);
    }
  }
}
 
Example 3
Source File: XAttrPermissionFilter.java    From big-c with Apache License 2.0 6 votes vote down vote up
static void checkPermissionForApi(FSPermissionChecker pc, XAttr xAttr,
    boolean isRawPath)
    throws AccessControlException {
  final boolean 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(SECURITY_XATTR_UNREADABLE_BY_SUPERUSER)) {
    if (xAttr.getValue() != null) {
      throw new AccessControlException("Attempt to set a value for '" +
          SECURITY_XATTR_UNREADABLE_BY_SUPERUSER +
          "'. Values are not allowed for this xattr.");
    }
    return;
  }
  throw new AccessControlException("User doesn't have permission for xattr: "
      + XAttrHelper.getPrefixName(xAttr));
}
 
Example 4
Source File: FSDirXAttrOp.java    From big-c with Apache License 2.0 6 votes vote down vote up
private static void checkXAttrChangeAccess(
    FSDirectory fsd, INodesInPath iip, XAttr xAttr,
    FSPermissionChecker pc)
    throws AccessControlException {
  if (fsd.isPermissionEnabled() && xAttr.getNameSpace() == XAttr.NameSpace
      .USER) {
    final INode inode = iip.getLastINode();
    if (inode != null &&
        inode.isDirectory() &&
        inode.getFsPermission().getStickyBit()) {
      if (!pc.isSuperUser()) {
        fsd.checkOwner(pc, iip);
      }
    } else {
      fsd.checkPathAccess(pc, iip, FsAction.WRITE);
    }
  }
}
 
Example 5
Source File: FSImageLoader.java    From hadoop with Apache License 2.0 5 votes vote down vote up
/**
 * Return the JSON formatted XAttrs of the specified file.
 *
 * @param path
 *          a path specifies a file
 * @return JSON formatted XAttrs
 * @throws IOException
 *           if failed to serialize fileStatus to JSON.
 */
String getXAttrs(String path, List<String> names, String encoder)
        throws IOException {

  List<XAttr> xAttrs = getXAttrList(path);
  List<XAttr> filtered;
  if (names == null || names.size() == 0) {
    filtered = xAttrs;
  } else {
    filtered = Lists.newArrayListWithCapacity(names.size());
    for (String name : names) {
      XAttr search = XAttrHelper.buildXAttr(name);

      boolean found = false;
      for (XAttr aXAttr : xAttrs) {
        if (aXAttr.getNameSpace() == search.getNameSpace()
                && aXAttr.getName().equals(search.getName())) {

          filtered.add(aXAttr);
          found = true;
          break;
        }
      }

      if (!found) {
        throw new IOException(
                "At least one of the attributes provided was not found.");
      }
    }

  }
  return JsonUtil.toJsonString(filtered,
          new XAttrEncodingParam(encoder).getEncoding());
}
 
Example 6
Source File: FSDirXAttrOp.java    From hadoop with Apache License 2.0 4 votes vote down vote up
static List<XAttr> getXAttrs(FSDirectory fsd, final String srcArg,
                             List<XAttr> xAttrs)
    throws IOException {
  String src = srcArg;
  checkXAttrsConfigFlag(fsd);
  FSPermissionChecker pc = fsd.getPermissionChecker();
  final boolean isRawPath = FSDirectory.isReservedRawName(src);
  boolean getAll = xAttrs == null || xAttrs.isEmpty();
  if (!getAll) {
    XAttrPermissionFilter.checkPermissionForApi(pc, xAttrs, isRawPath);
  }
  byte[][] pathComponents = FSDirectory.getPathComponentsForReservedPath(src);
  src = fsd.resolvePath(pc, src, pathComponents);
  final INodesInPath iip = fsd.getINodesInPath(src, true);
  if (fsd.isPermissionEnabled()) {
    fsd.checkPathAccess(pc, iip, FsAction.READ);
  }
  List<XAttr> all = FSDirXAttrOp.getXAttrs(fsd, src);
  List<XAttr> filteredAll = XAttrPermissionFilter.
      filterXAttrsForApi(pc, all, isRawPath);

  if (getAll) {
    return filteredAll;
  }
  if (filteredAll == null || filteredAll.isEmpty()) {
    return null;
  }
  List<XAttr> toGet = Lists.newArrayListWithCapacity(xAttrs.size());
  for (XAttr xAttr : xAttrs) {
    boolean foundIt = false;
    for (XAttr a : filteredAll) {
      if (xAttr.getNameSpace() == a.getNameSpace() && xAttr.getName().equals(
          a.getName())) {
        toGet.add(a);
        foundIt = true;
        break;
      }
    }
    if (!foundIt) {
      throw new IOException(
          "At least one of the attributes provided was not found.");
    }
  }
  return toGet;
}
 
Example 7
Source File: FSDirXAttrOp.java    From hadoop with Apache License 2.0 4 votes vote down vote up
private static boolean isUserVisible(XAttr xAttr) {
  XAttr.NameSpace ns = xAttr.getNameSpace();
  return ns == XAttr.NameSpace.USER || ns == XAttr.NameSpace.TRUSTED;
}
 
Example 8
Source File: BlockStoragePolicySuite.java    From hadoop with Apache License 2.0 4 votes vote down vote up
public static boolean isStoragePolicyXAttr(XAttr xattr) {
  return xattr != null && xattr.getNameSpace() == XAttrNS
      && xattr.getName().equals(STORAGE_POLICY_XATTR_NAME);
}
 
Example 9
Source File: FSDirXAttrOp.java    From big-c with Apache License 2.0 4 votes vote down vote up
static List<XAttr> getXAttrs(FSDirectory fsd, final String srcArg,
                             List<XAttr> xAttrs)
    throws IOException {
  String src = srcArg;
  checkXAttrsConfigFlag(fsd);
  FSPermissionChecker pc = fsd.getPermissionChecker();
  final boolean isRawPath = FSDirectory.isReservedRawName(src);
  boolean getAll = xAttrs == null || xAttrs.isEmpty();
  if (!getAll) {
    XAttrPermissionFilter.checkPermissionForApi(pc, xAttrs, isRawPath);
  }
  byte[][] pathComponents = FSDirectory.getPathComponentsForReservedPath(src);
  src = fsd.resolvePath(pc, src, pathComponents);
  final INodesInPath iip = fsd.getINodesInPath(src, true);
  if (fsd.isPermissionEnabled()) {
    fsd.checkPathAccess(pc, iip, FsAction.READ);
  }
  List<XAttr> all = FSDirXAttrOp.getXAttrs(fsd, src);
  List<XAttr> filteredAll = XAttrPermissionFilter.
      filterXAttrsForApi(pc, all, isRawPath);

  if (getAll) {
    return filteredAll;
  }
  if (filteredAll == null || filteredAll.isEmpty()) {
    return null;
  }
  List<XAttr> toGet = Lists.newArrayListWithCapacity(xAttrs.size());
  for (XAttr xAttr : xAttrs) {
    boolean foundIt = false;
    for (XAttr a : filteredAll) {
      if (xAttr.getNameSpace() == a.getNameSpace() && xAttr.getName().equals(
          a.getName())) {
        toGet.add(a);
        foundIt = true;
        break;
      }
    }
    if (!foundIt) {
      throw new IOException(
          "At least one of the attributes provided was not found.");
    }
  }
  return toGet;
}
 
Example 10
Source File: FSDirXAttrOp.java    From big-c with Apache License 2.0 4 votes vote down vote up
private static boolean isUserVisible(XAttr xAttr) {
  XAttr.NameSpace ns = xAttr.getNameSpace();
  return ns == XAttr.NameSpace.USER || ns == XAttr.NameSpace.TRUSTED;
}
 
Example 11
Source File: BlockStoragePolicySuite.java    From big-c with Apache License 2.0 4 votes vote down vote up
public static boolean isStoragePolicyXAttr(XAttr xattr) {
  return xattr != null && xattr.getNameSpace() == XAttrNS
      && xattr.getName().equals(STORAGE_POLICY_XATTR_NAME);
}