Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Running a program in different userid's

 
balaji govindaswamy
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Peter Chase
Ranch Hand
Posts: 1970
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
balaji govindaswamy
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic