internal PermissionSetEnumeratorInternal(PermissionSet permSet) { this.m_permSet = permSet; this.enm = new TokenBasedSetEnumerator(permSet.m_permSet); }
private static void CheckTokenBasedSetHelper(bool ignoreGrants, TokenBasedSet grants, TokenBasedSet denied, TokenBasedSet demands) { if (demands == null) { return; } TokenBasedSetEnumerator enumerator = (TokenBasedSetEnumerator)demands.GetEnum(); while (enumerator.MoveNext()) { CodeAccessPermission demand = (CodeAccessPermission)enumerator.Current; int index = enumerator.GetCurrentIndex(); if (demand != null) { try { // Check to make sure the permission was granted, unless we are supposed // to ignore grants. if (!ignoreGrants) { CodeAccessPermission grant = grants != null ? (CodeAccessPermission)grants.GetItem(index) : null; if (grant != null) { grant.CheckDemand(demand); } else { if (!demand.IsSubsetOf(null)) { throw new SecurityException(String.Format(Environment.GetResourceString("Security_Generic"), demand.GetType().AssemblyQualifiedName), demand.GetType(), demand.ToXml().ToString()); } } } // Check to make sure our permission was not denied. if (denied != null) { CodeAccessPermission deny = (CodeAccessPermission)denied.GetItem(index); if (deny != null && deny.Intersect(demand) != null) { throw new SecurityException(String.Format(Environment.GetResourceString("Security_Generic"), demand.GetType().AssemblyQualifiedName), demand.GetType(), demand.ToXml().ToString()); } } } catch (Exception e) { // Any exception besides a security exception in this code means that // a permission was unable to properly handle what we asked of it. // We will define this to mean that the demand failed. if (e is SecurityException) { throw e; } else { throw new SecurityException(String.Format(Environment.GetResourceString("Security_Generic"), demand.GetType().AssemblyQualifiedName), demand.GetType(), demand.ToXml().ToString()); } } } } }