Reputation: 17
I am running a java app as follows and my policy file is in the same folder and it gives the following error. if I run it without specifying policy related parameters, it runs fine. any idea what I am doing wrong here and how to fix it? thanks.
Error: Could not find or load main class –Djava.security.policy==quantanywhere.policy
java -Djava.security.manager –Djava.security.policy==my.policy -jar myapp.jar
my.policy file contents:
grant {
permission java.security.AllPermission;
};
Upvotes: 0
Views: 1235
Reputation: 17
i got it..
#1 create a policy file and give all permissions
grant {
permission java.security.AllPermission "", "";
};
#2 specify that policy file in command line
-Djava.security.manager -Djava.security.policy==/path/my.policy
#3 create a custom security manager class
public class MySecurityManager extends SecurityManager
{
@Override
public void checkExec(String cmd)
{
throw new RuntimeException( "Cannot execute shell script" );
}
}
#4 activate your custom security manager
SecurityManager securityManager = new MySecurityManager();
System.setSecurityManager( securityManager );
#5 that's it. your app can no longer execute shell commands/scripts
Upvotes: 1