source: trunk/src/gcc/libjava/java/net/SocketPermission.java@ 2228

Last change on this file since 2228 was 1392, checked in by bird, 22 years ago

This commit was generated by cvs2svn to compensate for changes in r1391,
which included commits to RCS files with non-trunk default branches.

  • Property cvs2svn:cvs-rev set to 1.1.1.2
  • Property svn:eol-style set to native
  • Property svn:executable set to *
File size: 11.9 KB
Line 
1/* SocketPermission.java -- Class modeling permissions for socket operations
2 Copyright (C) 1998, 2000, 2001, 2002 Free Software Foundation, Inc.
3
4This file is part of GNU Classpath.
5
6GNU Classpath is free software; you can redistribute it and/or modify
7it under the terms of the GNU General Public License as published by
8the Free Software Foundation; either version 2, or (at your option)
9any later version.
10
11GNU Classpath is distributed in the hope that it will be useful, but
12WITHOUT ANY WARRANTY; without even the implied warranty of
13MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14General Public License for more details.
15
16You should have received a copy of the GNU General Public License
17along with GNU Classpath; see the file COPYING. If not, write to the
18Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
1902111-1307 USA.
20
21Linking this library statically or dynamically with other modules is
22making a combined work based on this library. Thus, the terms and
23conditions of the GNU General Public License cover the whole
24combination.
25
26As a special exception, the copyright holders of this library give you
27permission to link this library with independent modules to produce an
28executable, regardless of the license terms of these independent
29modules, and to copy and distribute the resulting executable under
30terms of your choice, provided that you also meet, for each linked
31independent module, the terms and conditions of the license of that
32module. An independent module is a module which is not derived from
33or based on this library. If you modify this library, you may extend
34this exception to your version of the library, but you are not
35obligated to do so. If you do not wish to do so, delete this
36exception statement from your version. */
37
38package java.net;
39
40import java.io.Serializable;
41import java.security.Permission;
42import java.security.PermissionCollection;
43
44/**
45 * This class models a specific set of permssions for connecting to a
46 * host. There are two elements to this, the host/port combination and
47 * the permission list.
48 * <p>
49 * The host/port combination is specified as followed
50 * <p>
51 * <pre>
52 * hostname[:[-]port[-[port]]]
53 * </pre>
54 * <p>
55 * The hostname portion can be either a hostname or IP address. If it is
56 * a hostname, a wildcard is allowed in hostnames. This wildcard is a "*"
57 * and matches one or more characters. Only one "*" may appear in the
58 * host and it must be the leftmost character. For example,
59 * "*.urbanophile.com" matches all hosts in the "urbanophile.com" domain.
60 * <p>
61 * The port portion can be either a single value, or a range of values
62 * treated as inclusive. The first or the last port value in the range
63 * can be omitted in which case either the minimum or maximum legal
64 * value for a port (respectively) is used by default. Here are some
65 * examples:
66 * <p><ul>
67 * <li>8080 - Represents port 8080 only
68 * <li>2000-3000 - Represents ports 2000 through 3000 inclusive
69 * <li>-4000 - Represents ports 0 through 4000 inclusive
70 * <li>1024- - Represents ports 1024 through 65535 inclusive
71 * </ul><p>
72 * The permission list is a comma separated list of individual permissions.
73 * These individual permissions are:
74 * <p>
75 * accept<br>
76 * connect<br>
77 * listen<br>
78 * resolve<br>
79 * <p>
80 * The "listen" permission is only relevant if the host is localhost. If
81 * any permission at all is specified, then resolve permission is implied to
82 * exist.
83 * <p>
84 * Here are a variety of examples of how to create SocketPermission's
85 * <p><pre>
86 * SocketPermission("www.urbanophile.com", "connect");
87 * Can connect to any port on www.urbanophile.com
88 * SocketPermission("www.urbanophile.com:80", "connect,accept");
89 * Can connect to or accept connections from www.urbanophile.com on port 80
90 * SocketPermission("localhost:1024-", "listen,accept,connect");
91 * Can connect to, accept from, an listen on any local port number 1024
92 * and up.
93 * SocketPermission("*.edu", "connect");
94 * Can connect to any host in the edu domain
95 * SocketPermission("197.197.20.1", "accept");
96 * Can accept connections from 197.197.20.1
97 * </pre><p>
98 *
99 * @since 1.2
100 *
101 * @author Aaron M. Renn ([email protected])
102 */
103public final class SocketPermission extends Permission
104 implements Serializable
105{
106 static final long serialVersionUID = -7204263841984476862L;
107
108// FIXME: Needs serialization work, including readObject/writeObject methods.
109 /**
110 * A hostname/port combination as described above
111 */
112 private transient String hostport;
113
114 /**
115 * A comma separated list of actions for which we have permission
116 */
117 private String actions;
118
119 /**
120 * Initializes a new instance of <code>SocketPermission</code> with the
121 * specified host/port combination and actions string.
122 *
123 * @param hostport The hostname/port number combination
124 * @param actions The actions string
125 */
126 public SocketPermission(String hostport, String actions)
127 {
128 super(hostport);
129
130 this.hostport = hostport;
131 this.actions = actions;
132 }
133
134 /**
135 * Tests this object for equality against another. This will be true if
136 * and only if the passed object is an instance of
137 * <code>SocketPermission</code> and both its hostname/port combination
138 * and permissions string are identical.
139 *
140 * @param obj The object to test against for equality
141 *
142 * @return <code>true</code> if object is equal to this object,
143 * <code>false</code> otherwise.
144 */
145 public boolean equals(Object obj)
146 {
147 if (obj == null)