102 /* the rights this protection domain is granted */ 103 private PermissionCollection permissions; 104 105 /* if the permissions object has AllPermission */ 106 private boolean hasAllPerm = false; 107 108 /* the PermissionCollection is static (pre 1.4 constructor) 109 or dynamic (via a policy refresh) */ 110 private boolean staticPermissions; 111 112 /* 113 * An object used as a key when the ProtectionDomain is stored in a Map. 114 */ 115 final Key key = new Key(); 116 117 private static final Debug debug = Debug.getInstance("domain"); 118 119 /** 120 * Creates a new ProtectionDomain with the given CodeSource and 121 * Permissions. If the permissions object is not null, then 122 * <code>setReadOnly())</code> will be called on the passed in 123 * Permissions object. The only permissions granted to this domain 124 * are the ones specified; the current Policy will not be consulted. 125 * 126 * @param codesource the codesource associated with this domain 127 * @param permissions the permissions granted to this domain 128 */ 129 public ProtectionDomain(CodeSource codesource, 130 PermissionCollection permissions) { 131 this.codesource = codesource; 132 if (permissions != null) { 133 this.permissions = permissions; 134 this.permissions.setReadOnly(); 135 if (permissions instanceof Permissions && 136 ((Permissions)permissions).allPermission != null) { 137 hasAllPerm = true; 138 } 139 } 140 this.classloader = null; 141 this.principals = new Principal[0]; 142 staticPermissions = true; 143 } 144 145 /** 146 * Creates a new ProtectionDomain qualified by the given CodeSource, 147 * Permissions, ClassLoader and array of Principals. If the 148 * permissions object is not null, then <code>setReadOnly()</code> 149 * will be called on the passed in Permissions object. 150 * The permissions granted to this domain are dynamic; they include 151 * both the static permissions passed to this constructor, and any 152 * permissions granted to this domain by the current Policy at the 153 * time a permission is checked. 154 * <p> 155 * This constructor is typically used by 156 * {@link SecureClassLoader ClassLoaders} 157 * and {@link DomainCombiner DomainCombiners} which delegate to 158 * <code>Policy</code> to actively associate the permissions granted to 159 * this domain. This constructor affords the 160 * Policy provider the opportunity to augment the supplied 161 * PermissionCollection to reflect policy changes. 162 * <p> 163 * 164 * @param codesource the CodeSource associated with this domain 165 * @param permissions the permissions granted to this domain 166 * @param classloader the ClassLoader associated with this domain 167 * @param principals the array of Principals associated with this 168 * domain. The contents of the array are copied to protect against 169 * subsequent modification. 170 * @see Policy#refresh 171 * @see Policy#getPermissions(ProtectionDomain) 172 * @since 1.4 173 */ 174 public ProtectionDomain(CodeSource codesource, 175 PermissionCollection permissions, 176 ClassLoader classloader, 177 Principal[] principals) { 178 this.codesource = codesource; | 102 /* the rights this protection domain is granted */ 103 private PermissionCollection permissions; 104 105 /* if the permissions object has AllPermission */ 106 private boolean hasAllPerm = false; 107 108 /* the PermissionCollection is static (pre 1.4 constructor) 109 or dynamic (via a policy refresh) */ 110 private boolean staticPermissions; 111 112 /* 113 * An object used as a key when the ProtectionDomain is stored in a Map. 114 */ 115 final Key key = new Key(); 116 117 private static final Debug debug = Debug.getInstance("domain"); 118 119 /** 120 * Creates a new ProtectionDomain with the given CodeSource and 121 * Permissions. If the permissions object is not null, then 122 * {@code setReadOnly())} will be called on the passed in 123 * Permissions object. The only permissions granted to this domain 124 * are the ones specified; the current Policy will not be consulted. 125 * 126 * @param codesource the codesource associated with this domain 127 * @param permissions the permissions granted to this domain 128 */ 129 public ProtectionDomain(CodeSource codesource, 130 PermissionCollection permissions) { 131 this.codesource = codesource; 132 if (permissions != null) { 133 this.permissions = permissions; 134 this.permissions.setReadOnly(); 135 if (permissions instanceof Permissions && 136 ((Permissions)permissions).allPermission != null) { 137 hasAllPerm = true; 138 } 139 } 140 this.classloader = null; 141 this.principals = new Principal[0]; 142 staticPermissions = true; 143 } 144 145 /** 146 * Creates a new ProtectionDomain qualified by the given CodeSource, 147 * Permissions, ClassLoader and array of Principals. If the 148 * permissions object is not null, then {@code setReadOnly()} 149 * will be called on the passed in Permissions object. 150 * The permissions granted to this domain are dynamic; they include 151 * both the static permissions passed to this constructor, and any 152 * permissions granted to this domain by the current Policy at the 153 * time a permission is checked. 154 * <p> 155 * This constructor is typically used by 156 * {@link SecureClassLoader ClassLoaders} 157 * and {@link DomainCombiner DomainCombiners} which delegate to 158 * {@code Policy} to actively associate the permissions granted to 159 * this domain. This constructor affords the 160 * Policy provider the opportunity to augment the supplied 161 * PermissionCollection to reflect policy changes. 162 * <p> 163 * 164 * @param codesource the CodeSource associated with this domain 165 * @param permissions the permissions granted to this domain 166 * @param classloader the ClassLoader associated with this domain 167 * @param principals the array of Principals associated with this 168 * domain. The contents of the array are copied to protect against 169 * subsequent modification. 170 * @see Policy#refresh 171 * @see Policy#getPermissions(ProtectionDomain) 172 * @since 1.4 173 */ 174 public ProtectionDomain(CodeSource codesource, 175 PermissionCollection permissions, 176 ClassLoader classloader, 177 Principal[] principals) { 178 this.codesource = codesource; |