Search in sources :

Example 66 with Mode

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());
    }
}
Also used : FileInfo(alluxio.wire.FileInfo) AuthenticatedUserRule(alluxio.AuthenticatedUserRule) Mode(alluxio.security.authorization.Mode) UfsMode(alluxio.underfs.UfsMode) AlluxioURI(alluxio.AlluxioURI) BaseIntegrationTest(alluxio.testutils.BaseIntegrationTest) Test(org.junit.Test)

Example 67 with Mode

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();
}
Also used : MkdirsOptions(alluxio.underfs.options.MkdirsOptions) UfsStatus(alluxio.underfs.UfsStatus) LockMode(alluxio.concurrent.LockMode) Mode(alluxio.security.authorization.Mode) IOException(java.io.IOException) UnderFileSystem(alluxio.underfs.UnderFileSystem) InvalidPathException(alluxio.exception.InvalidPathException) FileDoesNotExistException(alluxio.exception.FileDoesNotExistException) UnavailableException(alluxio.exception.status.UnavailableException) BlockInfoException(alluxio.exception.BlockInfoException) FileAlreadyExistsException(alluxio.exception.FileAlreadyExistsException) IOException(java.io.IOException) InvalidPathException(alluxio.exception.InvalidPathException) AlluxioURI(alluxio.AlluxioURI)

Example 68 with Mode

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());
}
Also used : Mode(alluxio.security.authorization.Mode) PosixFilePermission(java.nio.file.attribute.PosixFilePermission)

Example 69 with Mode

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);
}
Also used : Mode(alluxio.security.authorization.Mode)

Example 70 with Mode

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());
        }
    }
}
Also used : SetAttributeContext(alluxio.master.file.contexts.SetAttributeContext) FileInfo(alluxio.wire.FileInfo) AuthenticatedUserRule(alluxio.AuthenticatedUserRule) Closeable(java.io.Closeable) Mode(alluxio.security.authorization.Mode) AlluxioURI(alluxio.AlluxioURI)

Aggregations

Mode (alluxio.security.authorization.Mode)78 Test (org.junit.Test)47 AlluxioURI (alluxio.AlluxioURI)43 BaseIntegrationTest (alluxio.testutils.BaseIntegrationTest)15 UnderFileSystem (alluxio.underfs.UnderFileSystem)14 Random (java.util.Random)14 IOException (java.io.IOException)11 UfsMode (alluxio.underfs.UfsMode)9 URIStatus (alluxio.client.file.URIStatus)8 FileInfo (alluxio.wire.FileInfo)8 ArrayList (java.util.ArrayList)8 FileAlreadyExistsException (alluxio.exception.FileAlreadyExistsException)7 SetAttributePOptions (alluxio.grpc.SetAttributePOptions)7 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)6 WriteType (alluxio.client.WriteType)5 AlluxioException (alluxio.exception.AlluxioException)5 LockedInodePath (alluxio.master.file.meta.LockedInodePath)5 AclEntry (alluxio.security.authorization.AclEntry)5 AuthenticatedClientUserResource (alluxio.AuthenticatedClientUserResource)4 AuthenticatedUserRule (alluxio.AuthenticatedUserRule)4