There is a requirement in my project .. where i have a void main () java program which gets triggered through Websphere MQ Queue once a message fall on it.
Now this Void main ()java program should start in different userid based on environment info that i give to it... I dont know how it could be done through java... as this could be possible in C language through " setuid()" call ( somewhere i heard) .. so is there anything similar to that in java APIs.
I'm fairly sure you can't do that in Pure Java. It's much too much an OS-specific thing.
You might be able to get your Java program invoked via a shell script that did the setuid (or su or sudo or whatever) before running Java. The Java would then be in a separate process, of course.
You can call native OS functions like setuid() via Java Native Interface (JNI). Not directly, of course - you need to write some wrapper Java and C code.
If you're running in an application server, bear in mind that setuid() almost certainly affects the whole process. Is that really what you want? Is the application server likely to get broken by changing its UID? I suspect it would.
None of this will get you around the OS's security constraints. If you're not set up to run stuff under a different UID, no amount of Java or JNI programming (except exploiting security holes, which I ain't helping with) is going to bypass that. [ June 29, 2007: Message edited by: Peter Chase ]
Betty Rubble? Well, I would go with Betty... but I'd be thinking of Wilma.
Joined: Jun 19, 2007
Thanks Peter.. Really this thing is blowing my mind.. have to make design decision.. would like to hear more workaround for this scenario..