tags:

views:

150

answers:

3

I have this code but when I run it I get an exception:

java.security.AccessControlException: access denied (java.net.SocketPermission 127.0.0.1:8081 connect,resolve)

This is the code, the server is running good, but the client doesn't work.

<OBJECT classid="clsid:8AD9C840-044E-11D1-B3E9-00805F499D93"
    width="615" height="360" 
    codebase="http://java.sun.com/products/plugin/autodl/jinstall-1_4-windows-i586.cab#Version=1,4,0,mn"&gt;
  <PARAM name="code" value="client/LlamaChat.class">
  <PARAM name="archive" value="LlamaChat.jar">
  <PARAM name="type" value="application/x-java-applet;version=1.4">
  <PARAM name="scriptable" value="true">
  <PARAM name="username" value="[replace with username]">
  <PARAM name="port" value="[replace with port]">
<COMMENT>
<EMBED type="application/x-java-applet;version=1.4" 
   width="615" height="360" 
   code="client/LlamaChat.class" archive="LlamaChat.jar"
   pluginspage="http://java.sun.com/j2se/1.4.1/download.html"
 username="nis"
 port="8081"
    <NOEMBED>
        No Java 1.4 plugin
    </NOEMBED></EMBED>
</COMMENT>
     </OBJECT>

This is the all error message:

java.security.AccessControlException: access denied (java.net.SocketPermission 127.0.0.1:8081 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 sun.plugin2.applet.Applet2SecurityManager.checkConnect(Unknown Source)
at java.net.Socket.connect(Unknown Source)
at com.sun.net.ssl.internal.ssl.SSLSocketImpl.connect(Unknown Source)
at com.sun.net.ssl.internal.ssl.SSLSocketImpl.<init>(Unknown Source)
at com.sun.net.ssl.internal.ssl.SSLSocketFactoryImpl.createSocket(Unknown Source)
at client.ServerConnection.<init>(Unknown Source)
at client.LlamaChat.connect(Unknown Source)
at client.LlamaChat.init(Unknown Source)
at sun.plugin2.applet.Plugin2Manager$AppletExecutionRunnable.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)

What is the problem and how I can fix this?

The port I used is 8081.

A: 

There are certain things applets can and can't do. Signed applets are able to do everything you give them permission for, or you have to explicitly grant an applet (or more specifically a host) permission to do a certain action. Opening a port (which is what I assume you are trying to do in your applet code), is one of those things that an applet requires permission to perform.

The best thing to do is to sign the jar the applet is in, and then your browser should prompt you as to what you would like to allow.

James B
can you tell me how to do that?
nisnis84
how do i sign the jar file?
nisnis84
http://java.sun.com/docs/books/tutorial/deployment/jar/signindex.html
James B
+1  A: 

This is actually a 3rd party applet. Signing is the responsibility of that 3rd party. I am however also not sure if this is caused by being unsigned, it would have given a generic error/warning prior to executing the applet. The exception can have another cause, e.g. a wrong username or port or configuration. I would just consult the documentation once again and if in vain, just report it to the responsible vendor.

The applet itself also look pretty ancient. Targeted on the vintage Java 1.4 and for the last time updated over 2500 days ago. The HTML example also contains a defacto deprecated <embed> element. I doubt if the vendor will respond on support requests. I would look for a more recent one. I can't recommend straight one (I never used any of them), but I would recommend to pay attention to the maintenance history, the last release date and the available documentation (how to configure/use it and so on).

BalusC
ok, thanks alot!!!
nisnis84
A: 

Have you got the matching server running?

If you used an example like this one, check that you properly entered username, port, site, and location - in the link and in your code, username is set twice and site is not set. The port is set to [replace with port] which is not right, and the hostname is set first to [replace with username] which is not right either.

I suspect the second time username is being set is where the servername should be set, but I don't know anything about this applet. Try using this code, but first replace all 4 values in the [square brackets]:

<OBJECT classid="clsid:8AD9C840-044E-11D1-B3E9-00805F499D93"
    width="615" height="360" 
    codebase="http://java.sun.com/products/plugin/autodl/jinstall-1_4-windows-i586.cab#Version=1,4,0,mn"&gt;
  <PARAM name="code" value="client/LlamaChat.class">
  <PARAM name="archive" value="LlamaChat.jar">
  <PARAM name="type" value="application/x-java-applet;version=1.4">
  <PARAM name="scriptable" value="true">
  <PARAM name="username" value="[replace with username]">
  <PARAM name="port" value="[replace with port]">
<COMMENT>
<EMBED type="application/x-java-applet;version=1.4" 
   width="615" height="360" 
   code="client/LlamaChat.class" archive="LlamaChat.jar"
   pluginspage="http://java.sun.com/j2se/1.4.1/download.html"
 site="[replace with site]"
 port="[replace with port]"
    <NOEMBED>
        No Java 1.4 plugin
    </NOEMBED></EMBED>
</COMMENT>
     </OBJECT>
Colin Pickard