Hint about: java.security.AccessControlException: access denied (java.net.SocketPermission host connect,resolve)

I am not Java Applet expert, but I found this worth for sharing.

I was told by my boss to check for the resolved ip for CDN domain. As I know, the resolved ip for a CDN domain is vary from geographic to geographic.It does not work to place the detection code on a particular server.

JavaScript does not have such thing besides basic client IP. So I tried using Actioncript, and turn out that AS# does has net package, and sadly it works on AIR 2 but Flash. So my boss throw out an idea to look for the information through Java Applet. In my mind, Java Applet is evil, which crash my browser in old time, making my computer run slower. Despite that, I know Java Applet should be able to do this job.

My approach is that: Java Applet run on JVM, which should be able to get the information on client side. I search for example and find the following code should help me get the resolved domain ip:

InetAddress thisIp = java.net.InetAddress.getByName(“{cdn.domain.com}”);
String ip = thisIp.getHostAddress();

I can run the code, generate the .class file. But I fail to make it runs in browser no matter how I try. Until I find out the Java control panel and the console log. I get the reason why it stop working:

java.security.AccessControlException: access denied (java.net.SocketPermission cdn.domain.com resolve)

Well, definitely I try to test a valid CDN domain URL, however it just keep saying the access denied. Due to the knowledge about Flash cross domain experience, I know this should be something about foreign domain issue. So I try to change the domain that I try to look up from CDN domain to my blog domain or some URL with gordon-chan.net as domain (the domain that host the code), and the result is: work!!! Which mean, if I host the code and test the domain that hosting that code, it should not be any problem.

How about if it has to look up a foreign domain? I am not sure but here has a website talk about keystore or cert that may help working out the purpose:

http://www.khattam.info/solved-java-security-accesscontrolexception-access-denied-java-net-socketpermission-host-connectresolve-2010-03-24.html

 Update (29 Sep 2012): I notice there are lots of traffic to this blog, I appreciate if you could share what problem you are facing and does my post provide more hint to you?

Be Sociable, Share!

Leave a Reply

Your email address will not be published. Required fields are marked *

Please Answer * Time limit is exhausted. Please reload CAPTCHA.