~ubuntu-branches/ubuntu/precise/classpath/precise

« back to all changes in this revision

Viewing changes to java/security/ProtectionDomain.java

  • Committer: Bazaar Package Importer
  • Author(s): Michael Koch
  • Date: 2006-05-27 16:11:15 UTC
  • mfrom: (1.1.3 upstream)
  • Revision ID: james.westby@ubuntu.com-20060527161115-h6e39eposdt5snb6
Tags: 2:0.91-3
* Install header files to /usr/include/classpath.
* debian/control: classpath: Conflict with jamvm < 1.4.3 and
  cacao < 0.96 (Closes: #368172).

Show diffs side-by-side

added added

removed removed

Lines of Context:
37
37
 
38
38
package java.security;
39
39
 
 
40
import gnu.classpath.SystemProperties;
 
41
 
40
42
/**
41
 
 * <p>This <code>ProtectionDomain</code> class encapsulates the characteristics
42
 
 * of a domain, which encloses a set of classes whose instances are granted a
43
 
 * set of permissions when being executed on behalf of a given set of
44
 
 * <i>Principals</i>.
45
 
 *
46
 
 * <p>A static set of permissions can be bound to a <code>ProtectionDomain</code>
47
 
 * when it is constructed; such permissions are granted to the domain regardless
48
 
 * of the {@link Policy} in force. However, to support dynamic security
49
 
 * policies, a <code>ProtectionDomain</code> can also be constructed such that
50
 
 * it is dynamically mapped to a set of permissions by the current {@link
51
 
 * Policy} whenever a permission is checked.</p>
 
43
 * This class represents a group of classes, along with their granted
 
44
 * permissions. The classes are identified by a {@link CodeSource}. Thus, any
 
45
 * class loaded from the specified {@link CodeSource} is treated as part of
 
46
 * this domain. The set of permissions is represented by an instance of
 
47
 * {@link PermissionCollection}.
 
48
 * 
 
49
 * <p>Every class in the system will belong to one and only one
 
50
 * <code>ProtectionDomain</code>.</p>
52
51
 *
53
52
 * @author Aaron M. Renn (arenn@urbanophile.com)
54
53
 * @version 0.0
71
70
  private boolean staticBinding;
72
71
 
73
72
  /**
74
 
   * Creates a new <code>ProtectionDomain</code> with the given {@link
75
 
   * CodeSource} and {@link Permissions}. If the permissions object is not
76
 
   * <code>null</code>, then <code>setReadOnly()</code> will be called on the
77
 
   * passed in {@link Permissions} object. The only permissions granted to this
78
 
   * domain are the ones specified; the current {@link Policy} will not be
79
 
   * consulted.
80
 
   *
81
 
   * @param codesource the codesource associated with this domain.
82
 
   * @param permissions the permissions granted to this domain
 
73
   * Initializes a new instance of <code>ProtectionDomain</code> representing
 
74
   * the specified {@link CodeSource} and set of permissions. No permissions
 
75
   * can be added later to the {@link PermissionCollection} and this contructor
 
76
   * will call the <code>setReadOnly</code> method on the specified set of
 
77
   * permissions.
 
78
   * 
 
79
   * @param codesource
 
80
   *          The {@link CodeSource} for this domain.
 
81
   * @param permissions
 
82
   *          The set of permissions for this domain.
 
83
   * @see PermissionCollection#setReadOnly()
83
84
   */
84
85
  public ProtectionDomain(CodeSource codesource, PermissionCollection permissions)
85
86
  {
87
88
  }
88
89
 
89
90
  /**
90
 
   * <p>Creates a new ProtectionDomain qualified by the given CodeSource,
91
 
   * Permissions, ClassLoader and array of Principals. If the permissions
92
 
   * object is not null, then <code>setReadOnly()</code> will be called on the
93
 
   * passed in Permissions object. The permissions granted to this domain are
94
 
   * dynamic; they include both the static permissions passed to this
95
 
   * constructor, and any permissions granted to this domain by the current
96
 
   * Policy at the time a permission is checked.</p>
97
 
   *
98
 
   * <p>This constructor is typically used by {@link ClassLoader}s and {@link
99
 
   * DomainCombiner}s which delegate to <code>Policy</code> to actively
100
 
   * associate the permissions granted to this domain. This constructor affords
101
 
   * the Policy provider the opportunity to augment the supplied
102
 
   * PermissionCollection to reflect policy changes.</p>
103
 
   *
104
 
   * @param codesource the CodeSource associated with this domain.
105
 
   * @param permissions the permissions granted to this domain.
106
 
   * @param classloader the ClassLoader associated with this domain.
107
 
   * @param principals the array of Principals associated with this domain.
 
91
   * This method initializes a new instance of <code>ProtectionDomain</code>
 
92
   * given its {@link CodeSource}, granted permissions, associated
 
93
   * {@link ClassLoader} and {@link Principal}s.
 
94
   * 
 
95
   * <p>Similar to the previous constructor, if the designated set of
 
96
   * permissions is not <code>null</code>, the <code>setReadOnly</code> method
 
97
   * is called on that set.</p>
 
98
   * 
 
99
   * @param codesource
 
100
   *          The {@link CodeSource} for this domain.
 
101
   * @param permissions
 
102
   *          The permission set for this domain.
 
103
   * @param classloader
 
104
   *          the ClassLoader associated with this domain.
 
105
   * @param principals
 
106
   *          the array of {@link Principal}s associated with this domain.
108
107
   * @since 1.4
109
 
   * @see Policy#refresh()
110
 
   * @see Policy#getPermissions(ProtectionDomain)
111
 
  */
 
108
   * @see PermissionCollection#setReadOnly()
 
109
   */
112
110
  public ProtectionDomain(CodeSource codesource,
113
111
                          PermissionCollection permissions,
114
112
                          ClassLoader classloader, Principal[] principals)
138
136
 
139
137
  /**
140
138
   * Returns the {@link CodeSource} of this domain.
141
 
   *
142
 
   * @return the {@link CodeSource} of this domain which may be <code>null</code>.
 
139
   * 
 
140
   * @return the {@link CodeSource} of this domain.
143
141
   * @since 1.2
144
142
   */
145
143
  public final CodeSource getCodeSource()
149
147
 
150
148
  /**
151
149
   * Returns the {@link ClassLoader} of this domain.
152
 
   *
153
 
   * @return the {@link ClassLoader} of this domain which may be
154
 
   * <code>null</code>.
 
150
   * 
 
151
   * @return the {@link ClassLoader} of this domain.
155
152
   * @since 1.4
156
153
   */
157
154
  public final ClassLoader getClassLoader()
160
157
  }
