Code:
/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / fx / src / security / system / security / authentication / ExtendedProtection / ExtendedProtectionPolicy.cs / 1305376 / ExtendedProtectionPolicy.cs
//------------------------------------------------------------------------------
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
//-----------------------------------------------------------------------------
using System;
using System.Collections;
using System.ComponentModel;
using System.Net;
using System.Runtime.InteropServices;
using System.Runtime.Serialization;
using System.Security.Permissions;
using System.Text;
namespace System.Security.Authentication.ExtendedProtection
{
///
/// This class contains the necessary settings for specifying how Extended Protection
/// should behave. Use one of the Build* methods to create an instance of this type.
///
[Serializable]
[TypeConverter(typeof(ExtendedProtectionPolicyTypeConverter))]
public class ExtendedProtectionPolicy : ISerializable
{
private const string policyEnforcementName = "policyEnforcement";
private const string protectionScenarioName = "protectionScenario";
private const string customServiceNamesName = "customServiceNames";
private const string customChannelBindingName = "customChannelBinding";
private ServiceNameCollection customServiceNames;
private PolicyEnforcement policyEnforcement;
private ProtectionScenario protectionScenario;
private ChannelBinding customChannelBinding;
public ExtendedProtectionPolicy(PolicyEnforcement policyEnforcement,
ProtectionScenario protectionScenario,
ServiceNameCollection customServiceNames)
{
if (policyEnforcement == PolicyEnforcement.Never)
{
throw new ArgumentException(SR.GetString(SR.security_ExtendedProtectionPolicy_UseDifferentConstructorForNever), "policyEnforcement");
}
if (customServiceNames != null && customServiceNames.Count == 0)
{
throw new ArgumentException(SR.GetString(SR.security_ExtendedProtectionPolicy_NoEmptyServiceNameCollection), "customServiceNames");
}
this.policyEnforcement = policyEnforcement;
this.protectionScenario = protectionScenario;
this.customServiceNames = customServiceNames;
}
public ExtendedProtectionPolicy(PolicyEnforcement policyEnforcement,
ProtectionScenario protectionScenario,
ICollection customServiceNames)
: this(policyEnforcement, protectionScenario,
customServiceNames == null ? (ServiceNameCollection)null : new ServiceNameCollection(customServiceNames))
{
}
public ExtendedProtectionPolicy(PolicyEnforcement policyEnforcement,
ChannelBinding customChannelBinding)
{
if (policyEnforcement == PolicyEnforcement.Never)
{
throw new ArgumentException(SR.GetString(SR.security_ExtendedProtectionPolicy_UseDifferentConstructorForNever), "policyEnforcement");
}
if (customChannelBinding == null)
{
throw new ArgumentNullException("customChannelBinding");
}
this.policyEnforcement = policyEnforcement;
this.protectionScenario = ProtectionScenario.TransportSelected;
this.customChannelBinding = customChannelBinding;
}
public ExtendedProtectionPolicy(PolicyEnforcement policyEnforcement)
{
// this is the only constructor which allows PolicyEnforcement.Never.
this.policyEnforcement = policyEnforcement;
this.protectionScenario = ProtectionScenario.TransportSelected;
}
protected ExtendedProtectionPolicy(SerializationInfo info, StreamingContext context)
{
policyEnforcement = (PolicyEnforcement)info.GetInt32(policyEnforcementName);
protectionScenario = (ProtectionScenario)info.GetInt32(protectionScenarioName);
customServiceNames = (ServiceNameCollection)info.GetValue(customServiceNamesName, typeof(ServiceNameCollection));
byte[] channelBindingData = (byte[])info.GetValue(customChannelBindingName, typeof(byte[]));
if (channelBindingData != null)
{
customChannelBinding = SafeLocalFreeChannelBinding.LocalAlloc(channelBindingData.Length);
Marshal.Copy(channelBindingData, 0, customChannelBinding.DangerousGetHandle(), channelBindingData.Length);
}
}
public ServiceNameCollection CustomServiceNames
{
get { return customServiceNames; }
}
public PolicyEnforcement PolicyEnforcement
{
get { return policyEnforcement; }
}
public ProtectionScenario ProtectionScenario
{
get { return protectionScenario; }
}
public ChannelBinding CustomChannelBinding
{
get { return customChannelBinding; }
}
public override string ToString()
{
StringBuilder sb = new StringBuilder();
sb.Append("ProtectionScenario=");
sb.Append(protectionScenario.ToString());
sb.Append("; PolicyEnforcement=");
sb.Append(policyEnforcement.ToString());
sb.Append("; CustomChannelBinding=");
if (customChannelBinding == null)
{
sb.Append("");
}
else
{
sb.Append(customChannelBinding.ToString());
}
sb.Append("; ServiceNames=");
if (customServiceNames == null)
{
sb.Append("");
}
else
{
bool first = true;
foreach (string serviceName in customServiceNames)
{
if (first)
{
first = false;
}
else
{
sb.Append(", ");
}
sb.Append(serviceName);
}
}
return sb.ToString();
}
public static bool OSSupportsExtendedProtection
{
get
{
return AuthenticationManager.OSSupportsExtendedProtection;
}
}
[SecurityPermissionAttribute(SecurityAction.LinkDemand, SerializationFormatter = true)]
void ISerializable.GetObjectData(SerializationInfo info, StreamingContext context)
{
info.AddValue(policyEnforcementName, (int)policyEnforcement);
info.AddValue(protectionScenarioName, (int)protectionScenario);
info.AddValue(customServiceNamesName, customServiceNames, typeof(ServiceNameCollection));
if (customChannelBinding == null)
{
info.AddValue(customChannelBindingName, null, typeof(byte[]));
}
else
{
byte[] channelBindingData = new byte[customChannelBinding.Size];
Marshal.Copy(customChannelBinding.DangerousGetHandle(), channelBindingData, 0, customChannelBinding.Size);
info.AddValue(customChannelBindingName, channelBindingData, typeof(byte[]));
}
}
}
}
// 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.ComponentModel;
using System.Net;
using System.Runtime.InteropServices;
using System.Runtime.Serialization;
using System.Security.Permissions;
using System.Text;
namespace System.Security.Authentication.ExtendedProtection
{
///
/// This class contains the necessary settings for specifying how Extended Protection
/// should behave. Use one of the Build* methods to create an instance of this type.
///
[Serializable]
[TypeConverter(typeof(ExtendedProtectionPolicyTypeConverter))]
public class ExtendedProtectionPolicy : ISerializable
{
private const string policyEnforcementName = "policyEnforcement";
private const string protectionScenarioName = "protectionScenario";
private const string customServiceNamesName = "customServiceNames";
private const string customChannelBindingName = "customChannelBinding";
private ServiceNameCollection customServiceNames;
private PolicyEnforcement policyEnforcement;
private ProtectionScenario protectionScenario;
private ChannelBinding customChannelBinding;
public ExtendedProtectionPolicy(PolicyEnforcement policyEnforcement,
ProtectionScenario protectionScenario,
ServiceNameCollection customServiceNames)
{
if (policyEnforcement == PolicyEnforcement.Never)
{
throw new ArgumentException(SR.GetString(SR.security_ExtendedProtectionPolicy_UseDifferentConstructorForNever), "policyEnforcement");
}
if (customServiceNames != null && customServiceNames.Count == 0)
{
throw new ArgumentException(SR.GetString(SR.security_ExtendedProtectionPolicy_NoEmptyServiceNameCollection), "customServiceNames");
}
this.policyEnforcement = policyEnforcement;
this.protectionScenario = protectionScenario;
this.customServiceNames = customServiceNames;
}
public ExtendedProtectionPolicy(PolicyEnforcement policyEnforcement,
ProtectionScenario protectionScenario,
ICollection customServiceNames)
: this(policyEnforcement, protectionScenario,
customServiceNames == null ? (ServiceNameCollection)null : new ServiceNameCollection(customServiceNames))
{
}
public ExtendedProtectionPolicy(PolicyEnforcement policyEnforcement,
ChannelBinding customChannelBinding)
{
if (policyEnforcement == PolicyEnforcement.Never)
{
throw new ArgumentException(SR.GetString(SR.security_ExtendedProtectionPolicy_UseDifferentConstructorForNever), "policyEnforcement");
}
if (customChannelBinding == null)
{
throw new ArgumentNullException("customChannelBinding");
}
this.policyEnforcement = policyEnforcement;
this.protectionScenario = ProtectionScenario.TransportSelected;
this.customChannelBinding = customChannelBinding;
}
public ExtendedProtectionPolicy(PolicyEnforcement policyEnforcement)
{
// this is the only constructor which allows PolicyEnforcement.Never.
this.policyEnforcement = policyEnforcement;
this.protectionScenario = ProtectionScenario.TransportSelected;
}
protected ExtendedProtectionPolicy(SerializationInfo info, StreamingContext context)
{
policyEnforcement = (PolicyEnforcement)info.GetInt32(policyEnforcementName);
protectionScenario = (ProtectionScenario)info.GetInt32(protectionScenarioName);
customServiceNames = (ServiceNameCollection)info.GetValue(customServiceNamesName, typeof(ServiceNameCollection));
byte[] channelBindingData = (byte[])info.GetValue(customChannelBindingName, typeof(byte[]));
if (channelBindingData != null)
{
customChannelBinding = SafeLocalFreeChannelBinding.LocalAlloc(channelBindingData.Length);
Marshal.Copy(channelBindingData, 0, customChannelBinding.DangerousGetHandle(), channelBindingData.Length);
}
}
public ServiceNameCollection CustomServiceNames
{
get { return customServiceNames; }
}
public PolicyEnforcement PolicyEnforcement
{
get { return policyEnforcement; }
}
public ProtectionScenario ProtectionScenario
{
get { return protectionScenario; }
}
public ChannelBinding CustomChannelBinding
{
get { return customChannelBinding; }
}
public override string ToString()
{
StringBuilder sb = new StringBuilder();
sb.Append("ProtectionScenario=");
sb.Append(protectionScenario.ToString());
sb.Append("; PolicyEnforcement=");
sb.Append(policyEnforcement.ToString());
sb.Append("; CustomChannelBinding=");
if (customChannelBinding == null)
{
sb.Append("");
}
else
{
sb.Append(customChannelBinding.ToString());
}
sb.Append("; ServiceNames=");
if (customServiceNames == null)
{
sb.Append("");
}
else
{
bool first = true;
foreach (string serviceName in customServiceNames)
{
if (first)
{
first = false;
}
else
{
sb.Append(", ");
}
sb.Append(serviceName);
}
}
return sb.ToString();
}
public static bool OSSupportsExtendedProtection
{
get
{
return AuthenticationManager.OSSupportsExtendedProtection;
}
}
[SecurityPermissionAttribute(SecurityAction.LinkDemand, SerializationFormatter = true)]
void ISerializable.GetObjectData(SerializationInfo info, StreamingContext context)
{
info.AddValue(policyEnforcementName, (int)policyEnforcement);
info.AddValue(protectionScenarioName, (int)protectionScenario);
info.AddValue(customServiceNamesName, customServiceNames, typeof(ServiceNameCollection));
if (customChannelBinding == null)
{
info.AddValue(customChannelBindingName, null, typeof(byte[]));
}
else
{
byte[] channelBindingData = new byte[customChannelBinding.Size];
Marshal.Copy(customChannelBinding.DangerousGetHandle(), channelBindingData, 0, customChannelBinding.Size);
info.AddValue(customChannelBindingName, channelBindingData, typeof(byte[]));
}
}
}
}
// 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
- XsdBuildProvider.cs
- Window.cs
- ExpressionVisitor.cs
- PropertyItem.cs
- Events.cs
- PersistenceTypeAttribute.cs
- TransformGroup.cs
- DefaultHttpHandler.cs
- HeaderedContentControl.cs
- LayoutEvent.cs
- TraceInternal.cs
- NgenServicingAttributes.cs
- Composition.cs
- Rotation3D.cs
- RewritingSimplifier.cs
- ListMarkerLine.cs
- Journal.cs
- AtomMaterializer.cs
- HorizontalAlignConverter.cs
- IRCollection.cs
- WindowsStatusBar.cs
- LinkTarget.cs
- Handle.cs
- GeneralTransform3DGroup.cs
- XmlObjectSerializerWriteContextComplexJson.cs
- DictionaryEntry.cs
- LinkDesigner.cs
- FullTextBreakpoint.cs
- StringAttributeCollection.cs
- WebConfigurationHostFileChange.cs
- XmlUrlResolver.cs
- XPathNodeHelper.cs
- XmlCharacterData.cs
- XmlSchemaChoice.cs
- TreeNodeEventArgs.cs
- SafeEventHandle.cs
- JsonReader.cs
- sqlser.cs
- VisualStateManager.cs
- BrowserDefinition.cs
- XmlKeywords.cs
- PersonalizationStateQuery.cs
- DesignTimeHTMLTextWriter.cs
- StructuralCache.cs
- _NestedMultipleAsyncResult.cs
- ValidationErrorEventArgs.cs
- HashHelpers.cs
- GenericWebPart.cs
- CallSite.cs
- RewritingProcessor.cs
- FilteredXmlReader.cs
- PrtCap_Public.cs
- ASCIIEncoding.cs
- ITreeGenerator.cs
- KeyTime.cs
- NavigationCommands.cs
- RectAnimationClockResource.cs
- Keyboard.cs
- Gdiplus.cs
- XmlSchemaDatatype.cs
- PhysicalOps.cs
- ReservationCollection.cs
- CodeNamespace.cs
- InfoCardRSAPKCS1KeyExchangeDeformatter.cs
- NameValueCollection.cs
- FragmentQuery.cs
- FormViewInsertEventArgs.cs
- HighlightComponent.cs
- JavaScriptString.cs
- RuntimeArgumentHandle.cs
- ResourceDisplayNameAttribute.cs
- DataGridColumnCollection.cs
- sqlpipe.cs
- XmlDictionaryWriter.cs
- ToolstripProfessionalRenderer.cs
- SymLanguageVendor.cs
- MergeExecutor.cs
- HttpListenerRequestTraceRecord.cs
- ProtocolImporter.cs
- BrowserCapabilitiesFactory35.cs
- ToolStripHighContrastRenderer.cs
- TextMarkerSource.cs
- ListControl.cs
- SelectionRange.cs
- control.ime.cs
- AffineTransform3D.cs
- ThreadExceptionDialog.cs
- PowerStatus.cs
- EdmItemCollection.cs
- GridViewRowEventArgs.cs
- PackWebResponse.cs
- Stack.cs
- MenuEventArgs.cs
- InvalidFilterCriteriaException.cs
- PassportIdentity.cs
- Enumerable.cs
- ButtonField.cs
- DocumentSequenceHighlightLayer.cs
- NavigatorOutput.cs
- PageEventArgs.cs