简体   繁体   中英

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. 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.

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.

Appreciate your help.

you could change the group permissions on the file. You could start a System.process( "su user && cat file" ); You could have the other user copy the file to you using a 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)

Check out this Class file for examples on launching local commands:

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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