aboutsummaryrefslogtreecommitdiff
path: root/libjava/java/net/SocketPermission.java
diff options
context:
space:
mode:
Diffstat (limited to 'libjava/java/net/SocketPermission.java')
-rw-r--r--libjava/java/net/SocketPermission.java209
1 files changed, 113 insertions, 96 deletions
diff --git a/libjava/java/net/SocketPermission.java b/libjava/java/net/SocketPermission.java
index 3500617..e9d1402 100644
--- a/libjava/java/net/SocketPermission.java
+++ b/libjava/java/net/SocketPermission.java
@@ -1,5 +1,5 @@
/* SocketPermission.java -- Class modeling permissions for socket operations
- Copyright (C) 1998, 2000, 2001, 2002 Free Software Foundation, Inc.
+ Copyright (C) 1998, 2000, 2001, 2002, 2004 Free Software Foundation, Inc.
This file is part of GNU Classpath.
@@ -41,6 +41,7 @@ import java.io.Serializable;
import java.security.Permission;
import java.security.PermissionCollection;
+
/**
* This class models a specific set of permssions for connecting to a
* host. There are two elements to this, the host/port combination and
@@ -64,18 +65,20 @@ import java.security.PermissionCollection;
* value for a port (respectively) is used by default. Here are some
* examples:
* <p><ul>
- * <li>8080 - Represents port 8080 only
- * <li>2000-3000 - Represents ports 2000 through 3000 inclusive
- * <li>-4000 - Represents ports 0 through 4000 inclusive
- * <li>1024- - Represents ports 1024 through 65535 inclusive
+ * <li>8080 - Represents port 8080 only</li>
+ * <li>2000-3000 - Represents ports 2000 through 3000 inclusive</li>
+ * <li>-4000 - Represents ports 0 through 4000 inclusive</li>
+ * <li>1024- - Represents ports 1024 through 65535 inclusive</li>
* </ul><p>
* The permission list is a comma separated list of individual permissions.
* These individual permissions are:
* <p>
- * accept<br>
- * connect<br>
- * listen<br>
- * resolve<br>
+ * <pre>
+ * accept
+ * connect
+ * listen
+ * resolve
+ * </pre>
* <p>
* The "listen" permission is only relevant if the host is localhost. If
* any permission at all is specified, then resolve permission is implied to
@@ -103,12 +106,12 @@ import java.security.PermissionCollection;
*
* @author Aaron M. Renn (arenn@urbanophile.com)
*/
-public final class SocketPermission extends Permission
- implements Serializable
+public final class SocketPermission extends Permission implements Serializable
{
static final long serialVersionUID = -7204263841984476862L;
// FIXME: Needs serialization work, including readObject/writeObject methods.
+
/**
* A hostname/port combination as described above
*/
@@ -120,7 +123,7 @@ public final class SocketPermission extends Permission
private String actions;
/**
- * Initializes a new instance of <code>SocketPermission</code> with the
+ * Initializes a new instance of <code>SocketPermission</code> with the
* specified host/port combination and actions string.
*
* @param hostport The hostname/port number combination
@@ -136,18 +139,18 @@ public final class SocketPermission extends Permission
/**
* Tests this object for equality against another. This will be true if
- * and only if the passed object is an instance of
- * <code>SocketPermission</code> and both its hostname/port combination
+ * and only if the passed object is an instance of
+ * <code>SocketPermission</code> and both its hostname/port combination
* and permissions string are identical.
*
* @param obj The object to test against for equality
*
- * @return <code>true</code> if object is equal to this object,
+ * @return <code>true</code> if object is equal to this object,
* <code>false</code> otherwise.
*/
public boolean equals(Object obj)
{
- if (!(obj instanceof SocketPermission))
+ if (! (obj instanceof SocketPermission))
return (false);
if (((SocketPermission) obj).hostport.equals(hostport))
@@ -158,7 +161,7 @@ public final class SocketPermission extends Permission
}
/**
- * Returns a hash code value for this object. Overrides the
+ * Returns a hash code value for this object. Overrides the
* <code>Permission.hashCode()</code>.
*
* @return A hash code
@@ -192,21 +195,21 @@ public final class SocketPermission extends Permission
if (actions.indexOf("listen") != -1)
if (found)
- sb.append(",listen");
+ sb.append(",listen");
else
- {
+ {
sb.append("listen");
found = true;
- }
+ }
if (actions.indexOf("accept") != -1)
if (found)
sb.append(",accept");
else
- {
+ {
sb.append("accept");
found = true;
- }
+ }
if (found)
sb.append(",resolve");
@@ -231,25 +234,27 @@ public final class SocketPermission extends Permission
/**
* Returns true if the permission object passed it is implied by the
- * this permission. This will be true if
- * <p><ul>
- * <li>The argument is of type <code>SocketPermission</code>
- * <li>The actions list of the argument are in this object's actions
- * <li>The port range of the argument is within this objects port range
- * <li>The hostname is equal to or a subset of this objects hostname
+ * this permission. This will be true if:
+ *
+ * <ul>
+ * <li>The argument is of type <code>SocketPermission</code></li>
+ * <li>The actions list of the argument are in this object's actions</li>
+ * <li>The port range of the argument is within this objects port range</li>
+ * <li>The hostname is equal to or a subset of this objects hostname</li>
* </ul>
- * <p>
- * The argument's hostname will be a subset of this object's hostname if:
- * <p><ul>
- * <li>The argument's hostname or IP address is equal to this object's.
- * <li>The argument's canonical hostname is equal to this object's.
+ *
+ * <p>The argument's hostname will be a subset of this object's hostname if:</p>
+ *
+ * <ul>
+ * <li>The argument's hostname or IP address is equal to this object's.</li>
+ * <li>The argument's canonical hostname is equal to this object's.</li>
* <li>The argument's canonical name matches this domains hostname with
- * wildcards
+ * wildcards</li>
* </ul>
*
* @param perm The <code>Permission</code> to check against
*
- * @return <code>true</code> if the <code>Permission</code> is implied by
+ * @return <code>true</code> if the <code>Permission</code> is implied by
* this object, <code>false</code> otherwise.
*/
public boolean implies(Permission perm)
@@ -266,72 +271,78 @@ public final class SocketPermission extends Permission
String ourlist = getActions();
String theirlist = p.getActions();
- if (!ourlist.startsWith(theirlist))
+ if (! ourlist.startsWith(theirlist))
return (false);
// Now check ports
- int ourfirstport = 0, ourlastport = 0, theirfirstport = 0, theirlastport =
- 0;
+ int ourfirstport = 0;
+
+ // Now check ports
+ int ourlastport = 0;
+
+ // Now check ports
+ int theirfirstport = 0;
+
+ // Now check ports
+ int theirlastport = 0;
// Get ours
if (hostport.indexOf(":") == -1)
{
- ourfirstport = 0;
- ourlastport = 65535;
+ ourfirstport = 0;
+ ourlastport = 65535;
}
else
{
- // FIXME: Needs bulletproofing.
- // This will dump if hostport if all sorts of bad data was passed to
- // the constructor
- String range = hostport.substring(hostport.indexOf(":") + 1);
- if (range.startsWith("-"))
- ourfirstport = 0;
- else if (range.indexOf("-") == -1)
- ourfirstport = Integer.parseInt(range);
- else
- ourfirstport =
- Integer.parseInt(range.substring(0, range.indexOf("-")));
-
- if (range.endsWith("-"))
- ourlastport = 65535;
- else if (range.indexOf("-") == -1)
- ourlastport = Integer.parseInt(range);
- else
- ourlastport =
- Integer.parseInt(range.
- substring(range.indexOf("-") + 1,
- range.length()));
+ // FIXME: Needs bulletproofing.
+ // This will dump if hostport if all sorts of bad data was passed to
+ // the constructor
+ String range = hostport.substring(hostport.indexOf(":") + 1);
+ if (range.startsWith("-"))
+ ourfirstport = 0;
+ else if (range.indexOf("-") == -1)
+ ourfirstport = Integer.parseInt(range);
+ else
+ ourfirstport =
+ Integer.parseInt(range.substring(0, range.indexOf("-")));
+
+ if (range.endsWith("-"))
+ ourlastport = 65535;
+ else if (range.indexOf("-") == -1)
+ ourlastport = Integer.parseInt(range);
+ else
+ ourlastport =
+ Integer.parseInt(range.substring(range.indexOf("-") + 1,
+ range.length()));
}
// Get theirs
if (p.hostport.indexOf(":") == -1)
{
- theirfirstport = 0;
- ourlastport = 65535;
+ theirfirstport = 0;
+ ourlastport = 65535;
}
else
{
- // This will dump if hostport if all sorts of bad data was passed to
- // the constructor
- String range = p.hostport.substring(hostport.indexOf(":") + 1);
- if (range.startsWith("-"))
- theirfirstport = 0;
- else if (range.indexOf("-") == -1)
- theirfirstport = Integer.parseInt(range);
- else
- theirfirstport =
- Integer.parseInt(range.substring(0, range.indexOf("-")));
-
- if (range.endsWith("-"))
- theirlastport = 65535;
- else if (range.indexOf("-") == -1)
- theirlastport = Integer.parseInt(range);
- else
- theirlastport =
- Integer.parseInt(range.
- substring(range.indexOf("-") + 1,
- range.length()));
+ // This will dump if hostport if all sorts of bad data was passed to
+ // the constructor
+ String range = p.hostport.substring(hostport.indexOf(":") + 1);
+ if (range.startsWith("-"))
+ theirfirstport = 0;
+ else if (range.indexOf("-") == -1)
+ theirfirstport = Integer.parseInt(range);
+ else
+ theirfirstport =
+ Integer.parseInt(range.substring(0, range.indexOf("-")));
+
+ if (range.endsWith("-"))
+ theirlastport = 65535;
+ else if (range.indexOf("-") == -1)
+ theirlastport = Integer.parseInt(range);
+ else
+ theirlastport =
+ Integer.parseInt(range.substring(range.indexOf("-") + 1,
+ range.length()));
}
// Now check them
@@ -339,7 +350,10 @@ public final class SocketPermission extends Permission
return (false);
// Finally we can check the hosts
- String ourhost, theirhost;
+ String ourhost;
+
+ // Finally we can check the hosts
+ String theirhost;
// Get ours
if (hostport.indexOf(":") == -1)
@@ -358,20 +372,23 @@ public final class SocketPermission extends Permission
return (true);
// Try the canonical names
- String ourcanonical = null, theircanonical = null;
+ String ourcanonical = null;
+
+ // Try the canonical names
+ String theircanonical = null;
try
{
- ourcanonical = InetAddress.getByName(ourhost).getHostName();
- theircanonical = InetAddress.getByName(theirhost).getHostName();
+ ourcanonical = InetAddress.getByName(ourhost).getHostName();
+ theircanonical = InetAddress.getByName(theirhost).getHostName();
}
catch (UnknownHostException e)
{
- // Who didn't resolve? Just assume current address is canonical enough
- // Is this ok to do?
- if (ourcanonical == null)
- ourcanonical = ourhost;
- if (theircanonical == null)
- theircanonical = theirhost;
+ // Who didn't resolve? Just assume current address is canonical enough
+ // Is this ok to do?
+ if (ourcanonical == null)
+ ourcanonical = ourhost;
+ if (theircanonical == null)
+ theircanonical = theirhost;
}
if (ourcanonical.equals(theircanonical))
@@ -380,9 +397,9 @@ public final class SocketPermission extends Permission
// Well, last chance. Try for a wildcard
if (ourhost.indexOf("*.") != -1)
{
- String wild_domain = ourhost.substring(ourhost.indexOf("*" + 1));
- if (theircanonical.endsWith(wild_domain))
- return (true);
+ String wild_domain = ourhost.substring(ourhost.indexOf("*" + 1));
+ if (theircanonical.endsWith(wild_domain))
+ return (true);
}
// Didn't make it