Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to understand java Socket-Permissions?

permission java.net.SocketPermission "192.168.1.1:31337", "connect, accept, resolve";

What does the following permission allow? Is my Application allowed to accept connections only from 192.168.1.1:31337 (maybe an external client) or to accept connections on to 192.168.1.1:31337 (my application is running on 192.168.1.1:31337, where is the difference to 'listen'?).

like image 515
lazydaemon Avatar asked Sep 05 '12 14:09

lazydaemon


People also ask

What is socket permission?

This class represents access to a network via sockets. A SocketPermission consists of a host specification and a set of "actions" specifying ways to connect to that host.

How do you handle a socket in Java?

Java socket server example Create a ServerSocket , specifying a port to listen on. Invoke the ServerSocket 's accept() method to listen on the configured port for a client connection. When a client connects to the server, the accept() method returns a Socket through which the server can communicate with the client.

What is permission in Java?

A permission represents access to a system resource. In order for a resource access to be allowed for an applet (or an application running with a security manager), the corresponding permission must be explicitly granted to the code attempting the access.

How do I grant permissions in Java security AllPermission?

The AllPermission is a permission that implies all other permissions. Note: Granting AllPermission should be done with extreme care, as it implies all other permissions. Thus, it grants code the ability to run with security disabled. Extreme caution should be taken before granting such a permission to code.


1 Answers

If your code is an applet or running under a java security manager you need to explicitly grant it permissions to do stuff.

In order for a resource access to be allowed for an applet (or an application running with a security manager), the corresponding permission must be explicitly granted to the code attempting the access.

By default your code has no socket permission. Your permission says that your code has the permission to accept connection on, to connect to and to resolve only the host with IP 192.168.1.1 on port 31337.

The "accept" and "connect" actions are obvious.

The "resolve" action is implied when any of the other actions are present. The action "resolve" refers to host/ip name service lookups.

The "listen" action is only meaningful when used with "localhost".

The difference between listen and accept is that listening means "be prepared for connection and see if there is a connection waiting" and accepting means "ok, accept it".

See the docs for permissions in java 7. and java.net.SocketPermission java docs

like image 108
dcernahoschi Avatar answered Oct 06 '22 19:10

dcernahoschi