Code:
/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / cdf / src / WCF / IdentityModel / System / IdentityModel / Tokens / SamlConditions.cs / 1305376 / 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.
//-----------------------------------------------------------------------------
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.
Link Menu

This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- Duration.cs
- SByteConverter.cs
- LocalizeDesigner.cs
- CodeComment.cs
- DataTableMappingCollection.cs
- AppLevelCompilationSectionCache.cs
- IsolatedStorage.cs
- PersonalizableAttribute.cs
- Camera.cs
- TemplateLookupAction.cs
- ButtonPopupAdapter.cs
- MenuItem.cs
- AttributeTableBuilder.cs
- CultureMapper.cs
- WebPartDisplayModeCancelEventArgs.cs
- SQLGuidStorage.cs
- ACE.cs
- HierarchicalDataSourceControl.cs
- ToolBarPanel.cs
- CounterSet.cs
- ContextMenuService.cs
- MouseGesture.cs
- SqlInfoMessageEvent.cs
- Label.cs
- DataGridViewDataConnection.cs
- DESCryptoServiceProvider.cs
- ProxyWebPartManager.cs
- FrameworkContentElementAutomationPeer.cs
- MetadataItemEmitter.cs
- RoutedEventValueSerializer.cs
- PeerChannelFactory.cs
- QilPatternVisitor.cs
- EntityUtil.cs
- SoapAttributes.cs
- EntityProxyTypeInfo.cs
- MULTI_QI.cs
- DomainUpDown.cs
- BitmapSourceSafeMILHandle.cs
- ColorConverter.cs
- VariantWrapper.cs
- TextCharacters.cs
- AssertFilter.cs
- TreeViewCancelEvent.cs
- PluralizationService.cs
- SqlBulkCopy.cs
- TextDecorationUnitValidation.cs
- EnterpriseServicesHelper.cs
- Win32PrintDialog.cs
- RegionInfo.cs
- InProcStateClientManager.cs
- DependencyPropertyHelper.cs
- SqlBuilder.cs
- SpeechSeg.cs
- BitmapEffectInput.cs
- PrtCap_Reader.cs
- PathFigureCollection.cs
- ColumnResizeUndoUnit.cs
- VBIdentifierName.cs
- util.cs
- TextBlockAutomationPeer.cs
- AtomicFile.cs
- FrameworkPropertyMetadata.cs
- ProcessHostFactoryHelper.cs
- StringCollection.cs
- DataGridViewCellStyleConverter.cs
- ContentDisposition.cs
- XPathSingletonIterator.cs
- ButtonStandardAdapter.cs
- AddInProcess.cs
- LinqDataSourceDisposeEventArgs.cs
- HyperLinkField.cs
- AttachedProperty.cs
- ThreadAbortException.cs
- EmptyCollection.cs
- LinkClickEvent.cs
- DrawListViewSubItemEventArgs.cs
- RepeatInfo.cs
- HTTPNotFoundHandler.cs
- ExtensionWindowResizeGrip.cs
- SecurityPermission.cs
- StateItem.cs
- Inflater.cs
- LinkClickEvent.cs
- OneWayElement.cs
- SolidBrush.cs
- MILUtilities.cs
- RelationshipWrapper.cs
- DataGridViewRowPrePaintEventArgs.cs
- SafeWaitHandle.cs
- DataServiceQueryException.cs
- DataGridCell.cs
- SHA256.cs
- UIElement3D.cs
- UriParserTemplates.cs
- MimePart.cs
- DurationConverter.cs
- PropertyItemInternal.cs
- CultureMapper.cs
- DbFunctionCommandTree.cs
- SelectionBorderGlyph.cs