aspose file tools*
The moose likes Beginning Java and the fly likes Enforcing custom policies using policytool - reg. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Enforcing custom policies using policytool - reg." Watch "Enforcing custom policies using policytool - reg." New topic
Author

Enforcing custom policies using policytool - reg.

dinesh Venkatesan
Ranch Hand

Joined: Oct 12, 2006
Posts: 134
Hi Friends,

I have written a small code to connect to google. Here is the code:


And here is my policy file:


Then, I tried to execute the Connector class in the presence of DefaultSecurityManager and this policy file using the following command line:

java -Djava.security.manager -Djava.security.policy=test.policy Connector

java.security.AccessControlException: access denied (java.net.SocketPermission 209.85.153.104:80 connect,resolve)
at java.security.AccessControlContext.checkPermission(Unknown Source)
at java.security.AccessController.checkPermission(Unknown Source)
at java.lang.SecurityManager.checkPermission(Unknown Source)
at java.lang.SecurityManager.checkConnect(Unknown Source)
at java.net.Socket.connect(Unknown Source)
at java.net.Socket.connect(Unknown Source)
at java.net.Socket.<init>(Unknown Source)
at java.net.Socket.<init>(Unknown Source)
at Connector.main(Connector.java:6)

Can anybody help me to find what is wrong in my approach?

Thanks in Advance!
Norm Radder
Ranch Hand

Joined: Aug 10, 2005
Posts: 690
    
    1
I've had problems with policytool in the past writing bad java.policy files and I've had to manually edit them.
Here's a grant line from my policy file. Note the single / after file:
grant codeBase "file:/D:/Testing/-" {
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Enforcing custom policies using policytool - reg.