How to disable all network connections in Java

Is there any way to run Java VM (Java. Exe) on Windows Server 2008 and disable all network connections using command line parameters or system variables?

Solution

You can do this by enabling the default Java security manager By default, no security is enforced, so you can perform any action, but if security manager is enabled, network access, file access and many other actions will be restricted unless you specify otherwise in the security policy file

To enable the default security manager, pass this parameter to the JVM at startup

java -Djava.security.manager=default my.main.Class

By doing so, any attempt to access the network from within the JVM will throw a Java net. NetPermission.

This will also destroy file access and other contents, so if you need to allow it, you need to specify them in a special security policy file (- DJava. Security. Policy = path / to / policy. File) There should be many examples of how to set it. Just search "Java permission" to start using it

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>