use of alluxio.security.authorization.Mode in project alluxio by Alluxio.
the class FileSystemMasterIntegrationTest method setModeOwnerNoWritePermission.
@Test
public void setModeOwnerNoWritePermission() throws Exception {
AlluxioURI root = new AlluxioURI("/");
mFsMaster.setAttribute(root, SetAttributeContext.mergeFrom(SetAttributePOptions.newBuilder().setMode(new Mode((short) 0777).toProto())));
try (AutoCloseable closeable = new AuthenticatedUserRule("foo", ServerConfiguration.global()).toResource()) {
AlluxioURI alluxioFile = new AlluxioURI("/in_alluxio");
FileInfo file = mFsMaster.createFile(alluxioFile, CreateFileContext.defaults());
long opTimeMs = TEST_TIME_MS;
mFsMaster.completeFile(alluxioFile, CompleteFileContext.mergeFrom(CompleteFilePOptions.newBuilder().setUfsLength(0)).setOperationTimeMs(opTimeMs));
mFsMaster.setAttribute(alluxioFile, SetAttributeContext.mergeFrom(SetAttributePOptions.newBuilder().setMode(new Mode((short) 0407).toProto())));
Assert.assertEquals(0407, mFsMaster.getFileInfo(file.getFileId()).getMode());
mFsMaster.setAttribute(alluxioFile, SetAttributeContext.mergeFrom(SetAttributePOptions.newBuilder().setMode(new Mode((short) 0777).toProto())));
Assert.assertEquals(0777, mFsMaster.getFileInfo(file.getFileId()).getMode());
}
}
use of alluxio.security.authorization.Mode in project alluxio by Alluxio.
the class InodeTree method syncPersistDirectory.
/**
* Persists the directory to the UFS, returning the UFS status if the directory is found to
* already exist in the UFS.
*
* @param dir the directory to persist
* @return optional ufs status if the directory already existed
*/
private Optional<UfsStatus> syncPersistDirectory(InodeDirectoryView dir) throws FileDoesNotExistException, IOException, InvalidPathException {
AlluxioURI uri = getPath(dir);
MountTable.Resolution resolution = mMountTable.resolve(uri);
String ufsUri = resolution.getUri().toString();
try (CloseableResource<UnderFileSystem> ufsResource = resolution.acquireUfsResource()) {
UnderFileSystem ufs = ufsResource.get();
MkdirsOptions mkdirsOptions = MkdirsOptions.defaults(ServerConfiguration.global()).setCreateParent(false).setOwner(dir.getOwner()).setGroup(dir.getGroup()).setMode(new Mode(dir.getMode()));
if (!ufs.mkdirs(ufsUri, mkdirsOptions)) {
// Directory might already exist. Try loading the status from ufs.
UfsStatus status;
try {
status = ufs.getStatus(ufsUri);
} catch (Exception e) {
throw new IOException(String.format("Cannot create or load UFS directory %s: %s.", ufsUri, e.toString()), e);
}
if (status.isFile()) {
throw new InvalidPathException(String.format("Error persisting directory. A file exists at the UFS location %s.", ufsUri));
}
return Optional.of(status);
}
}
return Optional.empty();
}
use of alluxio.security.authorization.Mode in project alluxio by Alluxio.
the class SimpleFileManagerTest method verifyPerms.
private static void verifyPerms(Set<PosixFilePermission> perms, String actual) {
short perm = Short.parseShort(actual, 8);
Mode mode = new Mode(perm);
Set<PosixFilePermission> actualPerms = PosixFilePermissions.fromString(mode.toString());
assertTrue(perms.containsAll(actualPerms));
assertEquals(actualPerms.size(), perms.size());
}
use of alluxio.security.authorization.Mode in project alluxio by Alluxio.
the class LocalUnderFileSystem method setMode.
@Override
public void setMode(String path, short mode) throws IOException {
path = stripPath(path);
String posixPerm = new Mode(mode).toString();
FileUtils.changeLocalFilePermission(path, posixPerm);
}
use of alluxio.security.authorization.Mode in project alluxio by Alluxio.
the class PermissionCheckTest method verifySetAcl.
private void verifySetAcl(TestUser runUser, String path, String owner, String group, short mode, boolean recursive) throws Exception {
try (Closeable r = new AuthenticatedUserRule(runUser.getUser(), ServerConfiguration.global()).toResource()) {
SetAttributeContext context = SetAttributeContext.mergeFrom(SetAttributePOptions.newBuilder().setMode(new Mode(mode).toProto()).setRecursive(recursive));
if (owner != null) {
context.getOptions().setOwner(owner);
}
if (group != null) {
context.getOptions().setGroup(group);
}
mFileSystemMaster.setAttribute(new AlluxioURI(path), context);
}
try (Closeable r = new AuthenticatedUserRule(TEST_USER_ADMIN.getUser(), ServerConfiguration.global()).toResource()) {
FileInfo fileInfo = mFileSystemMaster.getFileInfo(mFileSystemMaster.getFileId(new AlluxioURI(path)));
if (owner != null) {
assertEquals(owner, fileInfo.getOwner());
}
if (group != null) {
assertEquals(group, fileInfo.getGroup());
}
if (mode != -1) {
assertEquals(mode, fileInfo.getMode());
}
}
}
Aggregations