Is it possible to access a file (read/write/delete/move...) using different credentials then the one the logged in user?
3 Answers
What's relevant is not the logged in user but the user under which the process is running - these are not necessarily the same.
However, running a process under a different user ID is very OS-specific, and there is no Java API for it. Besides, it would have to be done when the JVM starts up, as I do not think any OS allows a process to switch its user ID.
2 Comments
Kevin Brock
Yes, you can switch user id on any Unix - see setuid() and seteuid(). After all, that's how login works on Unix systems! There are also similar in Windows (impersonisation, etc). Probably all OS have some means to do this within a process. [You are right about no JVM allowing it though.]
Michael Borgwardt
Hm, I'd assumed that setting the user ID would only be possible when a process is created, but having to change it afterwards is consistent with the fork() model of process creation.