38
38
package java.security;
40
import gnu.classpath.SystemProperties;
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
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}.
49
* <p>Every class in the system will belong to one and only one
50
* <code>ProtectionDomain</code>.</p>
53
52
* @author Aaron M. Renn (arenn@urbanophile.com)
71
70
private boolean staticBinding;
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
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
80
* The {@link CodeSource} for this domain.
82
* The set of permissions for this domain.
83
* @see PermissionCollection#setReadOnly()
84
85
public ProtectionDomain(CodeSource codesource, PermissionCollection permissions)
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>
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>
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.
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>
100
* The {@link CodeSource} for this domain.
102
* The permission set for this domain.
104
* the ClassLoader associated with this domain.
106
* the array of {@link Principal}s associated with this domain.
109
* @see Policy#refresh()
110
* @see Policy#getPermissions(ProtectionDomain)
108
* @see PermissionCollection#setReadOnly()
112
110
public ProtectionDomain(CodeSource codesource,
113
111
PermissionCollection permissions,
114
112
ClassLoader classloader, Principal[] principals)
163
* Returns an array of principals for this domain.
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.
162
* @return a clone of the {@link Principal}s of this domain.
169
165
public final Principal[] getPrincipals()
175
* Returns the static permissions granted to this domain.
177
* @return the static set of permissions for this domain which may be
179
* @see Policy#refresh()
180
* @see Policy#getPermissions(ProtectionDomain)
171
* Returns the {@link PermissionCollection} of this domain.
173
* @return The {@link PermissionCollection} of this domain.
182
175
public final PermissionCollection getPermissions()
188
* <p>Check and see if this <code>ProtectionDomain</code> implies the
189
* permissions expressed in the <code>Permission</code> object.</p>
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>
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>
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.
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.
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.
209
189
public boolean implies(Permission permission)
219
* Convert a <code>ProtectionDomain</code> to a String.
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.
202
* @return A string representation of this object.
223
204
public String toString()
225
String linesep = System.getProperty("line.separator");
206
String linesep = SystemProperties.getProperty("line.separator");
226
207
StringBuffer sb = new StringBuffer("ProtectionDomain (").append(linesep);
228
209
if (code_source == null)