Code:
/ WCF / WCF / 3.5.30729.1 / untmp / Orcas / SP / ndp / cdf / src / WCF / IdentityModel / System / IdentityModel / Tokens / SamlConditions.cs / 1 / SamlConditions.cs
//------------------------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
//-----------------------------------------------------------------------------
namespace System.IdentityModel.Tokens
{
using System.Collections;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Xml.Serialization;
using System.Xml;
using System.Runtime.Serialization;
using System.Globalization;
using System.IdentityModel.Selectors;
public class SamlConditions
{
readonly ImmutableCollection conditions = new ImmutableCollection();
bool isReadOnly = false;
// Calculate once
DateTime notBefore = SecurityUtils.MinUtcDateTime;
DateTime notOnOrAfter = SecurityUtils.MaxUtcDateTime;
public SamlConditions()
{
}
public SamlConditions(DateTime notBefore, DateTime notOnOrAfter)
: this(notBefore, notOnOrAfter, null)
{
}
public SamlConditions(DateTime notBefore, DateTime notOnOrAfter,
IEnumerable conditions
)
{
this.notBefore = notBefore.ToUniversalTime();
this.notOnOrAfter = notOnOrAfter.ToUniversalTime();
if (conditions != null)
{
foreach (SamlCondition condition in conditions)
{
if (condition == null)
throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgument(SR.GetString(SR.SAMLEntityCannotBeNullOrEmpty, XD.SamlDictionary.Condition.Value));
this.conditions.Add(condition);
}
}
}
public IList Conditions
{
get {return this.conditions; }
}
public DateTime NotBefore
{
get {return this.notBefore; }
set
{
if (isReadOnly)
throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.GetString(SR.ObjectIsReadOnly)));
this.notBefore = value;
}
}
public DateTime NotOnOrAfter
{
get {return this.notOnOrAfter; }
set
{
if (isReadOnly)
throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.GetString(SR.ObjectIsReadOnly)));
this.notOnOrAfter = value;
}
}
public bool IsReadOnly
{
get { return this.isReadOnly; }
}
public void MakeReadOnly()
{
if (!this.isReadOnly)
{
this.conditions.MakeReadOnly();
foreach (SamlCondition condition in this.conditions)
{
condition.MakeReadOnly();
}
this.isReadOnly = true;
}
}
public virtual void ReadXml(XmlDictionaryReader reader, SamlSerializer samlSerializer, SecurityTokenSerializer keyInfoSerializer, SecurityTokenResolver outOfBandTokenResolver)
{
if (reader == null)
throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentNullException("reader"));
if (samlSerializer == null)
throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentNullException("samlSerializer"));
#pragma warning suppress 56506 // samlSerializer.DictionaryManager is never null.
SamlDictionary dictionary = samlSerializer.DictionaryManager.SamlDictionary;
string time = reader.GetAttribute(dictionary.NotBefore, null);
if (!String.IsNullOrEmpty(time))
this.notBefore = DateTime.ParseExact(
time, SamlConstants.AcceptedDateTimeFormats, DateTimeFormatInfo.InvariantInfo, DateTimeStyles.None).ToUniversalTime();
time = reader.GetAttribute(dictionary.NotOnOrAfter, null);
if (!String.IsNullOrEmpty(time))
this.notOnOrAfter = DateTime.ParseExact(
time, SamlConstants.AcceptedDateTimeFormats, DateTimeFormatInfo.InvariantInfo, DateTimeStyles.None).ToUniversalTime();
// Saml Conditions element is an optional element and all its child element
// are optional as well. So we can have a empty element
// in a valid Saml token.
if (reader.IsEmptyElement)
{
// Just issue a read to read the Empty element.
reader.MoveToContent();
reader.Read();
return;
}
reader.MoveToContent();
reader.Read();
while (reader.IsStartElement())
{
SamlCondition condition = samlSerializer.LoadCondition(reader, keyInfoSerializer, outOfBandTokenResolver);
if (condition == null)
throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new SecurityTokenException(SR.GetString(SR.SAMLUnableToLoadCondtion)));
this.conditions.Add(condition);
}
reader.MoveToContent();
reader.ReadEndElement();
}
public virtual void WriteXml(XmlDictionaryWriter writer, SamlSerializer samlSerializer, SecurityTokenSerializer keyInfoSerializer)
{
if (writer == null)
throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentNullException("writer"));
if (samlSerializer == null)
throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentNullException("samlSerializer"));
#pragma warning suppress 56506 // samlSerializer.DictionaryManager is never null.
SamlDictionary dictionary = samlSerializer.DictionaryManager.SamlDictionary;
writer.WriteStartElement(dictionary.PreferredPrefix.Value, dictionary.Conditions, dictionary.Namespace);
if (this.notBefore != SecurityUtils.MinUtcDateTime)
{
writer.WriteStartAttribute(dictionary.NotBefore, null);
writer.WriteString(this.notBefore.ToString(SamlConstants.GeneratedDateTimeFormat, DateTimeFormatInfo.InvariantInfo));
writer.WriteEndAttribute();
}
if (this.notOnOrAfter != SecurityUtils.MaxUtcDateTime)
{
writer.WriteStartAttribute(dictionary.NotOnOrAfter, null);
writer.WriteString(this.notOnOrAfter.ToString(SamlConstants.GeneratedDateTimeFormat, DateTimeFormatInfo.InvariantInfo));
writer.WriteEndAttribute();
}
for (int i = 0; i < this.conditions.Count; i++)
{
this.conditions[i].WriteXml(writer, samlSerializer, keyInfoSerializer);
}
writer.WriteEndElement();
}
}
}
// 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
- TaiwanCalendar.cs
- CapabilitiesUse.cs
- XPathEmptyIterator.cs
- CustomUserNameSecurityTokenAuthenticator.cs
- XmlSchemaExporter.cs
- AsyncStreamReader.cs
- Script.cs
- HotCommands.cs
- cookiecollection.cs
- ActivityValidator.cs
- DeviceContext.cs
- PopOutPanel.cs
- DocumentViewerAutomationPeer.cs
- VBCodeProvider.cs
- MediaContextNotificationWindow.cs
- FixedNode.cs
- EventDescriptor.cs
- DataSetUtil.cs
- SessionStateItemCollection.cs
- ComplexObject.cs
- ElapsedEventArgs.cs
- UnknownBitmapDecoder.cs
- WebPermission.cs
- AdjustableArrowCap.cs
- ChunkedMemoryStream.cs
- ParenthesizePropertyNameAttribute.cs
- DataGridLinkButton.cs
- XPathSelfQuery.cs
- DateTimeAutomationPeer.cs
- ZipFileInfoCollection.cs
- AmbientEnvironment.cs
- ModuleBuilder.cs
- PngBitmapEncoder.cs
- HttpCachePolicy.cs
- EventLogInternal.cs
- ConnectionPointCookie.cs
- PolyQuadraticBezierSegment.cs
- bidPrivateBase.cs
- SHA512.cs
- Completion.cs
- ToolStripSplitButton.cs
- PtsHelper.cs
- ZoneButton.cs
- HostedHttpRequestAsyncResult.cs
- ProcessThreadCollection.cs
- UriTemplateClientFormatter.cs
- SchemaEntity.cs
- FormatConvertedBitmap.cs
- RoleManagerEventArgs.cs
- DataGridRowsPresenter.cs
- HttpModulesInstallComponent.cs
- MetabaseSettingsIis7.cs
- SqlUserDefinedTypeAttribute.cs
- xml.cs
- TextBoxView.cs
- WebScriptServiceHost.cs
- AttributeTableBuilder.cs
- BitmapDecoder.cs
- UnmanagedMarshal.cs
- JavascriptCallbackMessageInspector.cs
- ExceptionHandlersDesigner.cs
- RowCache.cs
- Command.cs
- ContractBase.cs
- ConnectionsZone.cs
- FontFamilyConverter.cs
- SqlCommandBuilder.cs
- XamlFxTrace.cs
- XmlnsDefinitionAttribute.cs
- __TransparentProxy.cs
- VectorKeyFrameCollection.cs
- DataSourceHelper.cs
- Configuration.cs
- HTTPNotFoundHandler.cs
- AutoGeneratedFieldProperties.cs
- DefaultPrintController.cs
- StreamAsIStream.cs
- HMACSHA384.cs
- ObjectDataSourceMethodEventArgs.cs
- ManualResetEvent.cs
- ScrollViewer.cs
- DataTableClearEvent.cs
- XMLSchema.cs
- TableRow.cs
- SelectionChangedEventArgs.cs
- HashUtility.cs
- ApplicationCommands.cs
- Encoding.cs
- RouteItem.cs
- ObjectComplexPropertyMapping.cs
- ExtentJoinTreeNode.cs
- ResXResourceWriter.cs
- BindingsSection.cs
- NamedElement.cs
- AssemblyCollection.cs
- NgenServicingAttributes.cs
- WindowsFont.cs
- Main.cs
- DirectoryGroupQuery.cs
- LongValidatorAttribute.cs