/** * Gets the default mode. * * @return the default {@link Mode} */ public static Mode defaults() { return new Mode(Constants.DEFAULT_FILE_SYSTEM_MODE); }
/** * Creates the "full access" mode. * * @return the none {@link Mode} */ public static Mode createFullAccess() { return new Mode(Bits.ALL, Bits.ALL, Bits.ALL); }
/** * Creates the "no access" mode. * * @return the none {@link Mode} */ public static Mode createNoAccess() { return new Mode(); }
private static Mode parseNumeric(String value) { short s = Short.parseShort(value, 8); return new Mode(s); }
private static String toExceptionMessage(String user, Mode.Bits bits, String path, Inode inode) { StringBuilder sb = new StringBuilder().append("user=").append(user).append(", ").append("access=").append(bits) .append(", ").append("path=").append(path).append(": ").append("failed at ") .append(inode.getName().equals("") ? "/" : inode.getName()).append(", inode owner=") .append(inode.getOwner()).append(", inode group=").append(inode.getGroup()) .append(", inode mode=").append(new Mode(inode.getMode()).toString()); return sb.toString(); } }
/** * @param mode1 first mode of the and operation * @param mode2 second mode of the and operation * @return the AND result of the two Modes */ public static Mode and(Mode mode1, Mode mode2) { Bits u = mode1.mOwnerBits.and(mode2.mOwnerBits); Bits g = mode1.mGroupBits.and(mode2.mGroupBits); Bits o = mode1.mOtherBits.and(mode2.mOtherBits); return new Mode(u, g, o); }
@Override public void setMode(String path, short mode) throws IOException { path = stripPath(path); String posixPerm = new Mode(mode).toString(); FileUtils.changeLocalFilePermission(path, posixPerm); }
/** * Tests the {@link Mode#toString()} method. */ @Test public void toStringTest() { assertEquals("rwxrwxrwx", new Mode((short) 0777).toString()); assertEquals("rw-r-----", new Mode((short) 0640).toString()); assertEquals("rw-------", new Mode((short) 0600).toString()); assertEquals("---------", new Mode((short) 0000).toString()); }
/** * Tests the {@link Mode#toShort()} method. */ @Test public void toShort() { Mode mode = new Mode(Mode.Bits.ALL, Mode.Bits.READ_EXECUTE, Mode.Bits.READ_EXECUTE); assertEquals(0755, mode.toShort()); mode = Mode.defaults(); assertEquals(0777, mode.toShort()); mode = new Mode(Mode.Bits.READ_WRITE, Mode.Bits.READ, Mode.Bits.READ); assertEquals(0644, mode.toShort()); }
@Override public void check(FileSystem fs) throws Exception { for (AlluxioURI file : Arrays.asList(PATH, NESTED, THROUGH, TTL)) { assertTrue(fs.exists(file)); } assertEquals(TEST_MODE, new Mode((short) fs.getStatus(MODE).getMode())); assertTrue(fs.getStatus(THROUGH).isPersisted()); assertEquals(TEST_TTL, fs.getStatus(TTL).getTtl()); assertEquals(TtlAction.FREE, fs.getStatus(TTL).getTtlAction()); } }
/** * Tests the {@link Mode#equals(Object)} method. */ @Test public void equals() { Mode allAccess = new Mode((short) 0777); assertTrue(allAccess.equals(Mode.defaults())); Mode noAccess = new Mode((short) 0000); assertTrue(noAccess.equals(Mode.createNoAccess())); assertFalse(allAccess.equals(noAccess)); }
@Test public void setAclWithoutOwner() throws Exception { createFileWithSingleBlock(NESTED_FILE_URI); mFileSystemMaster.setAttribute(NESTED_URI, SetAttributeContext .defaults(SetAttributePOptions.newBuilder().setMode(new Mode((short) 0777).toProto()))); Set<String> entries = Sets.newHashSet(mFileSystemMaster .getFileInfo(NESTED_FILE_URI, GET_STATUS_CONTEXT).convertAclToStringEntries()); assertEquals(3, entries.size()); try (AuthenticatedClientUserResource userA = new AuthenticatedClientUserResource("userA", ServerConfiguration.global())) { Set<String> newEntries = Sets.newHashSet("user::rwx", "group::rwx", "other::rwx"); mThrown.expect(AccessControlException.class); mFileSystemMaster.setAcl(NESTED_FILE_URI, SetAclAction.REPLACE, newEntries.stream().map(AclEntry::fromCliString).collect(Collectors.toList()), SetAclContext.defaults()); } }
/** * Creates {@link Mode} from proto {@link PMode}. * * @param pMode proto mode * @return created mode */ public static Mode fromProto(PMode pMode) { Bits ownerBits = pMode.hasOwnerBits() ? Bits.valueOf(pMode.getOwnerBits().name()) : Bits.NONE; Bits groupBits = pMode.hasGroupBits() ? Bits.valueOf(pMode.getGroupBits().name()) : Bits.NONE; Bits otherBits = pMode.hasOtherBits() ? Bits.valueOf(pMode.getOtherBits().name()) : Bits.NONE; return new Mode(ownerBits, groupBits, otherBits); }
/** * Tests {@link AccessControlList#setMode(short)}. */ @Test public void setMode() { AccessControlList acl = new AccessControlList(); short mode = new Mode(Mode.Bits.EXECUTE, Mode.Bits.WRITE, Mode.Bits.READ).toShort(); acl.setMode(mode); Assert.assertEquals(mode, acl.getMode()); }
@Test public void setOtherBits() { Mode mode = new Mode((short) 0000); mode.setOtherBits(Mode.Bits.READ_EXECUTE); assertEquals(Mode.Bits.READ_EXECUTE, mode.getOtherBits()); mode.setOtherBits(Mode.Bits.WRITE); assertEquals(Mode.Bits.WRITE, mode.getOtherBits()); mode.setOtherBits(Mode.Bits.ALL); assertEquals(Mode.Bits.ALL, mode.getOtherBits()); } }
@Test public void setGroupBits() { Mode mode = new Mode((short) 0000); mode.setGroupBits(Mode.Bits.READ_EXECUTE); assertEquals(Mode.Bits.READ_EXECUTE, mode.getGroupBits()); mode.setGroupBits(Mode.Bits.WRITE); assertEquals(Mode.Bits.WRITE, mode.getGroupBits()); mode.setGroupBits(Mode.Bits.ALL); assertEquals(Mode.Bits.ALL, mode.getGroupBits()); }
/** * Tests the {@link Mode#Mode(Mode)} constructor. */ @Test public void copyConstructor() { Mode mode = new Mode(Mode.defaults()); assertEquals(Mode.Bits.ALL, mode.getOwnerBits()); assertEquals(Mode.Bits.ALL, mode.getGroupBits()); assertEquals(Mode.Bits.ALL, mode.getOtherBits()); assertEquals(0777, mode.toShort()); }
@Test public void setOwnerBits() { Mode mode = new Mode((short) 0000); mode.setOwnerBits(Mode.Bits.READ_EXECUTE); assertEquals(Mode.Bits.READ_EXECUTE, mode.getOwnerBits()); mode.setOwnerBits(Mode.Bits.WRITE); assertEquals(Mode.Bits.WRITE, mode.getOwnerBits()); mode.setOwnerBits(Mode.Bits.ALL); assertEquals(Mode.Bits.ALL, mode.getOwnerBits()); }
@Test public void deleteDirRecursiveWithPermissions() throws Exception { // userA has permissions to delete directory and nested file createFileWithSingleBlock(NESTED_FILE_URI); mFileSystemMaster.setAttribute(NESTED_URI, SetAttributeContext .defaults(SetAttributePOptions.newBuilder().setMode(new Mode((short) 0777).toProto()))); mFileSystemMaster.setAttribute(NESTED_FILE_URI, SetAttributeContext .defaults(SetAttributePOptions.newBuilder().setMode(new Mode((short) 0777).toProto()))); try (AuthenticatedClientUserResource userA = new AuthenticatedClientUserResource("userA", ServerConfiguration.global())) { mFileSystemMaster.delete(NESTED_URI, DeleteContext.defaults(DeletePOptions.newBuilder().setRecursive(true))); } assertEquals(IdUtils.INVALID_FILE_ID, mFileSystemMaster.getFileId(NESTED_URI)); assertEquals(IdUtils.INVALID_FILE_ID, mFileSystemMaster.getFileId(NESTED_FILE_URI)); }
/** * Tests {@link AccessControlList#getMode()}. */ @Test public void getMode() { AccessControlList acl = new AccessControlList(); Assert.assertEquals(0, acl.getMode()); acl.setEntry(new AclEntry.Builder().setType(AclEntryType.OWNING_USER).setSubject(OWNING_USER) .addAction(AclAction.READ).build()); acl.setEntry(new AclEntry.Builder().setType(AclEntryType.OWNING_GROUP).setSubject(OWNING_GROUP) .addAction(AclAction.WRITE).build()); acl.setEntry(new AclEntry.Builder().setType(AclEntryType.OTHER) .addAction(AclAction.EXECUTE).build()); Assert.assertEquals(new Mode(Mode.Bits.READ, Mode.Bits.WRITE, Mode.Bits.EXECUTE).toShort(), acl.getMode()); }