i am trying to switch unix super user through java code. but getting authentication failure error, please help to switch user using java.
1 Answer
You simply cannot. The only way to switch users in a process in unix is through the setuid(2)
system call, that for an unprivileged user account is only valid to switch user ids between the real and saved user ids (this happens only in case of a suid executable) Java Thread
s run as process threads in architectures that allow that, but not as different processes, so all the JVM runs normally as a single process.
All these concepts are foreign to Java, as the JVM runs on behalf of the user who started the application (you can make java setuid root, but this is a highly dangerous security risk, as the JVM has no means to check for the validity of the uid change and in such situation all users capable of executing java code should be able to switch to whatever user they want) So this being said, no possibility of changing users for a java process is allowed in a un*x system.
I don't know if there exists a Runtime.setuid()
call, but as the only utility is for JVMs started by root, who is the only user that can switch users without validating them, I think there's no implementation and you'll have to deal with some JNI programming to implement such a thing.
setuid(2)
system call is reserved for theroot
account.