/// <summary> /// add static permissions to provided permission collection /// </summary> private void AddStaticPerms(PermissionCollection perms, PermissionCollection statics) { if (statics != null) { lock (statics) { IEnumerator <Permission> e = statics.Elements(); while (e.MoveNext()) { perms.Add(e.Current); } } } }
/// <summary> /// Return a PermissionCollection object containing the set of /// permissions granted to the specified ProtectionDomain. /// /// <para> Applications are discouraged from calling this method /// since this operation may not be supported by all policy implementations. /// Applications should rely on the {@code implies} method /// to perform policy checks. /// /// </para> /// <para> The default implementation of this method first retrieves /// the permissions returned via {@code getPermissions(CodeSource)} /// (the CodeSource is taken from the specified ProtectionDomain), /// as well as the permissions located inside the specified ProtectionDomain. /// All of these permissions are then combined and returned in a new /// PermissionCollection object. If {@code getPermissions(CodeSource)} /// returns Policy.UNSUPPORTED_EMPTY_COLLECTION, then this method /// returns the permissions contained inside the specified ProtectionDomain /// in a new PermissionCollection object. /// /// </para> /// <para> This method can be overridden if the policy implementation /// supports returning a set of permissions granted to a ProtectionDomain. /// /// </para> /// </summary> /// <param name="domain"> the ProtectionDomain to which the returned /// PermissionCollection has been granted. /// </param> /// <returns> a set of permissions granted to the specified ProtectionDomain. /// If this operation is supported, the returned /// set of permissions must be a new mutable instance /// and it must support heterogeneous Permission types. /// If this operation is not supported, /// Policy.UNSUPPORTED_EMPTY_COLLECTION is returned. /// /// @since 1.4 </returns> public virtual PermissionCollection GetPermissions(ProtectionDomain domain) { PermissionCollection pc = null; if (domain == null) { return(new Permissions()); } if (PdMapping == null) { InitPolicy(this); } lock (PdMapping) { pc = PdMapping.Get(domain.Key); } if (pc != null) { Permissions perms = new Permissions(); lock (pc) { for (IEnumerator <Permission> e = pc.Elements(); e.MoveNext();) { perms.Add(e.Current); } } return(perms); } pc = GetPermissions(domain.CodeSource); if (pc == null || pc == UNSUPPORTED_EMPTY_COLLECTION) { pc = new Permissions(); } AddStaticPerms(pc, domain.Permissions); return(pc); }