Question about Java SocketPermission Policy

I have a client and server program that are trying to communicate with each other. In my server policy file, I specified the following:

grant signedBy "vivin" {
  permission java.io.FilePermission "-", "read, write";
  permission java.net.SocketPermission "localhost:2220-2230", "accept, connect, listen, resolve", signedBy "vivin";
};

And in my client policy file, I:

grant signedBy "vivin" {
  permission java.net.SocketPermission "localhost:2220-2230", "accept, connect, listen, resolve", signedBy "vivin";
};

I start my server and it listens on port 2225. Then I start my client and tries to connect to the server that listens on port 2225. Unfortunately, I get this error on the server:

[java] Exception in thread "main" java.security.AccessControlException: access denied (java.net.SocketPermission 127.0.0.1:45944 accept,resolve)
[java]  at java.security.AccessControlContext.checkPermission(AccessControlContext.java:323)
[java]  at java.security.AccessController.checkPermission(AccessController.java:546)
[java]  at java.lang.SecurityManager.checkPermission(SecurityManager.java:532)
[java]  at java.lang.SecurityManager.checkAccept(SecurityManager.java:1157)
[java]  at java.net.ServerSocket.implAccept(ServerSocket.java:457)
[java]  at java.net.ServerSocket.accept(ServerSocket.java:421)

The port number continues to change; I assume this is the port number for the client (where does the server connect back to the client?). It's right? There is a restriction on port numbers for this purpose:

Java, , . , 2220-2230.

? , ? , , accept resolve 2231. , .

+3
1

tcp- ( ), :

grant signedBy "vivin" {
  permission java.net.SocketPermission "localhost:1024-", "connect, resolve", signedBy "vivin";
};

"" "". , , "", tcp.

+5

Source: https://habr.com/ru/post/1774451/


All Articles