Grant permission to use a word with a protected file

I need to programmatically edit, record or delete protected files. On Windows, if I do this manually, it asks for permission, and on Unix systems I need "sudo".

How can I ask in Java about higher privileges at runtime?

+4
source share
2 answers

If your program requires high-level access, it is best to advise the user to run it as root / privileged account to work. Otherwise, the best option is to start a new "proxy process" that initializes with "sudo" and then a program that does what you want, such as "sudo cp File1 File2", which will do your dirty work for you. Unfortunately, this is not a cross platform and requires a password for users. It is simply not possible to simply push the JVM towards a higher user at runtime, as this would create a huge security risk.

md_5

+2
source

Since Java works using a virtual machine, you cannot just start (for example) another thread in high mode. Instead, you will need to start a completely new virtual machine with which you cannot connect.

I would consider ways to run a separate Java process that can work with elevated permissions. You can still use the same code, but this is the main method.

You cannot simply increase your privileges.

Perhaps I am mistaken, and I am happy that it will be shown differently.

0
source

All Articles