Help (Urgent) - Server socket connection problem

Please kindly help.

I tried to connect to my own computer by giving the server IP address and a port number and kept getting an error --(exception occurred during event dispatching:

java.security.AccessControlException: access denied (java.net.SocketPermission).

Please kindly assist

[315 byte] By [matt202] at [2007-9-26 6:45:22]
# 1
Just want to add more...I tried creating sockets by giving my computer name and a port number and I am getting the error while creating the socket..
matt202 at 2007-7-1 16:08:27 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 2

H i Matt

You have not mentioned what type of application you are trying to run. Is it a RMI application or Simple Socket based application?

In any case you have a security exception therefore you must set the security policy allowing clients to connect to your systems.

A good place to start off on secuirty policy files and their configuration is :

http://java.sun.com/products/jdk/1.2/docs/guide/security/permissions.html

Keep me posted on your progress.

Good Luck!

Eshwar Rao

Developer Technical Support

Sun microsystems Inc.

http://www.sun.com/developers/support

Eshwar_indts at 2007-7-1 16:08:27 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 3

Hi,

I'm trying to connect to my own computer.But I am unable to create the socket connection.I'm using Windows 98. First I tried to use my IP address and later I tried to use "localhost" as server and I'm giving port address around 9000.But everytime I'm getting java.net.socketpermission error.Does anybody know how can I solve this problem?

Matty

matt202 at 2007-7-1 16:08:27 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 4

hi this is the error i am having. do i need to work on the policy tool? I don't know how to do this. this happens when i am trying to login to the applet,,,, or is it the username, password problem?

AUTHENTICATING.....

127.0.0.18888

BEFORE AUTHORIZATION

Exception occurred during event dispatching:

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

at java.security.AccessControlContext.checkPermission(AccessControlContext.java:272)

at java.security.AccessController.checkPermission(AccessController.java:399)

at java.lang.SecurityManager.checkPermission(SecurityManager.java:545)

at java.lang.SecurityManager.checkConnect(SecurityManager.java:1044)

at java.net.Socket.<init>(Socket.java:262)

at java.net.Socket.<init>(Socket.java:100)

at webtrics.client.WebtricsClient.send(WebtricsClient.java:195)

at webtrics.ui.LoginApplet$OptionListener.actionPerformed(LoginApplet.java:187)

at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1450)

at javax.swing.AbstractButton$ForwardActionEvents.actionPerformed(AbstractButton.java:1504)

at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:378)

at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:250)

at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:216)

at java.awt.Component.processMouseEvent(Component.java:3717)

at java.awt.Component.processEvent(Component.java:3546)

at java.awt.Container.processEvent(Container.java:1164)

at java.awt.Component.dispatchEventImpl(Component.java:2595)

at java.awt.Container.dispatchEventImpl(Container.java:1213)

at java.awt.Component.dispatchEvent(Component.java:2499)

at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:2451)

at java.awt.LightweightDispatcher.processMouseEvent(Container.java:2216)

at java.awt.LightweightDispatcher.dispatchEvent(Container.java:2125)

at java.awt.Container.dispatchEventImpl(Container.java:1200)

at java.awt.Component.dispatchEvent(Component.java:2499)

at java.awt.EventQueue.dispatchEvent(EventQueue.java:319)

at java.awt.EventDispatchThread.pumpOneEvent(EventDispatchThread.java:103)

at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:93)

at java.awt.EventDispatchThread.run(EventDispatchThread.java:84)

matt202 at 2007-7-1 16:08:28 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 5

Ok, so you have an applet that is trying to connect to your local host. Port you are trying to connect to: 8888.

And you are using Swing which means you have plugin installed, right?

Well, go to your plugin's JRE directory (you can also do this for JDK's JRE as well). I will use windows+jre1.2.2 plugin example for locating the file:

Edit this file:

C:\Program Files\JavaSoft\JRE\1.2\lib\security\java.policy

At the very top of this file, add these 3 lines:

grant {

permission java.security.AllPermission;

};

And try after shutting/restarting browser. if it works, you would want to add a codebase to that persmission setting to restrict access for local machine only.

ashutosh at 2007-7-1 16:08:28 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 6

Hi

Let me surmise what you are trying to do: You are trying to connect to the local machine from an applet so as to authenticate the user from a username/password file.

If this is so, you must note a couple of things. Applets cannot access the local system resources unless they are signed and an unsigned applet can connect only to the server from which it is downloaded.

If I try visualizing your application you are opening a socket to read some data. A better way is to go the RMI way. The applet is downloaded from and connects to an RMI server. The RMI can then load the resource and return the value to your applet. RMI is a better way on other counts as well like ease of development, multithreading issues taken care of and dynamic class loading.

There are a couple of security considerations.

"grant all permission" may be a security hazard so look at the security policy file that comes with your JDK to set socket permissions. By modifying the security policy file you would be setting permissions for all your applications. To selectively set permissions for your application, write a policy file - .policy extension and mention it as a property when you run your server : ex -

java -Djava.secuirty.policy=yourPolicy.policy .......

Keep me posted.

Good Luck!

Eshwar Rao

Developer Technical Support

Sun microsystems INC

http://www.sun.com/developers/support

Eshwar_indts at 2007-7-1 16:08:28 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 7

hello once again,

Please we are still having the same problems.

First of all let me ask you some questions:

1. After setting the java policy, where do we save it or put it? We have it in our working folder and also in JDK(Security).. which one should we work on?

2. How do we set it so that localhost can be assesible?

3. We have an applet we are trying to access, is the password, username and company important for authentication?

Please do you have any messenger so that we can chat OR rather u can add me to yahoo: efe_igbide, MSN:eigbide@hotmail.com, ICQ: 105133875 for more assistant.

Find below the errors we got.

AUTHENTICATING.....

localhost9000

BEFORE AUTHORIZATION

After getting into send....

Checking security.......

Accessing accepted

Error opening socket.java.net.ConnectException: Connection refused: connect

IT is okERR - error opening sockets

after AUTHORIZATION

why is it not working

matt202 at 2007-7-1 16:08:28 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 8

hello once again,

Please we are still having the same problems.

First of all let me ask you some questions:

1. After setting the java policy, where do we save it or put it? We have it in our working folder and also in JDK(Security).. which one should we work on?

2. How do we set it so that localhost can be assesible?

3. We have an applet we are trying to access, is the password, username and company important for authentication?

Please do you have any messenger so that we can chat OR rather u can add me to yahoo: efe_igbide, MSN:eigbide@hotmail.com, ICQ: 105133875 for more assistant.

Find below the errors we got.

AUTHENTICATING.....

localhost9000

BEFORE AUTHORIZATION

After getting into send....

Checking security.......

Accessing accepted

Error opening socket.java.net.ConnectException: Connection refused: connect

IT is okERR - error opening sockets

after AUTHORIZATION

why is it not working

matt202 at 2007-7-1 16:08:28 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 9

* I don't have this problem if I use host=localhost,

but if I use the PC's host=(pc's-IP)

- It returns this:

java.security.AccessControlException: access denied (java.net.SocketPermission 172 resolve)

- All Policy Permissions seem to be setup correctly (All Permissions)

for the Class file using the Socket.

- I even tried :

grant {

permission java.security.AllPermission;

};

grant codeBase "file:/Demo/*" {

permission java.net.SocketPermission "172.16.1.57:7070", "resolve,connect,accept";

permission java.net.SocketPermission "172.16.1.57:172", "resolve,connect,accept";

};

-but I still get back the same Socket Access Denied.

- The Class file does Not give me any Security problem though.

jlsilicon at 2007-7-1 16:08:28 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...