How do I get the current user from the ReadWriteFileSystemProvider implementation and/or the FileSystemNotifier events?

0 votes
asked Jul 18 by asgallant (240 points)

I have a Rebex FileServer with an SFTP binding and an implementation of a ReadWriteFileSystemProvider. When a user performs certain operations on the SFTP server (file create/modify/delete/etc), I need to process metadata about that operation, which must include information about the user.

I cannot find any way to extract the user from the ReadWriteFileSystemProvider or from the FileSystemNotifier events, though. I don't particularly care which one gives me the user (I can make what I need to do work with either one). I'm open to alternatives if there's another path that gets me what I need.

How can I get the FileServerUser from a ReadWriteFileSystemProvider method or a FileSystemNotifier event?

Applies to: File Server

1 Answer

0 votes
answered Jul 18 by Lukas Matyska (55,470 points)

It is very easy. Just use: ServerSession.Current.User

commented Jul 18 by asgallant (240 points)
Where do I get an instance of `ServerSession` from?
commented Jul 18 by renestein (2,790 points)
edited Jul 18 by renestein
Hi asgallant,
thanks for the question.
Despite the tight integration between both components and intended similarities in the API, FileServer and Virtual FileSystem are two independent components.
I think that you are looking for this.

1) Add the reference to the Rebex.FileServer assembly.
2) Add the using directive - using Rebex.Net.Servers.
3) Use the ServerSession.Current static property.

https://api.rebex.net/##RebexTotalPack.chm/Html/P_Rebex_Net_Servers_ServerSession_Current.htm

 private static void MyFilterDownloadFiles(object sender, GetChildrenEventArgs e)
 {

// obtain the current session.

    var session = ServerSession.Current;

...

}

You can obtain a current session from every event handler in the FileSystemNotifier and from methods in the Read(Write)FileSystemProvider as well. From the Virtual File System component point of view ServerSession.Current is an "ambient context"  (when the Virtual File System serves as a constitutive part of the FileServer).
commented Jul 18 by asgallant (240 points)
Thanks, I'll give that a try.
...