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
- XLinq.cs
- PasswordRecoveryAutoFormat.cs
- QueryCacheKey.cs
- XmlSchemaDocumentation.cs
- DependencyObjectType.cs
- StrokeFIndices.cs
- SQLBinaryStorage.cs
- DebugHandleTracker.cs
- PointCollection.cs
- KnownBoxes.cs
- XmlSchemaAttributeGroup.cs
- CallbackValidator.cs
- LocalFileSettingsProvider.cs
- ParameterBuilder.cs
- DateTimeFormatInfoScanner.cs
- DefaultShape.cs
- isolationinterop.cs
- FilteredXmlReader.cs
- SiteMapDataSource.cs
- XmlChildNodes.cs
- Permission.cs
- DependencyPropertyHelper.cs
- OdbcTransaction.cs
- UriWriter.cs
- PngBitmapDecoder.cs
- BlurBitmapEffect.cs
- FilterElement.cs
- ApplicationActivator.cs
- DesignTimeType.cs
- CultureSpecificStringDictionary.cs
- ListViewGroupConverter.cs
- XPathQilFactory.cs
- ControlIdConverter.cs
- CompilerLocalReference.cs
- FileDialog_Vista_Interop.cs
- cache.cs
- WindowsTitleBar.cs
- GlobalizationSection.cs
- HtmlInputCheckBox.cs
- MaskDescriptor.cs
- QueryAccessibilityHelpEvent.cs
- SelectionHighlightInfo.cs
- EmbeddedMailObjectCollectionEditor.cs
- ComboBoxRenderer.cs
- StringAnimationUsingKeyFrames.cs
- SystemIPGlobalStatistics.cs
- OptimalTextSource.cs
- DbConnectionFactory.cs
- Control.cs
- FileLoadException.cs
- Perspective.cs
- PropertyChangedEventArgs.cs
- ThrowHelper.cs
- LexicalChunk.cs
- path.cs
- EntityModelSchemaGenerator.cs
- Size.cs
- Int32AnimationBase.cs
- Substitution.cs
- ExtendedProtectionPolicyTypeConverter.cs
- CodeTypeConstructor.cs
- DoubleAnimation.cs
- ProjectionCamera.cs
- SystemDiagnosticsSection.cs
- MouseGesture.cs
- WebDescriptionAttribute.cs
- System.Data_BID.cs
- GridViewUpdatedEventArgs.cs
- TextDecorationCollection.cs
- TokenBasedSet.cs
- TimeSpan.cs
- WebPageTraceListener.cs
- DataGridItemEventArgs.cs
- CngAlgorithmGroup.cs
- CorrelationToken.cs
- MetabaseServerConfig.cs
- CallSiteBinder.cs
- SocketInformation.cs
- ContentPlaceHolder.cs
- ListMarkerLine.cs
- PerfCounters.cs
- HttpServerVarsCollection.cs
- Base64Decoder.cs
- DashStyle.cs
- XamlWriter.cs
- InputElement.cs
- ModelPropertyDescriptor.cs
- SchemaComplexType.cs
- SiteIdentityPermission.cs
- FigureParagraph.cs
- ControlCollection.cs
- UnknownMessageReceivedEventArgs.cs
- InkCanvasSelectionAdorner.cs
- DataBoundControlAdapter.cs
- UdpDiscoveryMessageFilter.cs
- SchemaType.cs
- WebServiceClientProxyGenerator.cs
- SqlTransaction.cs
- SectionXmlInfo.cs
- StylusPointCollection.cs