File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java in General and the fly likes Running a program in different userid's Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Running a program in different userid Watch "Running a program in different userid New topic
Author

Running a program in different userid's

balaji govindaswamy
Greenhorn

Joined: Jun 19, 2007
Posts: 3
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.

Thanks & Regards,
Balaji.


-Cheers<br />Balaji G
Peter Chase
Ranch Hand

Joined: Oct 30, 2001
Posts: 1970
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.
balaji govindaswamy
Greenhorn

Joined: Jun 19, 2007
Posts: 3
Thanks Peter.. Really this thing is blowing my mind.. have to make design decision.. would like to hear more workaround for this scenario..

Thanks in advance ..
Balaji.G
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Running a program in different userid's