Is there a legal way to add/remove permissions to Java security policy at runtime?
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
Javadoc says that Policy.refresh()
for file-based policy would re-read the file. Thus, it is possible to modify system-wide policy at runtime by editing policy file and then calling Policy.refresh()
回答2:
From 1.4 dynamic ProtectionDomain
s can delegate to the Policy
. Dynamically removing permissions from code is unlikely to make any sense. The two argument forms of AccessController.doPrivileged
might also be useful.
回答3:
It is possible to set custom Policy implementation, using Policy.setPolicy()
method. For example see JAAS in Action book.