Code:
/ 4.0 / 4.0 / untmp / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / clr / src / BCL / System / Security / Policy / ZoneMembershipCondition.cs / 1305376 / ZoneMembershipCondition.cs
using System.Diagnostics.Contracts; // ==++== // // Copyright (c) Microsoft Corporation. All rights reserved. // // ==--== // ZoneMembershipCondition.cs // //[....] // // Implementation of membership condition for zones // namespace System.Security.Policy { using System; using SecurityManager = System.Security.SecurityManager; using PermissionSet = System.Security.PermissionSet; using SecurityElement = System.Security.SecurityElement; using System.Collections; using System.Globalization; [Serializable] [System.Runtime.InteropServices.ComVisible(true)] sealed public class ZoneMembershipCondition : IMembershipCondition, IConstantMembershipCondition, IReportMatchMembershipCondition { //------------------------------------------------------ // // PRIVATE CONSTANTS // //----------------------------------------------------- private static readonly String[] s_names = {"MyComputer", "Intranet", "Trusted", "Internet", "Untrusted"}; //----------------------------------------------------- // // PRIVATE STATE DATA // //----------------------------------------------------- private SecurityZone m_zone; private SecurityElement m_element; //------------------------------------------------------ // // PUBLIC CONSTRUCTORS // //----------------------------------------------------- internal ZoneMembershipCondition() { m_zone = SecurityZone.NoZone; } public ZoneMembershipCondition( SecurityZone zone ) { VerifyZone( zone ); this.SecurityZone = zone; } //------------------------------------------------------ // // PUBLIC ACCESSOR METHODS // //------------------------------------------------------ public SecurityZone SecurityZone { set { VerifyZone( value ); m_zone = value; } get { if (m_zone == SecurityZone.NoZone && m_element != null) ParseZone(); return m_zone; } } //----------------------------------------------------- // // PRIVATE AND PROTECTED HELPERS FOR ACCESSORS AND CONSTRUCTORS // //------------------------------------------------------ private static void VerifyZone( SecurityZone zone ) { if (zone < SecurityZone.MyComputer || zone > SecurityZone.Untrusted) { throw new ArgumentException( Environment.GetResourceString( "Argument_IllegalZone" ) ); } Contract.EndContractBlock(); } //----------------------------------------------------- // // IMEMBERSHIPCONDITION IMPLEMENTATION // //----------------------------------------------------- public bool Check( Evidence evidence ) { object usedEvidence = null; return (this as IReportMatchMembershipCondition).Check(evidence, out usedEvidence); } bool IReportMatchMembershipCondition.Check(Evidence evidence, out object usedEvidence) { usedEvidence = null; if (evidence == null) return false; Zone zone = evidence.GetHostEvidence(); if (zone != null) { if (m_zone == SecurityZone.NoZone && m_element != null) { ParseZone(); } if (zone.SecurityZone == m_zone) { usedEvidence = zone; return true; } } return false; } public IMembershipCondition Copy() { if (m_zone == SecurityZone.NoZone && m_element != null) ParseZone(); return new ZoneMembershipCondition( m_zone ); } public SecurityElement ToXml() { return ToXml( null ); } public void FromXml( SecurityElement e ) { FromXml( e, null ); } public SecurityElement ToXml( PolicyLevel level ) { if (m_zone == SecurityZone.NoZone && m_element != null) ParseZone(); SecurityElement root = new SecurityElement( "IMembershipCondition" ); System.Security.Util.XMLUtil.AddClassAttribute( root, this.GetType(), "System.Security.Policy.ZoneMembershipCondition" ); // 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. Contract.Assert( this.GetType().FullName.Equals( "System.Security.Policy.ZoneMembershipCondition" ), "Class name changed!" ); root.AddAttribute( "version", "1" ); if (m_zone != SecurityZone.NoZone) root.AddAttribute( "Zone", Enum.GetName( typeof( SecurityZone ), m_zone ) ); return root; } public void FromXml( SecurityElement e, PolicyLevel level ) { if (e == null) throw new ArgumentNullException("e"); if (!e.Tag.Equals( "IMembershipCondition" )) { throw new ArgumentException( Environment.GetResourceString( "Argument_MembershipConditionElement" ) ); } Contract.EndContractBlock(); lock (this) { m_zone = SecurityZone.NoZone; m_element = e; } } private void ParseZone() { lock (this) { if (m_element == null) return; String eZone = m_element.Attribute( "Zone" ); m_zone = SecurityZone.NoZone; if (eZone != null) { m_zone = (SecurityZone)Enum.Parse( typeof( SecurityZone ), eZone ); } else { throw new ArgumentException( Environment.GetResourceString( "Argument_ZoneCannotBeNull" ) ); } VerifyZone(m_zone); m_element = null; } } public override bool Equals( Object o ) { ZoneMembershipCondition that = (o as ZoneMembershipCondition); if (that != null) { if (this.m_zone == SecurityZone.NoZone && this.m_element != null) this.ParseZone(); if (that.m_zone == SecurityZone.NoZone && that.m_element != null) that.ParseZone(); if(this.m_zone == that.m_zone) { return true; } } return false; } public override int GetHashCode() { if (this.m_zone == SecurityZone.NoZone && this.m_element != null) this.ParseZone(); return (int)m_zone; } public override String ToString() { if (m_zone == SecurityZone.NoZone && m_element != null) ParseZone(); return String.Format( CultureInfo.CurrentCulture, Environment.GetResourceString( "Zone_ToString" ), s_names[(int)m_zone] ); } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. // Copyright (c) Microsoft Corporation. All rights reserved.
Link Menu
This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- ObjectTypeMapping.cs
- XomlSerializationHelpers.cs
- SQLUtility.cs
- DictionaryMarkupSerializer.cs
- UDPClient.cs
- SpecularMaterial.cs
- SynchronizationLockException.cs
- LogEntry.cs
- BamlResourceDeserializer.cs
- DivideByZeroException.cs
- UpdateManifestForBrowserApplication.cs
- TextChangedEventArgs.cs
- XmlIncludeAttribute.cs
- ToolStripPanelSelectionGlyph.cs
- DataGridItemAutomationPeer.cs
- WsatProxy.cs
- XamlInt32CollectionSerializer.cs
- Part.cs
- TextPatternIdentifiers.cs
- DeferredBinaryDeserializerExtension.cs
- DependencyObjectValidator.cs
- DataServiceQuery.cs
- OleStrCAMarshaler.cs
- Table.cs
- SevenBitStream.cs
- PaintValueEventArgs.cs
- HiddenFieldPageStatePersister.cs
- ServiceSettingsResponseInfo.cs
- ThicknessAnimationUsingKeyFrames.cs
- Int64KeyFrameCollection.cs
- ManipulationInertiaStartingEventArgs.cs
- OdbcCommand.cs
- WebPartZoneDesigner.cs
- TrackingParameters.cs
- CreateUserWizard.cs
- ItemsChangedEventArgs.cs
- ZipIOLocalFileHeader.cs
- DataViewSetting.cs
- RIPEMD160Managed.cs
- InputLangChangeRequestEvent.cs
- InfoCardClaimCollection.cs
- CommonObjectSecurity.cs
- ClientConfigPaths.cs
- ScriptingJsonSerializationSection.cs
- CustomValidator.cs
- DataViewListener.cs
- OdbcDataReader.cs
- TextDecorationLocationValidation.cs
- BookmarkNameHelper.cs
- RouteItem.cs
- MD5CryptoServiceProvider.cs
- TextContainerChangeEventArgs.cs
- MenuStrip.cs
- WindowsStatic.cs
- DataGridViewColumn.cs
- SimpleLine.cs
- WebPartDisplayModeCancelEventArgs.cs
- PathData.cs
- DataGridCommandEventArgs.cs
- OrthographicCamera.cs
- SystemParameters.cs
- ToggleButton.cs
- ListItemCollection.cs
- SQLInt16Storage.cs
- DbDataSourceEnumerator.cs
- ConnectionsZone.cs
- ListenerElementsCollection.cs
- StyleXamlParser.cs
- ListBox.cs
- DataServiceException.cs
- WhitespaceRuleReader.cs
- ModelPropertyImpl.cs
- PriorityBinding.cs
- OrderedDictionaryStateHelper.cs
- MultipleCopiesCollection.cs
- GeneralTransform3DTo2D.cs
- DefaultTraceListener.cs
- StructuredType.cs
- ValueExpressions.cs
- PropertiesTab.cs
- MarkupWriter.cs
- ToolStripRendererSwitcher.cs
- IisTraceWebEventProvider.cs
- PointAnimation.cs
- _NegoStream.cs
- DrawListViewSubItemEventArgs.cs
- GeometryGroup.cs
- MultiTargetingUtil.cs
- ComponentCollection.cs
- Trigger.cs
- Memoizer.cs
- JavaScriptObjectDeserializer.cs
- FixedNode.cs
- PasswordBox.cs
- WebWorkflowRole.cs
- EdmComplexPropertyAttribute.cs
- XmlElementList.cs
- CollectionViewSource.cs
- ListMarkerSourceInfo.cs
- Facet.cs