161
158
 
162
159
  /**
163
 
   * Returns an array of principals for this domain.
164
 
   *
165
 
   * @return returns a non-null array of principals for this domain. Changes to
166
 
   * this array will have no impact on the <code>ProtectionDomain</code>.
 
160
   * Returns a clone of the {@link Principal}s of this domain.
 
161
   * 
 
162
   * @return a clone of the {@link Principal}s of this domain.
167
163
   * @since 1.4
168
164
   */
169
165
  public final Principal[] getPrincipals()
172
168
  }
173
169
 
174
170
  /**
175
 
   * Returns the static permissions granted to this domain.
176
 
   *
177
 
   * @return the static set of permissions for this domain which may be
178
 
   * <code>null</code>.
179
 
   * @see Policy#refresh()
180
 
   * @see Policy#getPermissions(ProtectionDomain)
 
171
   * Returns the {@link PermissionCollection} of this domain.
 
172
   * 
 
173
   * @return The {@link PermissionCollection} of this domain.
181
174
   */
182
175
  public final PermissionCollection getPermissions()
183
176
  {
185
178
  }
186
179
 
187
180
  /**
188
 
   * <p>Check and see if this <code>ProtectionDomain</code> implies the
189
 
   * permissions expressed in the <code>Permission</code> object.</p>
190
 
   *
191
 
   * <p>The set of permissions evaluated is a function of whether the
192
 
   * <code>ProtectionDomain</code> was constructed with a static set of
193
 
   * permissions or it was bound to a dynamically mapped set of permissions.</p>
194
 
   *
195
 
   * <p>If the <code>ProtectionDomain</code> was constructed to a statically
196
 
   * bound {@link PermissionCollection} then the permission will only be checked
197
 
   * against the {@link PermissionCollection} supplied at construction.</p>
198
 
   *
199
 
   * <p>However, if the <code>ProtectionDomain</code> was constructed with the
200
 
   * constructor variant which supports dynamically binding permissions, then
201
 
   * the permission will be checked against the combination of the
202
 
   * {@link PermissionCollection} supplied at construction and the current
203
 
   * {@link Policy} binding.
204
 
   *
205
 
   * @param permission the {@link Permission} object to check.
206
 
   * @return <code>true</code> if <code>permission</code> is implicit to this
207
 
   * <code>ProtectionDomain</code>.
 
181
   * Tests whether or not the specified {@link Permission} is implied by the
 
182
   * set of permissions granted to this domain.
 
183
   * 
 
184
   * @param permission
 
185
   *          the {@link Permission} to test.
 
186
   * @return <code>true</code> if the specified {@link Permission} is implied
 
187
   *         for this domain, <code>false</code> otherwise.
208
188
   */
209
189
  public boolean implies(Permission permission)
210
190
  {
216
196
  }
217
197
 
218
198
  /**
219
 
   * Convert a <code>ProtectionDomain</code> to a String.
220
 
   *
221
 
   * @return a string representation of the object.
 
199
   * Returns a string representation of this object. It will include the
 
200
   * {@link CodeSource} and set of permissions associated with this domain.
 
201
   * 
 
202
   * @return A string representation of this object.
222
203
   */
223
204
  public String toString()
224
205
  {
225
 
    String linesep = System.getProperty("line.separator");
 
206
    String linesep = SystemProperties.getProperty("line.separator");
226
207
    StringBuffer sb = new StringBuffer("ProtectionDomain (").append(linesep);
227
208
 
228
209
    if (code_source == null)