简体   繁体   English

Java切换用户在Linux上使用su

[英]Java switch user using su on linux

I am writing a java program dor Oracle EBS that needs to switch user because of specific permissions defined on an user different than applmgr. 我正在编写Java程序dor Oracle EBS,由于在不同于applmgr的用户上定义的特定权限,因此需要切换用户。 The approach we're taking is to have a java class that will switch user on a separate session and then will list the file from a folder that the new user has access. 我们采用的方法是拥有一个Java类,该类将在一个单独的会话上切换用户,然后从新用户有权访问的文件夹中列出文件。

Any options available? 有没有其他选择?

So far I could create two shell script files and then I run these shell scripts, one that will store environment variables and the other one will actually switch user and list the files. 到目前为止,我可以创建两个Shell脚本文件,然后运行这些Shell脚本,一个将存储环境变量,另一个将实际切换用户并列出文件。

Appreciate your help. 感谢您的帮助。

you could change the group permissions on the file. 您可以更改文件的组权限。 You could start a System.process( "su user && cat file" ); 您可以启动System.process(“ su user && cat file”); You could have the other user copy the file to you using a cronjob... 您可以让其他用户使用cronjob将文件复制给您...

You can try having Java launch a local command on the system then as part of that command launch another program (far from being very clean, but probably would work) 您可以尝试让Java在系统上启动本地命令,然后作为该命令的一部分启动另一个程序(虽然不是很干净,但是可能会起作用)

Check out this Class file for examples on launching local commands: 请查看此Class文件,以获取有关启动本地命令的示例:

https://github.com/SnakeDoc/RPi_SerialGPS/blob/master/src/com/vanomaly/rpi/serial/gps/util/System.java https://github.com/SnakeDoc/RPi_SerialGPS/blob/master/src/com/vanomaly/rpi/serial/gps/util/System.java

You should be able to use setuid - I expect there is a version available directly in Java, but otherwise, it shouldn't be that hard to make your own JNI code to do that. 您应该能够使用setuid我希望Java中直接存在一个可用的版本,但是,否则,使自己的JNI代码做到这一点并不难。

However, it may be simpler to run a command that switches user (using su or sudo , for example) and then runs the required Java code. 但是,运行切换用户(例如,使用susudo )然后运行所需的Java代码的命令可能会更简单。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM