开发者

Can I switch user on runnable thread in Java?

Suppose I need to run this on shell,

$ su <user>; cp /x /y;

Is there a way to run threads with another unix开发者_运维技巧 user within the application ?


No. Java threads are at a finer level of granularity than unix processes; it's processes that have an effective user.


You might be able to Runtime.exec a sudo'd command. The exec creates a new unix process, which can use another user.

If sudo has been correctly configured (e.g. user joe can only exec program foobar using sudo) it shouldn't even be too much of a security problem provided you don't just punt credentials from the front-end in the command to execute.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