/** * Constructs a default {@link CreateOptions}. */ private CreateOptions(String authUmask) { mAcl = null; mCreateParent = false; mEnsureAtomic = false; // default owner and group are null (unset) mOwner = null; mGroup = null; mMode = ModeUtils.applyFileUMask(Mode.defaults(), authUmask); }
/** * Constructs a default {@link MkdirsOptions}. */ private MkdirsOptions(String authUmask) { // By default create parent is true. mCreateParent = true; // default owner and group are null (unset) mOwner = null; mGroup = null; mMode = ModeUtils.applyDirectoryUMask(Mode.defaults(), authUmask); }
/** * Applies the default umask for newly created files to this mode. * * @param mode the mode to update * @param authUmask the umask to apply on the file * @return the updated object */ public static Mode applyFileUMask(Mode mode, String authUmask) { mode = applyUMask(mode, getUMask(authUmask)); mode = applyUMask(mode, FILE_UMASK); return mode; }
/** * Gets the file / directory creation umask. * * @return the umask {@link Mode} */ private static Mode getUMask(String confUmask) { int umask = Constants.DEFAULT_FILE_SYSTEM_UMASK; if (confUmask != null) { if ((confUmask.length() > 4) || !isValid(confUmask)) { throw new IllegalArgumentException(ExceptionMessage.INVALID_CONFIGURATION_VALUE .getMessage(confUmask, PropertyKey.SECURITY_AUTHORIZATION_PERMISSION_UMASK)); } int newUmask = 0; int lastIndex = confUmask.length() - 1; for (int i = 0; i <= lastIndex; i++) { newUmask += (confUmask.charAt(i) - '0') << 3 * (lastIndex - i); } umask = newUmask; } return new Mode((short) umask); }
try { mode = String.valueOf(protoOptions.getMode()); ufs.setMode(ufsUri, ModeUtils.protoToShort(protoOptions.getMode())); } catch (IOException e) { throw new AccessControlException("Could not setMode for UFS file " + ufsUri entry.setMode(ModeUtils.protoToShort(protoOptions.getMode()));
private CreateUfsFileOptions(AlluxioConfiguration alluxioConf) { mOwner = SecurityUtils.getOwnerFromLoginModule(alluxioConf); mGroup = SecurityUtils.getGroupFromLoginModule(alluxioConf); mMode = ModeUtils.applyFileUMask(Mode.defaults(), alluxioConf .get(PropertyKey.SECURITY_AUTHORIZATION_PERMISSION_UMASK)); // TODO(chaomin): set permission based on the alluxio file. Not needed for now since the // file is always created with default permission. } }
/** * Tests the {@link Mode#getUMask()} method to thrown an exception when it is not an integer. */ @Test public void umaskNotInteger() { String umask = "NotInteger"; mThrown.expect(IllegalArgumentException.class); mThrown.expectMessage(ExceptionMessage.INVALID_CONFIGURATION_VALUE.getMessage(umask, PropertyKey.SECURITY_AUTHORIZATION_PERMISSION_UMASK)); ModeUtils.applyDirectoryUMask(Mode.defaults(), umask); }
/** * Applies the default umask for newly created directories to this mode. * * @param mode the mode to update * @param authUmask the umask to apply on the directory * @return the updated object */ public static Mode applyDirectoryUMask(Mode mode, String authUmask) { return applyUMask(mode, getUMask(authUmask)); }
private CompleteUfsFileOptions(AlluxioConfiguration alluxioConf) { mOwner = SecurityUtils.getOwnerFromLoginModule(alluxioConf); mGroup = SecurityUtils.getGroupFromLoginModule(alluxioConf); mMode = ModeUtils.applyFileUMask(Mode.defaults(), alluxioConf.get(PropertyKey.SECURITY_AUTHORIZATION_PERMISSION_UMASK)); // TODO(chaomin): set permission based on the alluxio file. Not needed for now since the // file is always created with default permission. } }
/** * @return Master side defaults for {@link CreateDirectoryPOptions} */ public static CreateDirectoryPOptions createDirectoryDefaults() { return CreateDirectoryPOptions.newBuilder() .setCommonOptions(commonDefaults()) .setMode(ModeUtils.applyDirectoryUMask(Mode.defaults(), ServerConfiguration.get(PropertyKey.SECURITY_AUTHORIZATION_PERMISSION_UMASK)).toProto()) .setRecursive(false) .setWriteType(ServerConfiguration .getEnum(PropertyKey.USER_FILE_WRITE_TYPE_DEFAULT, WriteType.class).toProto()) .setAllowExists(false).build(); }
private OutStreamOptions(AlluxioConfiguration alluxioConf) { mBlockSizeBytes = alluxioConf.getBytes(PropertyKey.USER_BLOCK_SIZE_BYTES_DEFAULT); mTtl = Constants.NO_TTL; mTtlAction = TtlAction.DELETE; mLocationPolicy = CommonUtils.createNewClassInstance(alluxioConf.<FileWriteLocationPolicy>getClass( PropertyKey.USER_FILE_WRITE_LOCATION_POLICY), new Class[] {AlluxioConfiguration.class}, new Object[] {alluxioConf}); mWriteTier = alluxioConf.getInt(PropertyKey.USER_FILE_WRITE_TIER_DEFAULT); mWriteType = alluxioConf.getEnum(PropertyKey.USER_FILE_WRITE_TYPE_DEFAULT, WriteType.class); mOwner = SecurityUtils.getOwnerFromLoginModule(alluxioConf); mGroup = SecurityUtils.getGroupFromLoginModule(alluxioConf); mMode = ModeUtils.applyFileUMask(Mode.defaults(), alluxioConf .get(PropertyKey.SECURITY_AUTHORIZATION_PERMISSION_UMASK)); mMountId = IdUtils.INVALID_MOUNT_ID; mReplicationDurable = alluxioConf.getInt(PropertyKey.USER_FILE_REPLICATION_DURABLE); mReplicationMax = alluxioConf.getInt(PropertyKey.USER_FILE_REPLICATION_MAX); mReplicationMin = alluxioConf.getInt(PropertyKey.USER_FILE_REPLICATION_MIN); }
/** * Tests the {@link Mode#getUMask()} method to thrown an exception when it exceeds the length. */ @Test public void umaskExceedLength() { String umask = "00022"; mConfiguration.set(PropertyKey.SECURITY_AUTHORIZATION_PERMISSION_UMASK, umask); mThrown.expect(IllegalArgumentException.class); mThrown.expectMessage(ExceptionMessage.INVALID_CONFIGURATION_VALUE.getMessage(umask, PropertyKey.SECURITY_AUTHORIZATION_PERMISSION_UMASK)); ModeUtils.applyDirectoryUMask(Mode.defaults(), mConfiguration .get(PropertyKey.SECURITY_AUTHORIZATION_PERMISSION_UMASK)); }
/** * Tests the {@link MutableInodeFile#getMode()} method. */ @Test public void permissionStatus() { MutableInodeFile inode1 = createInodeFile(1); assertEquals(TEST_OWNER, inode1.getOwner()); assertEquals(TEST_GROUP, inode1.getGroup()); assertEquals(ModeUtils.applyFileUMask(Mode.defaults(), ServerConfiguration.get(PropertyKey.SECURITY_AUTHORIZATION_PERMISSION_UMASK)).toShort(), inode1.getMode()); } }
SecurityUtils.getOwnerFromLoginModule(ServerConfiguration.global()), SecurityUtils.getGroupFromLoginModule(ServerConfiguration.global()), ModeUtils.applyDirectoryUMask(Mode.createFullAccess(), ServerConfiguration.get(PropertyKey.SECURITY_AUTHORIZATION_PERMISSION_UMASK)), context);
/** * Tests for default {@link CreateOptions}. */ @Test public void defaults() throws IOException { CreateOptions options = CreateOptions.defaults(mConfiguration); assertFalse(options.getCreateParent()); assertFalse(options.isEnsureAtomic()); assertNull(options.getOwner()); assertNull(options.getGroup()); String umask = mConfiguration.get(PropertyKey.SECURITY_AUTHORIZATION_PERMISSION_UMASK); assertEquals(ModeUtils.applyFileUMask(Mode.defaults(), umask), options.getMode()); }
/** * Tests the {@link Mode#getUMask()} and * {@link Mode#applyUMask(Mode)} methods. */ @Test public void umask() { String umask = "0022"; Mode mode = ModeUtils.applyDirectoryUMask(Mode.defaults(), umask); assertEquals(Mode.Bits.ALL, mode.getOwnerBits()); assertEquals(Mode.Bits.READ_EXECUTE, mode.getGroupBits()); assertEquals(Mode.Bits.READ_EXECUTE, mode.getOtherBits()); assertEquals(0755, mode.toShort()); }
/** * @return Master side defaults for {@link CreateFilePOptions} */ public static CreateFilePOptions createFileDefaults() { return CreateFilePOptions.newBuilder() .setCommonOptions(commonDefaults()) .setRecursive(false) .setBlockSizeBytes(ServerConfiguration.getBytes(PropertyKey.USER_BLOCK_SIZE_BYTES_DEFAULT)) .setFileWriteLocationPolicy( ServerConfiguration.get(PropertyKey.USER_FILE_WRITE_LOCATION_POLICY)) .setWriteTier(ServerConfiguration.getInt(PropertyKey.USER_FILE_WRITE_TIER_DEFAULT)) .setWriteType(ServerConfiguration .getEnum(PropertyKey.USER_FILE_WRITE_TYPE_DEFAULT, WriteType.class).toProto()) .setMode(ModeUtils.applyFileUMask(Mode.defaults(), ServerConfiguration.get(PropertyKey.SECURITY_AUTHORIZATION_PERMISSION_UMASK)).toProto()) .setReplicationDurable(ServerConfiguration .getInt(PropertyKey.USER_FILE_REPLICATION_DURABLE)) .setReplicationMin(ServerConfiguration.getInt(PropertyKey.USER_FILE_REPLICATION_MIN)) .setReplicationMax(ServerConfiguration.getInt(PropertyKey.USER_FILE_REPLICATION_MAX)) .build(); }
/** * Tests the {@link MutableInodeDirectory#getMode()} method. */ @Test public void permissionStatus() { MutableInodeDirectory inode2 = createInodeDirectory(); Assert.assertEquals(TEST_OWNER, inode2.getOwner()); Assert.assertEquals(TEST_GROUP, inode2.getGroup()); Assert.assertEquals(ModeUtils.applyDirectoryUMask(Mode.defaults(), ServerConfiguration.get(PropertyKey.SECURITY_AUTHORIZATION_PERMISSION_UMASK)).toShort(), inode2.getMode()); }
/** * Tests for building an {@link CreateOptions} with a security enabled * configuration. */ @Test public void securityEnabled() throws IOException { mConfiguration.set(PropertyKey.SECURITY_AUTHENTICATION_TYPE, AuthType.SIMPLE.getAuthName()); mConfiguration.set(PropertyKey.SECURITY_LOGIN_USERNAME, "foo"); // Use IdentityUserGroupMapping to map user "foo" to group "foo". mConfiguration.set(PropertyKey.SECURITY_GROUP_MAPPING_CLASS, IdentityUserGroupsMapping.class.getName()); CreateOptions options = CreateOptions.defaults(mConfiguration); assertFalse(options.getCreateParent()); assertFalse(options.isEnsureAtomic()); assertNull(options.getOwner()); assertNull(options.getGroup()); String umask = mConfiguration.get(PropertyKey.SECURITY_AUTHORIZATION_PERMISSION_UMASK); assertEquals(ModeUtils.applyFileUMask(Mode.defaults(), umask), options.getMode()); }
/** * Tests for default {@link MkdirsOptions}. */ @Test public void defaults() throws IOException { MkdirsOptions options = MkdirsOptions.defaults(mConfiguration); // Verify the default createParent is true. assertTrue(options.getCreateParent()); // Verify that the owner and group are not set. assertNull(options.getOwner()); assertNull(options.getGroup()); String umask = mConfiguration.get(PropertyKey.SECURITY_AUTHORIZATION_PERMISSION_UMASK); assertEquals(ModeUtils.applyDirectoryUMask(Mode.defaults(), umask), options.getMode()); }