All Packages  Class Hierarchy  This Package  Previous  Next  Index  

Class java.net.SocketPermission

java.lang.Object
    |
    +----java.security.Permission
            |
            +----java.net.SocketPermission

public final class SocketPermission
extends Permission
implements Serializable
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. The host is specified as
    host = (hostname | IPaddress)[:portrange]
    portrange = portnumber | portnumber-[portnumber]
 
The possible ways to connect to the host are
 accept
 connect
 listen
 resolve
 
The "listen" action is only meaningful when used with "localhost". The "resolve" (resolve host/ip name service lookups) action is implied when any of the other actions are present.

As an example of the creation and meaning of SocketPermissions, if the following permissions are created for classes signed by mrm:

   p1 = new SocketPermission("puffin.eng.sun.com:7777", "connect,accept");
   p2 = new SocketPermission("localhost:1024-", "accept,connect,listen");
 
then classes signedBy mrm can connect to port 7777 on puffin.eng.sun.com, or accept connections on that port. Classes signedBy mrm may also listen on any port between 1024 and 65535, as well as port 0.

See Also:
Permissions, SocketPermissions

Constructor Index

 o SocketPermission(String, String)
Creates a new SocketPermission object with the specified actions.

Method Index

 o equals(Object)
Checks two SocketPermission objects for equality.
 o getActions()
Returns the canonical string representation of the actions.
 o hashCode()
Returns the hash code value for this object.
 o implies(Permission)
Checks if this socket permission object "implies" the specified permission.
 o newPermissionCollection()
Returns a new PermissionCollection object for storing SocketPermission objects.

Constructors

 o SocketPermission
public SocketPermission(String host,
                        String action)
Creates a new SocketPermission object with the specified actions. The host is expressed as a DNS name, or as a numerical IP address. Optionally, a port or a portrange may be supplied (separated from the DNS name or IP address by a colon).

The actions parameter contains a comma-separated list of the actions granted for the specified host (and port(s)). Possible actions are "connect", "listen", "accept", "resolve", or any combination of those. "resolve" is automatically added when any of the other three are specified.

Examples of SocketPermission instantiation are the following:

    nr = new SocketPermission("www.catalog.com", "connect");
    nr = new SocketPermission("www.sun.com:80", "connect");
    nr = new SocketPermission("*.sun.com", "connect");
    nr = new SocketPermission("*.edu", "resolve");
    nr = new SocketPermission("204.160.241.0", "connect");
    nr = new SocketPermission("localhost:1024-65535", "listen");
    nr = new SocketPermission("204.160.241.0:1024-65535", "connect");
 

Parameters:
host - the hostname or IPaddress of the computer, optionally including a colon followed by a port or port range.
action - the action string.

Methods

 o implies
public boolean implies(Permission p)
Checks if this socket permission object "implies" the specified permission.

More specifically, this method first ensures that all of the following are true (and returns false if any of them are not):

Then implies checks each of the following, in order, and for each returns true if the stated condition is true:

If none of the above are true, implies returns false.

Parameters:
p - the permission to check against.
Returns:
true if the specified permission is implied by this object, false if not.
Overrides:
implies in class Permission
 o equals
public boolean equals(Object obj)
Checks two SocketPermission objects for equality.

Parameters:
obj - the object to test for equality with this object.
Returns:
true if obj is a SocketPermission, and has the same hostname and actions as this SocketPermission object.
Overrides:
equals in class Permission
 o hashCode
public int hashCode()
Returns the hash code value for this object.

Returns:
a hash code value for this object.
Overrides:
hashCode in class Permission
 o getActions
public String getActions()
Returns the canonical string representation of the actions. Always returns present actions in the following order: connect, listen, accept, resolve.

Returns:
the canonical string representation of the actions.
Overrides:
getActions in class Permission
 o newPermissionCollection
public PermissionCollection newPermissionCollection()
Returns a new PermissionCollection object for storing SocketPermission objects.

SocketPermission objects must be stored in a manner that allows them to be inserted into the collection in any order, but that also enables the PermissionCollection implies method to be implemented in an efficient (and consistent) manner.

Returns:
a new PermissionCollection object suitable for storing SocketPermissions.
Overrides:
newPermissionCollection in class Permission

All Packages  Class Hierarchy  This Package  Previous  Next  Index  

Submit a bug or feature