tags:

views:

203

answers:

3

Hi,

Is it possible to access a file (read/write/delete/move...) using different credentials then the one the logged in user?

+1  A: 

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.

Michael Borgwardt
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.]
Kevin Brock
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.
Michael Borgwardt
+1  A: 

Not directly from the JVM, no.

But under Windows, you could do exec() with a RunAs command, and under Unix/Linux/OS X you could do exec() with sudo. Though you may end up getting prompted for the password.

Carl Smotricz
A: 

If it is available as a file share you can use jcifs

tbond