简体   繁体   English

授予对带有受保护文件的单词的权限

[英]Grant permission to word with a protected file

I need to programmatically edit, write or delete protected files. 我需要以编程方式编辑,写入或删除受保护的文件。 In Windows, if i do it manually, it asks for permission and in Unix systems i need "sudo". 在Windows中,如果我手动进行操作,它会请求许可,而在Unix系统中,我需要“ sudo”。

How can I ask in Java for higher privileges during execution? 在执行过程中如何在Java中要求更高的特权?

If your program requires high level access it is best to advise the user that they need to run it as root / a privileged account in order to work. 如果您的程序需要高级别的访问权限,则最好告知用户他们需要以root用户/特权帐户运行该程序才能正常工作。 Otherwise the best option is to start a new 'proxy process' that is initialised using "sudo" and then a program doing what you want, eg "sudo cp File1 File2" that will perform your dirty work for you. 否则,最好的选择是启动一个新的“代理过程”,该过程使用“ sudo”初始化,然后使用某个程序执行所需的操作,例如“ sudo cp File1 File2”,它将为您执行肮脏的工作。 Unfortunately this is not cross platform and requires the users password. 不幸的是,这不是跨平台的,需要用户密码。 There is simply no way you can just bump the JVM to a higher user during execution as this would pose a huge security risk. 您根本无法在执行期间将JVM撞到更高的用户,因为这会带来巨大的安全风险。

md_5 md_5

Because Java works using a virtual machine, you can't just start (for example) another thread in an elevated mode. 因为Java使用虚拟机工作,所以您不能仅以提升模式启动(例如)另一个线程。 Instead, you'll need to launch an entirely new VM, which you won't be able to connect to. 相反,您将需要启动一个全新的VM,您将无法连接到该VM。

I'd look into ways of executing a separate Java process which can run with elevated permissions. 我将研究执行可以以提升的权限运行的单独Java进程的方法。 You can still use the same code, but have it be a main method. 您仍然可以使用相同的代码,但是将其作为主要方法。

You won't be able to just raise your privillages. 您将无法仅提高特权。

I might be entirely wrong, and am happy to be shown otherwise. 我可能完全错了,很高兴能被其他人看到。

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

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