Search in sources :

Example 11 with AuthenticatedUserRule

use of alluxio.AuthenticatedUserRule in project alluxio by Alluxio.

the class PermissionCheckTest method verifyRename.

private void verifyRename(TestUser user, String srcPath, String dstPath) throws Exception {
    try (Closeable r = new AuthenticatedUserRule(user.getUser(), ServerConfiguration.global()).toResource()) {
        String fileOwner = mFileSystemMaster.getFileInfo(mFileSystemMaster.getFileId(new AlluxioURI(srcPath))).getOwner();
        mFileSystemMaster.rename(new AlluxioURI(srcPath), new AlluxioURI(dstPath), RenameContext.defaults());
        assertEquals(-1, mFileSystemMaster.getFileId(new AlluxioURI(srcPath)));
        FileInfo fileInfo = mFileSystemMaster.getFileInfo(mFileSystemMaster.getFileId(new AlluxioURI(dstPath)));
        String[] pathComponents = dstPath.split("/");
        assertEquals(pathComponents[pathComponents.length - 1], fileInfo.getName());
        assertEquals(fileOwner, fileInfo.getOwner());
    }
}
Also used : FileInfo(alluxio.wire.FileInfo) AuthenticatedUserRule(alluxio.AuthenticatedUserRule) Closeable(java.io.Closeable) AlluxioURI(alluxio.AlluxioURI)

Example 12 with AuthenticatedUserRule

use of alluxio.AuthenticatedUserRule 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)

Example 13 with AuthenticatedUserRule

use of alluxio.AuthenticatedUserRule in project alluxio by Alluxio.

the class PermissionCheckTest method verifyCreateFile.

private void verifyCreateFile(TestUser user, String path, boolean recursive) throws Exception {
    try (Closeable r = new AuthenticatedUserRule(user.getUser(), ServerConfiguration.global()).toResource()) {
        CreateFileContext context = CreateFileContext.mergeFrom(CreateFilePOptions.newBuilder().setRecursive(recursive)).setOwner(SecurityUtils.getOwnerFromGrpcClient(ServerConfiguration.global())).setGroup(SecurityUtils.getGroupFromGrpcClient(ServerConfiguration.global())).setWriteType(WriteType.CACHE_THROUGH);
        FileInfo fileInfo = mFileSystemMaster.createFile(new AlluxioURI(path), context);
        String[] pathComponents = path.split("/");
        assertEquals(pathComponents[pathComponents.length - 1], fileInfo.getName());
        assertEquals(user.getUser(), fileInfo.getOwner());
    }
}
Also used : CreateFileContext(alluxio.master.file.contexts.CreateFileContext) FileInfo(alluxio.wire.FileInfo) AuthenticatedUserRule(alluxio.AuthenticatedUserRule) Closeable(java.io.Closeable) AlluxioURI(alluxio.AlluxioURI)

Aggregations

AuthenticatedUserRule (alluxio.AuthenticatedUserRule)13 Closeable (java.io.Closeable)11 AlluxioURI (alluxio.AlluxioURI)10 FileInfo (alluxio.wire.FileInfo)9 Mode (alluxio.security.authorization.Mode)4 Test (org.junit.Test)4 BaseIntegrationTest (alluxio.testutils.BaseIntegrationTest)2 UfsMode (alluxio.underfs.UfsMode)2 CreateDirectoryContext (alluxio.master.file.contexts.CreateDirectoryContext)1 CreateFileContext (alluxio.master.file.contexts.CreateFileContext)1 SetAttributeContext (alluxio.master.file.contexts.SetAttributeContext)1 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)1