Code:
/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / clr / src / BCL / System / Security / AccessControl / Rules.cs / 1305376 / Rules.cs
using System; using System.Collections; using System.Security.Principal; using System.Diagnostics.Contracts; namespace System.Security.AccessControl { public enum AccessControlType { Allow = 0, Deny = 1, } public abstract class AuthorizationRule { #region Private Members private readonly IdentityReference _identity; private readonly int _accessMask; private readonly bool _isInherited; private readonly InheritanceFlags _inheritanceFlags; private readonly PropagationFlags _propagationFlags; #endregion #region Constructors internal protected AuthorizationRule( IdentityReference identity, int accessMask, bool isInherited, InheritanceFlags inheritanceFlags, PropagationFlags propagationFlags ) { if ( identity == null ) { throw new ArgumentNullException( "identity" ); } if ( accessMask == 0 ) { throw new ArgumentException( Environment.GetResourceString( "Argument_ArgumentZero" ), "accessMask" ); } if ( inheritanceFlags < InheritanceFlags.None || inheritanceFlags > (InheritanceFlags.ObjectInherit | InheritanceFlags.ContainerInherit) ) { throw new ArgumentOutOfRangeException( "inheritanceFlags", Environment.GetResourceString( "Argument_InvalidEnumValue", inheritanceFlags, "InheritanceFlags" )); } if ( propagationFlags < PropagationFlags.None || propagationFlags > (PropagationFlags.NoPropagateInherit | PropagationFlags.InheritOnly) ) { throw new ArgumentOutOfRangeException( "propagationFlags", Environment.GetResourceString( "Argument_InvalidEnumValue", inheritanceFlags, "PropagationFlags" )); } Contract.EndContractBlock(); if (identity.IsValidTargetType(typeof(SecurityIdentifier)) == false) { throw new ArgumentException( Environment.GetResourceString("Arg_MustBeIdentityReferenceType"), "identity"); } _identity = identity; _accessMask = accessMask; _isInherited = isInherited; _inheritanceFlags = inheritanceFlags; if ( inheritanceFlags != 0 ) { _propagationFlags = propagationFlags; } else { _propagationFlags = 0; } } #endregion #region Properties public IdentityReference IdentityReference { get { return _identity; } } internal protected int AccessMask { get { return _accessMask; } } public bool IsInherited { get { return _isInherited; } } public InheritanceFlags InheritanceFlags { get { return _inheritanceFlags; } } public PropagationFlags PropagationFlags { get { return _propagationFlags; } } #endregion } public abstract class AccessRule : AuthorizationRule { #region Private Methods private readonly AccessControlType _type; #endregion #region Constructors protected AccessRule( IdentityReference identity, int accessMask, bool isInherited, InheritanceFlags inheritanceFlags, PropagationFlags propagationFlags, AccessControlType type ) : base( identity, accessMask, isInherited, inheritanceFlags, propagationFlags ) { if ( type != AccessControlType.Allow && type != AccessControlType.Deny ) { throw new ArgumentOutOfRangeException( "type", Environment.GetResourceString( "ArgumentOutOfRange_Enum" )); } if ( inheritanceFlags < InheritanceFlags.None || inheritanceFlags > (InheritanceFlags.ObjectInherit | InheritanceFlags.ContainerInherit) ) { throw new ArgumentOutOfRangeException( "inheritanceFlags", Environment.GetResourceString( "Argument_InvalidEnumValue", inheritanceFlags, "InheritanceFlags" )); } if ( propagationFlags < PropagationFlags.None || propagationFlags > (PropagationFlags.NoPropagateInherit | PropagationFlags.InheritOnly) ) { throw new ArgumentOutOfRangeException( "propagationFlags", Environment.GetResourceString( "Argument_InvalidEnumValue", inheritanceFlags, "PropagationFlags" )); } Contract.EndContractBlock(); _type = type; } #endregion #region Properties public AccessControlType AccessControlType { get { return _type; } } #endregion } public abstract class ObjectAccessRule: AccessRule { #region Private Members private readonly Guid _objectType; private readonly Guid _inheritedObjectType; private readonly ObjectAceFlags _objectFlags = ObjectAceFlags.None; #endregion #region Constructors protected ObjectAccessRule( IdentityReference identity, int accessMask, bool isInherited, InheritanceFlags inheritanceFlags, PropagationFlags propagationFlags, Guid objectType, Guid inheritedObjectType, AccessControlType type ) : base( identity, accessMask, isInherited, inheritanceFlags, propagationFlags, type ) { if (( !objectType.Equals( Guid.Empty )) && (( accessMask & ObjectAce.AccessMaskWithObjectType ) != 0 )) { _objectType = objectType; _objectFlags |= ObjectAceFlags.ObjectAceTypePresent; } else { _objectType = Guid.Empty; } if (( !inheritedObjectType.Equals( Guid.Empty )) && ((inheritanceFlags & InheritanceFlags.ContainerInherit ) != 0 )) { _inheritedObjectType = inheritedObjectType; _objectFlags |= ObjectAceFlags.InheritedObjectAceTypePresent; } else { _inheritedObjectType = Guid.Empty; } } #endregion #region Properties public Guid ObjectType { get { return _objectType; } } public Guid InheritedObjectType { get { return _inheritedObjectType; } } public ObjectAceFlags ObjectFlags { get { return _objectFlags; } } #endregion } public abstract class AuditRule : AuthorizationRule { #region Private Members private readonly AuditFlags _flags; #endregion #region Constructors protected AuditRule( IdentityReference identity, int accessMask, bool isInherited, InheritanceFlags inheritanceFlags, PropagationFlags propagationFlags, AuditFlags auditFlags ) : base( identity, accessMask, isInherited, inheritanceFlags, propagationFlags ) { if ( auditFlags == AuditFlags.None ) { throw new ArgumentException( Environment.GetResourceString( "Arg_EnumAtLeastOneFlag" ), "auditFlags" ); } else if (( auditFlags & ~( AuditFlags.Success | AuditFlags.Failure )) != 0 ) { throw new ArgumentOutOfRangeException( "auditFlags", Environment.GetResourceString( "ArgumentOutOfRange_Enum" )); } _flags = auditFlags; } #endregion #region Public Properties public AuditFlags AuditFlags { get { return _flags; } } #endregion } public abstract class ObjectAuditRule: AuditRule { #region Private Members private readonly Guid _objectType; private readonly Guid _inheritedObjectType; private readonly ObjectAceFlags _objectFlags = ObjectAceFlags.None; #endregion #region Constructors protected ObjectAuditRule( IdentityReference identity, int accessMask, bool isInherited, InheritanceFlags inheritanceFlags, PropagationFlags propagationFlags, Guid objectType, Guid inheritedObjectType, AuditFlags auditFlags ) : base( identity, accessMask, isInherited, inheritanceFlags, propagationFlags, auditFlags ) { if (( !objectType.Equals( Guid.Empty )) && (( accessMask & ObjectAce.AccessMaskWithObjectType ) != 0 )) { _objectType = objectType; _objectFlags |= ObjectAceFlags.ObjectAceTypePresent; } else { _objectType = Guid.Empty; } if (( !inheritedObjectType.Equals( Guid.Empty )) && ((inheritanceFlags & InheritanceFlags.ContainerInherit ) != 0 )) { _inheritedObjectType = inheritedObjectType; _objectFlags |= ObjectAceFlags.InheritedObjectAceTypePresent; } else { _inheritedObjectType = Guid.Empty; } } #endregion #region Public Properties public Guid ObjectType { get { return _objectType; } } public Guid InheritedObjectType { get { return _inheritedObjectType; } } public ObjectAceFlags ObjectFlags { get { return _objectFlags; } } #endregion } public sealed class AuthorizationRuleCollection : ReadOnlyCollectionBase { #region Constructors internal AuthorizationRuleCollection() : base() { } #endregion #region Internal methods internal void AddRule( AuthorizationRule rule ) { InnerList.Add( rule ); } #endregion #region ICollection Members public void CopyTo( AuthorizationRule[] rules, int index ) { (( ICollection )this ).CopyTo( rules, index ); } #endregion #region Public properties public AuthorizationRule this[int index] { get { return InnerList[index] as AuthorizationRule; } } #endregion } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. // Copyright (c) Microsoft Corporation. All rights reserved. using System; using System.Collections; using System.Security.Principal; using System.Diagnostics.Contracts; namespace System.Security.AccessControl { public enum AccessControlType { Allow = 0, Deny = 1, } public abstract class AuthorizationRule { #region Private Members private readonly IdentityReference _identity; private readonly int _accessMask; private readonly bool _isInherited; private readonly InheritanceFlags _inheritanceFlags; private readonly PropagationFlags _propagationFlags; #endregion #region Constructors internal protected AuthorizationRule( IdentityReference identity, int accessMask, bool isInherited, InheritanceFlags inheritanceFlags, PropagationFlags propagationFlags ) { if ( identity == null ) { throw new ArgumentNullException( "identity" ); } if ( accessMask == 0 ) { throw new ArgumentException( Environment.GetResourceString( "Argument_ArgumentZero" ), "accessMask" ); } if ( inheritanceFlags < InheritanceFlags.None || inheritanceFlags > (InheritanceFlags.ObjectInherit | InheritanceFlags.ContainerInherit) ) { throw new ArgumentOutOfRangeException( "inheritanceFlags", Environment.GetResourceString( "Argument_InvalidEnumValue", inheritanceFlags, "InheritanceFlags" )); } if ( propagationFlags < PropagationFlags.None || propagationFlags > (PropagationFlags.NoPropagateInherit | PropagationFlags.InheritOnly) ) { throw new ArgumentOutOfRangeException( "propagationFlags", Environment.GetResourceString( "Argument_InvalidEnumValue", inheritanceFlags, "PropagationFlags" )); } Contract.EndContractBlock(); if (identity.IsValidTargetType(typeof(SecurityIdentifier)) == false) { throw new ArgumentException( Environment.GetResourceString("Arg_MustBeIdentityReferenceType"), "identity"); } _identity = identity; _accessMask = accessMask; _isInherited = isInherited; _inheritanceFlags = inheritanceFlags; if ( inheritanceFlags != 0 ) { _propagationFlags = propagationFlags; } else { _propagationFlags = 0; } } #endregion #region Properties public IdentityReference IdentityReference { get { return _identity; } } internal protected int AccessMask { get { return _accessMask; } } public bool IsInherited { get { return _isInherited; } } public InheritanceFlags InheritanceFlags { get { return _inheritanceFlags; } } public PropagationFlags PropagationFlags { get { return _propagationFlags; } } #endregion } public abstract class AccessRule : AuthorizationRule { #region Private Methods private readonly AccessControlType _type; #endregion #region Constructors protected AccessRule( IdentityReference identity, int accessMask, bool isInherited, InheritanceFlags inheritanceFlags, PropagationFlags propagationFlags, AccessControlType type ) : base( identity, accessMask, isInherited, inheritanceFlags, propagationFlags ) { if ( type != AccessControlType.Allow && type != AccessControlType.Deny ) { throw new ArgumentOutOfRangeException( "type", Environment.GetResourceString( "ArgumentOutOfRange_Enum" )); } if ( inheritanceFlags < InheritanceFlags.None || inheritanceFlags > (InheritanceFlags.ObjectInherit | InheritanceFlags.ContainerInherit) ) { throw new ArgumentOutOfRangeException( "inheritanceFlags", Environment.GetResourceString( "Argument_InvalidEnumValue", inheritanceFlags, "InheritanceFlags" )); } if ( propagationFlags < PropagationFlags.None || propagationFlags > (PropagationFlags.NoPropagateInherit | PropagationFlags.InheritOnly) ) { throw new ArgumentOutOfRangeException( "propagationFlags", Environment.GetResourceString( "Argument_InvalidEnumValue", inheritanceFlags, "PropagationFlags" )); } Contract.EndContractBlock(); _type = type; } #endregion #region Properties public AccessControlType AccessControlType { get { return _type; } } #endregion } public abstract class ObjectAccessRule: AccessRule { #region Private Members private readonly Guid _objectType; private readonly Guid _inheritedObjectType; private readonly ObjectAceFlags _objectFlags = ObjectAceFlags.None; #endregion #region Constructors protected ObjectAccessRule( IdentityReference identity, int accessMask, bool isInherited, InheritanceFlags inheritanceFlags, PropagationFlags propagationFlags, Guid objectType, Guid inheritedObjectType, AccessControlType type ) : base( identity, accessMask, isInherited, inheritanceFlags, propagationFlags, type ) { if (( !objectType.Equals( Guid.Empty )) && (( accessMask & ObjectAce.AccessMaskWithObjectType ) != 0 )) { _objectType = objectType; _objectFlags |= ObjectAceFlags.ObjectAceTypePresent; } else { _objectType = Guid.Empty; } if (( !inheritedObjectType.Equals( Guid.Empty )) && ((inheritanceFlags & InheritanceFlags.ContainerInherit ) != 0 )) { _inheritedObjectType = inheritedObjectType; _objectFlags |= ObjectAceFlags.InheritedObjectAceTypePresent; } else { _inheritedObjectType = Guid.Empty; } } #endregion #region Properties public Guid ObjectType { get { return _objectType; } } public Guid InheritedObjectType { get { return _inheritedObjectType; } } public ObjectAceFlags ObjectFlags { get { return _objectFlags; } } #endregion } public abstract class AuditRule : AuthorizationRule { #region Private Members private readonly AuditFlags _flags; #endregion #region Constructors protected AuditRule( IdentityReference identity, int accessMask, bool isInherited, InheritanceFlags inheritanceFlags, PropagationFlags propagationFlags, AuditFlags auditFlags ) : base( identity, accessMask, isInherited, inheritanceFlags, propagationFlags ) { if ( auditFlags == AuditFlags.None ) { throw new ArgumentException( Environment.GetResourceString( "Arg_EnumAtLeastOneFlag" ), "auditFlags" ); } else if (( auditFlags & ~( AuditFlags.Success | AuditFlags.Failure )) != 0 ) { throw new ArgumentOutOfRangeException( "auditFlags", Environment.GetResourceString( "ArgumentOutOfRange_Enum" )); } _flags = auditFlags; } #endregion #region Public Properties public AuditFlags AuditFlags { get { return _flags; } } #endregion } public abstract class ObjectAuditRule: AuditRule { #region Private Members private readonly Guid _objectType; private readonly Guid _inheritedObjectType; private readonly ObjectAceFlags _objectFlags = ObjectAceFlags.None; #endregion #region Constructors protected ObjectAuditRule( IdentityReference identity, int accessMask, bool isInherited, InheritanceFlags inheritanceFlags, PropagationFlags propagationFlags, Guid objectType, Guid inheritedObjectType, AuditFlags auditFlags ) : base( identity, accessMask, isInherited, inheritanceFlags, propagationFlags, auditFlags ) { if (( !objectType.Equals( Guid.Empty )) && (( accessMask & ObjectAce.AccessMaskWithObjectType ) != 0 )) { _objectType = objectType; _objectFlags |= ObjectAceFlags.ObjectAceTypePresent; } else { _objectType = Guid.Empty; } if (( !inheritedObjectType.Equals( Guid.Empty )) && ((inheritanceFlags & InheritanceFlags.ContainerInherit ) != 0 )) { _inheritedObjectType = inheritedObjectType; _objectFlags |= ObjectAceFlags.InheritedObjectAceTypePresent; } else { _inheritedObjectType = Guid.Empty; } } #endregion #region Public Properties public Guid ObjectType { get { return _objectType; } } public Guid InheritedObjectType { get { return _inheritedObjectType; } } public ObjectAceFlags ObjectFlags { get { return _objectFlags; } } #endregion } public sealed class AuthorizationRuleCollection : ReadOnlyCollectionBase { #region Constructors internal AuthorizationRuleCollection() : base() { } #endregion #region Internal methods internal void AddRule( AuthorizationRule rule ) { InnerList.Add( rule ); } #endregion #region ICollection Members public void CopyTo( AuthorizationRule[] rules, int index ) { (( ICollection )this ).CopyTo( rules, index ); } #endregion #region Public properties public AuthorizationRule this[int index] { get { return InnerList[index] as AuthorizationRule; } } #endregion } } // 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
- TextFormattingConverter.cs
- TCPListener.cs
- Cloud.cs
- processwaithandle.cs
- SQLDouble.cs
- RtfToken.cs
- ImageListImageEditor.cs
- VirtualDirectoryMappingCollection.cs
- EntityWithKeyStrategy.cs
- AutomationElementIdentifiers.cs
- Stackframe.cs
- _ScatterGatherBuffers.cs
- SmtpReplyReaderFactory.cs
- ServiceHttpHandlerFactory.cs
- ChangesetResponse.cs
- FullTrustAssembly.cs
- PanelStyle.cs
- HtmlInputSubmit.cs
- FontNamesConverter.cs
- Menu.cs
- GestureRecognitionResult.cs
- OracleDateTime.cs
- ISFTagAndGuidCache.cs
- SourceFileBuildProvider.cs
- AnnouncementDispatcherAsyncResult.cs
- DecimalStorage.cs
- LinearGradientBrush.cs
- HttpPostProtocolReflector.cs
- TypeResolver.cs
- DirtyTextRange.cs
- ModifierKeysValueSerializer.cs
- FramingFormat.cs
- XPathItem.cs
- PageBreakRecord.cs
- ColumnMapVisitor.cs
- UrlPropertyAttribute.cs
- SecurityTokenResolver.cs
- DataControlFieldCollection.cs
- DebugView.cs
- VisualTreeHelper.cs
- ObjectCloneHelper.cs
- PropertyBuilder.cs
- HttpListenerContext.cs
- PaperSize.cs
- ColorTransformHelper.cs
- RadioButtonStandardAdapter.cs
- ArrayConverter.cs
- XamlGridLengthSerializer.cs
- CompareValidator.cs
- KeyEventArgs.cs
- DrawingContext.cs
- RegistryPermission.cs
- UIElement3DAutomationPeer.cs
- HostedNamedPipeTransportManager.cs
- ConstraintConverter.cs
- EntityContainer.cs
- BuildTopDownAttribute.cs
- TextRangeSerialization.cs
- DbDataRecord.cs
- AuthenticationConfig.cs
- UnrecognizedAssertionsBindingElement.cs
- SelectorAutomationPeer.cs
- OutputCacheProfile.cs
- XmlSchemaRedefine.cs
- RenderDataDrawingContext.cs
- CollectionViewGroup.cs
- WriterOutput.cs
- AspNetHostingPermission.cs
- FontFamily.cs
- FilterFactory.cs
- ListViewUpdateEventArgs.cs
- WebSysDefaultValueAttribute.cs
- SwitchAttribute.cs
- X509ChainElement.cs
- __ComObject.cs
- WeakReferenceEnumerator.cs
- ApplicationSettingsBase.cs
- ConfigurationElementCollection.cs
- GeneralTransform3DCollection.cs
- TextEditorCharacters.cs
- StreamResourceInfo.cs
- ValidationEventArgs.cs
- GenericsNotImplementedException.cs
- RegexStringValidatorAttribute.cs
- milexports.cs
- ConfigUtil.cs
- UnsafeNativeMethods.cs
- DockingAttribute.cs
- XmlTextReaderImpl.cs
- Int32RectConverter.cs
- RSACryptoServiceProvider.cs
- NonBatchDirectoryCompiler.cs
- Pkcs9Attribute.cs
- BaseDataBoundControlDesigner.cs
- PackageProperties.cs
- DbParameterCollectionHelper.cs
- CompilationUtil.cs
- StackBuilderSink.cs
- OpenTypeMethods.cs
- GuidelineSet.cs