Code:
/ Dotnetfx_Vista_SP2 / Dotnetfx_Vista_SP2 / 8.0.50727.4016 / DEVDIV / depot / DevDiv / releases / whidbey / NetFxQFE / ndp / clr / src / BCL / System / Security / CodeAccessPermission.cs / 1 / CodeAccessPermission.cs
// ==++== // // Copyright (c) Microsoft Corporation. All rights reserved. // // ==--== namespace System.Security { using System.IO; using System.Threading; using System.Security; using System.Security.Util; using System.Security.Permissions; using System.Runtime.CompilerServices; using System.Collections; using System.Text; using System; using IUnrestrictedPermission = System.Security.Permissions.IUnrestrictedPermission; [Serializable, SecurityPermissionAttribute( SecurityAction.InheritanceDemand, ControlEvidence = true, ControlPolicy = true )] [System.Runtime.InteropServices.ComVisible(true)] abstract public class CodeAccessPermission : IPermission, ISecurityEncodable, IStackWalk { // Static methods for manipulation of stack [MethodImplAttribute(MethodImplOptions.NoInlining)] // Methods containing StackCrawlMark local var has to be marked non-inlineable public static void RevertAssert() { StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller; SecurityRuntime.RevertAssert(ref stackMark); } [MethodImplAttribute(MethodImplOptions.NoInlining)] // Methods containing StackCrawlMark local var has to be marked non-inlineable public static void RevertDeny() { StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller; SecurityRuntime.RevertDeny(ref stackMark); } [MethodImplAttribute(MethodImplOptions.NoInlining)] // Methods containing StackCrawlMark local var has to be marked non-inlineable public static void RevertPermitOnly() { StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller; SecurityRuntime.RevertPermitOnly(ref stackMark); } [MethodImplAttribute(MethodImplOptions.NoInlining)] // Methods containing StackCrawlMark local var has to be marked non-inlineable public static void RevertAll() { StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller; SecurityRuntime.RevertAll(ref stackMark); } // // Standard implementation of IPermission methods for // code-access permissions. // // Mark this method as requiring a security object on the caller's frame // so the caller won't be inlined (which would mess up stack crawling). [DynamicSecurityMethodAttribute()] [MethodImplAttribute(MethodImplOptions.NoInlining)] // Methods containing StackCrawlMark local var has to be marked non-inlineable public void Demand() { if (!this.CheckDemand( null )) { StackCrawlMark stackMark = StackCrawlMark.LookForMyCallersCaller; CodeAccessSecurityEngine.Check(this, ref stackMark); } } [DynamicSecurityMethodAttribute()] [MethodImplAttribute(MethodImplOptions.NoInlining)] // Methods containing StackCrawlMark local var has to be marked non-inlineable internal static void DemandInternal(PermissionType permissionType) { StackCrawlMark stackMark = StackCrawlMark.LookForMyCallersCaller; CodeAccessSecurityEngine.SpecialDemand(permissionType, ref stackMark); } // Metadata for this method should be flaged with REQ_SQ so that // EE can allocate space on the stack frame for FrameSecurityDescriptor [DynamicSecurityMethodAttribute()] [MethodImplAttribute(MethodImplOptions.NoInlining)] // Methods containing StackCrawlMark local var has to be marked non-inlineable public void Assert() { StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller; CodeAccessSecurityEngine.Assert(this, ref stackMark); } [DynamicSecurityMethodAttribute()] [MethodImplAttribute(MethodImplOptions.NoInlining)] // Methods containing StackCrawlMark local var has to be marked non-inlineable static internal void AssertAllPossible() { StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller; SecurityRuntime.AssertAllPossible(ref stackMark); } // Metadata for this method should be flaged with REQ_SQ so that // EE can allocate space on the stack frame for FrameSecurityDescriptor [DynamicSecurityMethodAttribute()] [MethodImplAttribute(MethodImplOptions.NoInlining)] // Methods containing StackCrawlMark local var has to be marked non-inlineable public void Deny() { StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller; CodeAccessSecurityEngine.Deny(this, ref stackMark); } // Metadata for this method should be flaged with REQ_SQ so that // EE can allocate space on the stack frame for FrameSecurityDescriptor [DynamicSecurityMethodAttribute()] [MethodImplAttribute(MethodImplOptions.NoInlining)] // Methods containing StackCrawlMark local var has to be marked non-inlineable public void PermitOnly() { StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller; CodeAccessSecurityEngine.PermitOnly(this, ref stackMark); } // IPermission interfaces // We provide a default implementation of Union here. // Any permission that doesn't provide its own representation // of Union will get this one and trigger CompoundPermission // We can take care of simple cases here... public virtual IPermission Union(IPermission other) { // The other guy could be null if (other == null) return(this.Copy()); // otherwise we don't support it. throw new NotSupportedException(Environment.GetResourceString( "NotSupported_SecurityPermissionUnion" )); } static internal SecurityElement CreatePermissionElement( IPermission perm, String permname ) { SecurityElement root = new SecurityElement( "IPermission" ); XMLUtil.AddClassAttribute( root, perm.GetType(), permname ); // If you hit this assert then most likely you are trying to change the name of this class. // This is ok as long as you change the hard coded string above and change the assert below. BCLDebug.Assert( perm.GetType().FullName.Equals( permname ), "Incorrect class name passed in! Was: " + permname + " Should be " + perm.GetType().FullName); root.AddAttribute( "version", "1" ); return root; } static internal void ValidateElement( SecurityElement elem, IPermission perm ) { if (elem == null) throw new ArgumentNullException( "elem" ); if (!XMLUtil.IsPermissionElement( perm, elem )) throw new ArgumentException( Environment.GetResourceString( "Argument_NotAPermissionElement")); String version = elem.Attribute( "version" ); if (version != null && !version.Equals( "1" )) throw new ArgumentException( Environment.GetResourceString( "Argument_InvalidXMLBadVersion") ); } abstract public SecurityElement ToXml(); abstract public void FromXml( SecurityElement elem ); // // Unimplemented interface methods // (as a reminder only) // public override String ToString() { return ToXml().ToString(); } // // HELPERS FOR IMPLEMENTING ABSTRACT METHODS // // // Protected helper // internal bool VerifyType(IPermission perm) { // if perm is null, then obviously not of the same type if ((perm == null) || (perm.GetType() != this.GetType())) { return(false); } else { return(true); } } // The IPermission Interface public abstract IPermission Copy(); public abstract IPermission Intersect(IPermission target); public abstract bool IsSubsetOf(IPermission target); [System.Runtime.InteropServices.ComVisible(false)] public override bool Equals(Object obj) { IPermission perm = obj as IPermission; if(obj != null && perm == null) return false; try { if(!this.IsSubsetOf(perm)) return false; if(perm != null && !perm.IsSubsetOf(this)) return false; } catch (ArgumentException) { // Any argument exception implies inequality // Note that we require a try/catch block here because we have to deal with // custom permissions that may throw exceptions indiscriminately. return false; } return true; } [System.Runtime.InteropServices.ComVisible(false)] public override int GetHashCode() { // This implementation is only to silence a compiler warning. return base.GetHashCode(); } internal bool CheckDemand(CodeAccessPermission grant) { BCLDebug.Assert( grant == null || grant.GetType().Equals( this.GetType() ), "CheckDemand not defined for permissions of different type" ); return IsSubsetOf( grant ); } internal bool CheckPermitOnly(CodeAccessPermission permitted) { BCLDebug.Assert( permitted == null || permitted.GetType().Equals( this.GetType() ), "CheckPermitOnly not defined for permissions of different type" ); return IsSubsetOf( permitted ); } internal bool CheckDeny(CodeAccessPermission denied) { BCLDebug.Assert( denied == null || denied.GetType().Equals( this.GetType() ), "CheckDeny not defined for permissions of different type" ); IPermission intersectPerm = Intersect(denied); return (intersectPerm == null || intersectPerm.IsSubsetOf(null)); } internal bool CheckAssert(CodeAccessPermission asserted) { BCLDebug.Assert( asserted == null || asserted.GetType().Equals( this.GetType() ), "CheckPermitOnly not defined for permissions of different type" ); return IsSubsetOf( asserted ); } internal bool CanUnrestrictedOverride() { return CanUnrestrictedOverride(this); } internal static bool CanUnrestrictedOverride(IPermission ip) { if(CodeAccessSecurityEngine.DoesFullTrustMeanFullTrust()) return true; if(ip is IUnrestrictedPermission) return true; return false; } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. // ==++== // // Copyright (c) Microsoft Corporation. All rights reserved. // // ==--== namespace System.Security { using System.IO; using System.Threading; using System.Security; using System.Security.Util; using System.Security.Permissions; using System.Runtime.CompilerServices; using System.Collections; using System.Text; using System; using IUnrestrictedPermission = System.Security.Permissions.IUnrestrictedPermission; [Serializable, SecurityPermissionAttribute( SecurityAction.InheritanceDemand, ControlEvidence = true, ControlPolicy = true )] [System.Runtime.InteropServices.ComVisible(true)] abstract public class CodeAccessPermission : IPermission, ISecurityEncodable, IStackWalk { // Static methods for manipulation of stack [MethodImplAttribute(MethodImplOptions.NoInlining)] // Methods containing StackCrawlMark local var has to be marked non-inlineable public static void RevertAssert() { StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller; SecurityRuntime.RevertAssert(ref stackMark); } [MethodImplAttribute(MethodImplOptions.NoInlining)] // Methods containing StackCrawlMark local var has to be marked non-inlineable public static void RevertDeny() { StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller; SecurityRuntime.RevertDeny(ref stackMark); } [MethodImplAttribute(MethodImplOptions.NoInlining)] // Methods containing StackCrawlMark local var has to be marked non-inlineable public static void RevertPermitOnly() { StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller; SecurityRuntime.RevertPermitOnly(ref stackMark); } [MethodImplAttribute(MethodImplOptions.NoInlining)] // Methods containing StackCrawlMark local var has to be marked non-inlineable public static void RevertAll() { StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller; SecurityRuntime.RevertAll(ref stackMark); } // // Standard implementation of IPermission methods for // code-access permissions. // // Mark this method as requiring a security object on the caller's frame // so the caller won't be inlined (which would mess up stack crawling). [DynamicSecurityMethodAttribute()] [MethodImplAttribute(MethodImplOptions.NoInlining)] // Methods containing StackCrawlMark local var has to be marked non-inlineable public void Demand() { if (!this.CheckDemand( null )) { StackCrawlMark stackMark = StackCrawlMark.LookForMyCallersCaller; CodeAccessSecurityEngine.Check(this, ref stackMark); } } [DynamicSecurityMethodAttribute()] [MethodImplAttribute(MethodImplOptions.NoInlining)] // Methods containing StackCrawlMark local var has to be marked non-inlineable internal static void DemandInternal(PermissionType permissionType) { StackCrawlMark stackMark = StackCrawlMark.LookForMyCallersCaller; CodeAccessSecurityEngine.SpecialDemand(permissionType, ref stackMark); } // Metadata for this method should be flaged with REQ_SQ so that // EE can allocate space on the stack frame for FrameSecurityDescriptor [DynamicSecurityMethodAttribute()] [MethodImplAttribute(MethodImplOptions.NoInlining)] // Methods containing StackCrawlMark local var has to be marked non-inlineable public void Assert() { StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller; CodeAccessSecurityEngine.Assert(this, ref stackMark); } [DynamicSecurityMethodAttribute()] [MethodImplAttribute(MethodImplOptions.NoInlining)] // Methods containing StackCrawlMark local var has to be marked non-inlineable static internal void AssertAllPossible() { StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller; SecurityRuntime.AssertAllPossible(ref stackMark); } // Metadata for this method should be flaged with REQ_SQ so that // EE can allocate space on the stack frame for FrameSecurityDescriptor [DynamicSecurityMethodAttribute()] [MethodImplAttribute(MethodImplOptions.NoInlining)] // Methods containing StackCrawlMark local var has to be marked non-inlineable public void Deny() { StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller; CodeAccessSecurityEngine.Deny(this, ref stackMark); } // Metadata for this method should be flaged with REQ_SQ so that // EE can allocate space on the stack frame for FrameSecurityDescriptor [DynamicSecurityMethodAttribute()] [MethodImplAttribute(MethodImplOptions.NoInlining)] // Methods containing StackCrawlMark local var has to be marked non-inlineable public void PermitOnly() { StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller; CodeAccessSecurityEngine.PermitOnly(this, ref stackMark); } // IPermission interfaces // We provide a default implementation of Union here. // Any permission that doesn't provide its own representation // of Union will get this one and trigger CompoundPermission // We can take care of simple cases here... public virtual IPermission Union(IPermission other) { // The other guy could be null if (other == null) return(this.Copy()); // otherwise we don't support it. throw new NotSupportedException(Environment.GetResourceString( "NotSupported_SecurityPermissionUnion" )); } static internal SecurityElement CreatePermissionElement( IPermission perm, String permname ) { SecurityElement root = new SecurityElement( "IPermission" ); XMLUtil.AddClassAttribute( root, perm.GetType(), permname ); // If you hit this assert then most likely you are trying to change the name of this class. // This is ok as long as you change the hard coded string above and change the assert below. BCLDebug.Assert( perm.GetType().FullName.Equals( permname ), "Incorrect class name passed in! Was: " + permname + " Should be " + perm.GetType().FullName); root.AddAttribute( "version", "1" ); return root; } static internal void ValidateElement( SecurityElement elem, IPermission perm ) { if (elem == null) throw new ArgumentNullException( "elem" ); if (!XMLUtil.IsPermissionElement( perm, elem )) throw new ArgumentException( Environment.GetResourceString( "Argument_NotAPermissionElement")); String version = elem.Attribute( "version" ); if (version != null && !version.Equals( "1" )) throw new ArgumentException( Environment.GetResourceString( "Argument_InvalidXMLBadVersion") ); } abstract public SecurityElement ToXml(); abstract public void FromXml( SecurityElement elem ); // // Unimplemented interface methods // (as a reminder only) // public override String ToString() { return ToXml().ToString(); } // // HELPERS FOR IMPLEMENTING ABSTRACT METHODS // // // Protected helper // internal bool VerifyType(IPermission perm) { // if perm is null, then obviously not of the same type if ((perm == null) || (perm.GetType() != this.GetType())) { return(false); } else { return(true); } } // The IPermission Interface public abstract IPermission Copy(); public abstract IPermission Intersect(IPermission target); public abstract bool IsSubsetOf(IPermission target); [System.Runtime.InteropServices.ComVisible(false)] public override bool Equals(Object obj) { IPermission perm = obj as IPermission; if(obj != null && perm == null) return false; try { if(!this.IsSubsetOf(perm)) return false; if(perm != null && !perm.IsSubsetOf(this)) return false; } catch (ArgumentException) { // Any argument exception implies inequality // Note that we require a try/catch block here because we have to deal with // custom permissions that may throw exceptions indiscriminately. return false; } return true; } [System.Runtime.InteropServices.ComVisible(false)] public override int GetHashCode() { // This implementation is only to silence a compiler warning. return base.GetHashCode(); } internal bool CheckDemand(CodeAccessPermission grant) { BCLDebug.Assert( grant == null || grant.GetType().Equals( this.GetType() ), "CheckDemand not defined for permissions of different type" ); return IsSubsetOf( grant ); } internal bool CheckPermitOnly(CodeAccessPermission permitted) { BCLDebug.Assert( permitted == null || permitted.GetType().Equals( this.GetType() ), "CheckPermitOnly not defined for permissions of different type" ); return IsSubsetOf( permitted ); } internal bool CheckDeny(CodeAccessPermission denied) { BCLDebug.Assert( denied == null || denied.GetType().Equals( this.GetType() ), "CheckDeny not defined for permissions of different type" ); IPermission intersectPerm = Intersect(denied); return (intersectPerm == null || intersectPerm.IsSubsetOf(null)); } internal bool CheckAssert(CodeAccessPermission asserted) { BCLDebug.Assert( asserted == null || asserted.GetType().Equals( this.GetType() ), "CheckPermitOnly not defined for permissions of different type" ); return IsSubsetOf( asserted ); } internal bool CanUnrestrictedOverride() { return CanUnrestrictedOverride(this); } internal static bool CanUnrestrictedOverride(IPermission ip) { if(CodeAccessSecurityEngine.DoesFullTrustMeanFullTrust()) return true; if(ip is IUnrestrictedPermission) return true; return false; } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007.
Link Menu
This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- ResourceReferenceKeyNotFoundException.cs
- ContainerTracking.cs
- NegotiateStream.cs
- DBCommand.cs
- ConsoleCancelEventArgs.cs
- CompilerGeneratedAttribute.cs
- AjaxFrameworkAssemblyAttribute.cs
- ColumnResizeAdorner.cs
- InitializerFacet.cs
- MessageVersion.cs
- TimeSpan.cs
- BuildDependencySet.cs
- NumericPagerField.cs
- Line.cs
- ListBindableAttribute.cs
- CodeFieldReferenceExpression.cs
- XmlCharCheckingWriter.cs
- Latin1Encoding.cs
- StorageEntityTypeMapping.cs
- StringFunctions.cs
- Crc32.cs
- EnumMemberAttribute.cs
- CodeGotoStatement.cs
- CompilerInfo.cs
- PowerEase.cs
- ComponentFactoryHelpers.cs
- TrackBar.cs
- BaseValidator.cs
- ExpandCollapseIsCheckedConverter.cs
- RMEnrollmentPage1.cs
- ModelVisual3D.cs
- WindowsListViewItemStartMenu.cs
- RtfNavigator.cs
- XhtmlBasicLabelAdapter.cs
- DecimalConstantAttribute.cs
- CookieHandler.cs
- ControlAdapter.cs
- TargetPerspective.cs
- DiagnosticStrings.cs
- AssemblyAttributes.cs
- WebPartZoneBase.cs
- CircleEase.cs
- DockingAttribute.cs
- _NetworkingPerfCounters.cs
- TextSelection.cs
- ServicesUtilities.cs
- TextServicesHost.cs
- HealthMonitoringSectionHelper.cs
- PrivilegeNotHeldException.cs
- MemberListBinding.cs
- PropertyCondition.cs
- TypeResolver.cs
- Vector3dCollection.cs
- ProfileGroupSettings.cs
- CommunicationException.cs
- EmbeddedMailObjectsCollection.cs
- Label.cs
- BitmapSourceSafeMILHandle.cs
- WorkflowMarkupSerializationManager.cs
- HttpContext.cs
- ResourceSetExpression.cs
- WebConfigurationFileMap.cs
- Token.cs
- XmlSchemaAttributeGroup.cs
- EmptyControlCollection.cs
- RawKeyboardInputReport.cs
- TableLayoutRowStyleCollection.cs
- Point4DConverter.cs
- HandoffBehavior.cs
- FixedSOMTableCell.cs
- RegexNode.cs
- DebuggerService.cs
- Transform3DGroup.cs
- SmiEventStream.cs
- ConnectionStringsExpressionBuilder.cs
- AngleUtil.cs
- ScrollViewerAutomationPeer.cs
- XsltQilFactory.cs
- UnauthorizedWebPart.cs
- DiscoveryEndpoint.cs
- ControllableStoryboardAction.cs
- ProjectedWrapper.cs
- ArraySegment.cs
- OdbcConnectionOpen.cs
- PeerToPeerException.cs
- EntitySqlQueryCacheKey.cs
- SymLanguageType.cs
- StorageComplexPropertyMapping.cs
- NavigationExpr.cs
- RNGCryptoServiceProvider.cs
- DesignerWithHeader.cs
- Drawing.cs
- TraceUtility.cs
- CodeTypeReferenceExpression.cs
- FormatConvertedBitmap.cs
- BrushProxy.cs
- TimelineGroup.cs
- ObjectStateFormatter.cs
- XmlLoader.cs
- OperationPerformanceCounters.cs