@Override public String toString() { return MessageFormat.format("'{' masked: {0}, unmasked: {1} '}'", super.toString(), getUnmasked()); }
@Override public String explain() { String owner = this.destinationOwnerAndPermission != null && this.destinationOwnerAndPermission.getOwner() != null ? this.destinationOwnerAndPermission.getOwner() : "preserve"; String group = this.destinationOwnerAndPermission != null && this.destinationOwnerAndPermission.getGroup() != null ? this.destinationOwnerAndPermission.getGroup() : "preserve"; String permissions = this.destinationOwnerAndPermission != null && this.destinationOwnerAndPermission.getFsPermission() != null ? this.destinationOwnerAndPermission.getFsPermission().toString() : "preserve"; return String.format("Copy file %s to %s with owner %s, group %s, permission %s.", this.origin.getPath(), this.destination, owner, group, permissions); } }
FileStatus status = fs.getFileStatus(new Path(new URI(loc))); jb.put("group", status.getGroup()); jb.put("permission", status.getPermission().toString()); } catch (Exception e) { LOG.warn(e.getMessage() + " Couldn't get permissions for " + loc);
@Test public void testFsPermissionOperation() { HashMap<String, Integer> permsCode = new HashMap<String, Integer>(); for (int i = 0; i < 8; i++) { for (int j = 0; j < 8; j++) { for (int k = 0; k < 8; k++) { StringBuilder sb = new StringBuilder(); sb.append("0"); sb.append(i); sb.append(j); sb.append(k); Integer code = (((i * 8) + j) * 8) + k; String perms = (new FsPermission(Short.decode(sb.toString()))).toString(); if (permsCode.containsKey(perms)) { Assert.assertEquals("permissions(" + perms + ") mapped to multiple codes", code, permsCode.get(perms)); } permsCode.put(perms, code); assertFsPermissionTransformationIsGood(perms); } } } }
/** * Changes permission of a path. * * @param path path to set permission * @param permission permission set to path */ @Override public void setPermission(Path path, FsPermission permission) throws IOException { LOG.debug("setMode({},{})", path, permission.toString()); AlluxioURI uri = new AlluxioURI(HadoopUtils.getPathWithoutScheme(path)); SetAttributePOptions options = SetAttributePOptions.newBuilder() .setMode(new Mode(permission.toShort()).toProto()).setRecursive(false).build(); try { mFileSystem.setAttribute(uri, options); } catch (AlluxioException e) { throw new IOException(e); } }
private static void validatePermissions(CliSessionState ss, HiveConf conf, String perms) { perms = perms.trim(); FsPermission fp = null; if (perms.matches("^\\s*([r,w,x,-]{9})\\s*$")) { fp = FsPermission.valueOf("d" + perms); } else if (perms.matches("^\\s*([0-7]{3})\\s*$")) { fp = new FsPermission(Short.decode("0" + perms)); } else { ss.err.println("Invalid permission specification: " + perms); sysExit(ss,1); } if (!HCatUtil.validateMorePermissive(fp.getUserAction(), fp.getGroupAction())) { ss.err.println("Invalid permission specification: " + perms + " : user permissions must be more permissive than group permission "); sysExit(ss,1); } if (!HCatUtil.validateMorePermissive(fp.getGroupAction(), fp.getOtherAction())) { ss.err.println("Invalid permission specification: " + perms + " : group permissions must be more permissive than other permission "); sysExit(ss,1); } if ((!HCatUtil.validateExecuteBitPresentIfReadOrWrite(fp.getUserAction())) || (!HCatUtil.validateExecuteBitPresentIfReadOrWrite(fp.getGroupAction())) || (!HCatUtil.validateExecuteBitPresentIfReadOrWrite(fp.getOtherAction()))) { ss.err.println("Invalid permission specification: " + perms + " : permissions must have execute permissions if read or write permissions are specified "); sysExit(ss,1); } conf.set(HCatConstants.HCAT_PERMS, "d" + fp.toString()); }
@Override public String toString() { StringBuilder builder = new StringBuilder(); builder.append("ModifyCachePoolOp ["); ArrayList<String> fields = new ArrayList<String>(5); if (info.getPoolName() != null) { fields.add("poolName=" + info.getPoolName()); } if (info.getOwnerName() != null) { fields.add("ownerName=" + info.getOwnerName()); } if (info.getGroupName() != null) { fields.add("groupName=" + info.getGroupName()); } if (info.getMode() != null) { fields.add("mode=" + info.getMode().toString()); } if (info.getLimit() != null) { fields.add("limit=" + info.getLimit()); } builder.append(Joiner.on(",").join(fields)); appendRpcIdsToString(builder, rpcClientId, rpcCallId); builder.append("]"); return builder.toString(); } }
for(FileStatus status : fs.listStatus(path)) { dataList.add(new String[] { status.getPermission().toString() ,status.getOwner() ,status.getGroup()
private void throwStickyBitException( String inodePath, INodeAttributes inode, String parentPath, INodeAttributes parent) throws AccessControlException { throw new AccessControlException(String.format( FSExceptionMessages.PERMISSION_DENIED_BY_STICKY_BIT + ": user=%s, path=\"%s\":%s:%s:%s%s, " + "parent=\"%s\":%s:%s:%s%s", user, inodePath, inode.getUserName(), inode.getGroupName(), inode.isDirectory() ? "d" : "-", inode.getFsPermission().toString(), parentPath, parent.getUserName(), parent.getGroupName(), parent.isDirectory() ? "d" : "-", parent.getFsPermission().toString())); }
/** * Extract the INode permissions stored in the fsimage file. * * @param in Datastream to process * @param v Visitor to walk over inodes */ private void processPermission(DataInputStream in, ImageVisitor v) throws IOException { v.visitEnclosingElement(ImageElement.PERMISSIONS); v.visit(ImageElement.USER_NAME, Text.readString(in)); v.visit(ImageElement.GROUP_NAME, Text.readString(in)); FsPermission fsp = new FsPermission(in.readShort()); v.visit(ImageElement.PERMISSION_STRING, fsp.toString()); v.leaveEnclosingElement(); // Permissions }
/** * Extract CachePool permissions stored in the fsimage file. * * @param in Datastream to process * @param v Visitor to walk over inodes */ private void processCachePoolPermission(DataInputStream in, ImageVisitor v) throws IOException { v.visitEnclosingElement(ImageElement.PERMISSIONS); v.visit(ImageElement.CACHE_POOL_OWNER_NAME, Text.readString(in)); v.visit(ImageElement.CACHE_POOL_GROUP_NAME, Text.readString(in)); FsPermission fsp = new FsPermission(in.readShort()); v.visit(ImageElement.CACHE_POOL_PERMISSION_STRING, fsp.toString()); v.leaveEnclosingElement(); // Permissions }
row.add(info.getOwnerName()); row.add(info.getGroupName()); row.add(info.getMode() != null ? info.getMode().toString() : null); Long limit = info.getLimit(); String limitString;
String dirString = isDir ? "d" : "-"; String aclString = hasAcl ? "+" : ""; append(buffer, dirString + p.getPermission().toString() + aclString); append(buffer, p.getUserName()); append(buffer, p.getGroupName());
private void confirmPermissionChange(String toApply, String expected, FileSystem fs, FsShell shell, Path dir2) throws IOException { LOG.info("Confirming permission change of " + toApply + " to " + expected); runCmd(shell, "-chmod", toApply, dir2.toString()); String result = fs.getFileStatus(dir2).getPermission().toString(); LOG.info("Permission change result: " + result); assertEquals(expected, result); }
@Override public void setPermission(INodeAuthorizationInfo node, FsPermission permission) { // always fall through to defaultAuthZProvider, // issue warning when the path is sentry managed if (isSentryManaged(node)) { LOG.warn("### setPermission {} (sentry managed path) to {}, update HDFS." + WARN_VISIBILITY, node.getFullPathName(), permission.toString()); } defaultAuthzProvider.setPermission(node, permission); }
@Override public String explain() { String owner = this.destinationOwnerAndPermission != null && this.destinationOwnerAndPermission.getOwner() != null ? this.destinationOwnerAndPermission.getOwner() : "preserve"; String group = this.destinationOwnerAndPermission != null && this.destinationOwnerAndPermission.getGroup() != null ? this.destinationOwnerAndPermission.getGroup() : "preserve"; String permissions = this.destinationOwnerAndPermission != null && this.destinationOwnerAndPermission.getFsPermission() != null ? this.destinationOwnerAndPermission.getFsPermission().toString() : "preserve"; return String.format("Copy file %s to %s with owner %s, group %s, permission %s.", this.origin.getPath(), this.destination, owner, group, permissions); } }
private void confirmPermissionChange(String toApply, String expected, FileSystem fs, FsShell shell, Path dir2) throws IOException { LOG.info("Confirming permission change of " + toApply + " to " + expected); runCmd(shell, "-chmod", toApply, dir2.toString()); String result = fs.getFileStatus(dir2).getPermission().toString(); LOG.info("Permission change result: " + result); assertEquals(expected, result); }
public void testPermissionMask() throws Exception { FsActionExecutor ae = new FsActionExecutor(); assertEquals("rwxrwxrwx", ae.createShortPermission("777", null).toString()); assertEquals("rwxrwxrwx", ae.createShortPermission("-rwxrwxrwx", null).toString()); assertEquals("r--------", ae.createShortPermission("400", null).toString()); assertEquals("r--------", ae.createShortPermission("-r--------", null).toString()); }
@Override public void toJSON(Object obj, JSON.Output out) { PermissionStatus permissionStatus = (PermissionStatus) obj; // Don't store group as null, just store it as empty string // (which is FileStatus behavior). String group = permissionStatus.getGroupName() == null ? "" : permissionStatus.getGroupName(); out.add(OWNER_TAG, permissionStatus.getUserName()); out.add(GROUP_TAG, group); out.add(PERMISSIONS_TAG, permissionStatus.getPermission().toString()); }
@Override public void toJSON(Object obj, JSON.Output out) { PermissionStatus permissionStatus = (PermissionStatus) obj; // Don't store group as null, just store it as empty string // (which is FileStatus behavior). String group = permissionStatus.getGroupName() == null ? "" : permissionStatus.getGroupName(); out.add(OWNER_TAG, permissionStatus.getUserName()); out.add(GROUP_TAG, group); out.add(PERMISSIONS_TAG, permissionStatus.getPermission().toString()); }