Code:
/ 4.0 / 4.0 / untmp / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / clr / src / BCL / System / Security / BuiltInPermissionSets.cs / 1305376 / BuiltInPermissionSets.cs
// ==++== // // Copyright (c) Microsoft Corporation. All rights reserved. // // ==--== // //[....] // using System; using System.Diagnostics.Contracts; using System.Security.Permissions; using Microsoft.Win32; namespace System.Security { internal static class BuiltInPermissionSets { // // Raw PermissionSet XML - the built in permission sets are expressed in XML form since they contain // permissions from assemblies other than mscorlib. // private static readonly string s_everythingXml = @""; private static readonly string s_executionXml = @" "; private static readonly string s_fullTrustXml = @" "; private static readonly string s_internetXml = @" "; private static readonly string s_localIntranetXml = @" "; private static readonly string s_nothingXml = @" "; private static readonly string s_skipVerificationXml = @" "; #if FEATURE_CAS_POLICY private const string s_wpfExtensionXml = @" "; private const string s_wpfExtensionUnrestrictedXml = @" "; #endif //FEATURE_CAS_POLICY // // Built in permission set objects // private static NamedPermissionSet s_everything; private static NamedPermissionSet s_execution; private static NamedPermissionSet s_fullTrust; private static NamedPermissionSet s_internet; private static NamedPermissionSet s_localIntranet; private static NamedPermissionSet s_nothing; private static NamedPermissionSet s_skipVerification; // // Standard permission sets // internal static NamedPermissionSet Everything { get { return GetOrDeserializeExtendablePermissionSet(ref s_everything, s_everythingXml #if FEATURE_CAS_POLICY , s_wpfExtensionUnrestrictedXml #endif // FEATURE_CAS_POLICY ); } } internal static NamedPermissionSet Execution { get { return GetOrDeserializePermissionSet(ref s_execution, s_executionXml); } } internal static NamedPermissionSet FullTrust { get { return GetOrDeserializePermissionSet(ref s_fullTrust, s_fullTrustXml); } } internal static NamedPermissionSet Internet { get { return GetOrDeserializeExtendablePermissionSet(ref s_internet, s_internetXml #if FEATURE_CAS_POLICY , s_wpfExtensionXml #endif // FEATURE_CAS_POLICY ); } } internal static NamedPermissionSet LocalIntranet { get { return GetOrDeserializeExtendablePermissionSet(ref s_localIntranet, s_localIntranetXml #if FEATURE_CAS_POLICY , s_wpfExtensionXml #endif // FEATURE_CAS_POLICY ); } } internal static NamedPermissionSet Nothing { get { return GetOrDeserializePermissionSet(ref s_nothing, s_nothingXml); } } internal static NamedPermissionSet SkipVerification { get { return GetOrDeserializePermissionSet(ref s_skipVerification, s_skipVerificationXml); } } // // Utility methods to construct the permission set objects from the well known XML and any permission // set extensions if necessary // private static NamedPermissionSet GetOrDeserializeExtendablePermissionSet(ref NamedPermissionSet permissionSet, string permissionSetXml #if FEATURE_CAS_POLICY ,string extensionXml #endif // FEATURE_CAS_POLICY ) { Contract.Requires(!String.IsNullOrEmpty(permissionSetXml)); #if FEATURE_CAS_POLICY Contract.Requires(!String.IsNullOrEmpty(extensionXml)); #endif // FEATURE_CAS_POLICY if (permissionSet == null) { #if FEATURE_CAS_POLICY SecurityElement securityElement = SecurityElement.FromString(permissionSetXml); NamedPermissionSet deserializedPermissionSet = new NamedPermissionSet(securityElement); PermissionSet extensions = GetPermissionSetExtensions(extensionXml); deserializedPermissionSet.InplaceUnion(extensions); permissionSet = deserializedPermissionSet; #endif // FEATURE_CAS_POLICY } return permissionSet.Copy() as NamedPermissionSet; } private static NamedPermissionSet GetOrDeserializePermissionSet(ref NamedPermissionSet permissionSet, string permissionSetXml) { Contract.Assert(!String.IsNullOrEmpty(permissionSetXml)); #if FEATURE_CAS_POLICY if (permissionSet == null) { SecurityElement securityElement = SecurityElement.FromString(permissionSetXml); NamedPermissionSet deserializedPermissionSet = new NamedPermissionSet(securityElement); permissionSet = deserializedPermissionSet; } #endif // FEATURE_CAS_POLICY return permissionSet.Copy() as NamedPermissionSet; } #if FEATURE_CAS_POLICY private static PermissionSet GetPermissionSetExtensions(string extensionXml) { Contract.Requires(!String.IsNullOrEmpty(extensionXml)); SecurityElement se = SecurityElement.FromString(extensionXml); // Return the permission set extension only if WPF is in the present framework profile. // XMLUtil.GetClassFromElement() helps do the quickest check, with no exception thrown and // minimal parsing. SecurityElement firstPermission = (SecurityElement)se.Children[0]; if (System.Security.Util.XMLUtil.GetClassFromElement(firstPermission, /*ignoreTypeLoadFailures*/true) != null) { PermissionSet extensions = new NamedPermissionSet(se); return extensions; } return null; } #endif // FEATURE_CAS_POLICY } } // 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
- XmlSchemaSet.cs
- DataGridViewRowCancelEventArgs.cs
- Point.cs
- RoutedEvent.cs
- PropertyGeneratedEventArgs.cs
- DocumentPageHost.cs
- OleDbStruct.cs
- AnnotationAuthorChangedEventArgs.cs
- ComPlusDiagnosticTraceSchemas.cs
- Brush.cs
- TextDecorations.cs
- RegexTree.cs
- PropertyChangedEventManager.cs
- FixedSchema.cs
- InternalResources.cs
- SqlUdtInfo.cs
- RegexGroup.cs
- ConnectionStringEditor.cs
- PhonemeConverter.cs
- FrameworkElement.cs
- _ListenerRequestStream.cs
- DataServices.cs
- ObjectDataSourceEventArgs.cs
- InheritanceContextHelper.cs
- Ray3DHitTestResult.cs
- WebBaseEventKeyComparer.cs
- WindowsImpersonationContext.cs
- SecurityCapabilities.cs
- SkewTransform.cs
- MD5HashHelper.cs
- DotExpr.cs
- Subordinate.cs
- OracleMonthSpan.cs
- SafeRightsManagementSessionHandle.cs
- documentation.cs
- UdpContractFilterBehavior.cs
- ClipboardData.cs
- MessageBox.cs
- _LazyAsyncResult.cs
- TraceContextRecord.cs
- SID.cs
- PasswordDeriveBytes.cs
- IMembershipProvider.cs
- GenericsInstances.cs
- ScriptingScriptResourceHandlerSection.cs
- CodeTypeDeclaration.cs
- ConfigurationStrings.cs
- ContextMenuStripGroupCollection.cs
- AnnotationElement.cs
- XPathBuilder.cs
- SessionIDManager.cs
- MessageSmuggler.cs
- CodeRemoveEventStatement.cs
- CompiledQuery.cs
- NativeWindow.cs
- AudioFileOut.cs
- PackageStore.cs
- XmlSchemaChoice.cs
- SqlMethodTransformer.cs
- recordstate.cs
- DefaultHttpHandler.cs
- CodeDomConfigurationHandler.cs
- NameValueCollection.cs
- TemplateModeChangedEventArgs.cs
- GatewayDefinition.cs
- ProfilePropertySettings.cs
- HuffCodec.cs
- Publisher.cs
- SystemWebCachingSectionGroup.cs
- FamilyTypefaceCollection.cs
- ExpanderAutomationPeer.cs
- ExternalException.cs
- SiteMapHierarchicalDataSourceView.cs
- ChannelManager.cs
- DocumentXmlWriter.cs
- QuerySubExprEliminator.cs
- FileBasedResourceGroveler.cs
- Base64Decoder.cs
- EntityCommandCompilationException.cs
- _NetRes.cs
- ScriptMethodAttribute.cs
- SafeNativeMethods.cs
- TableLayoutRowStyleCollection.cs
- PenLineCapValidation.cs
- CompilerErrorCollection.cs
- XmlEncApr2001.cs
- DbProviderFactories.cs
- AutomationElementCollection.cs
- WindowsTitleBar.cs
- XmlSchemaSequence.cs
- ControlCachePolicy.cs
- ScopelessEnumAttribute.cs
- EventLogger.cs
- RootAction.cs
- MeshGeometry3D.cs
- PageAsyncTaskManager.cs
- WebControlAdapter.cs
- DefaultIfEmptyQueryOperator.cs
- WindowsFormsLinkLabel.cs
- AttributeCollection.cs