Code:
/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / cdf / src / WCF / IdentityModel / System / IdentityModel / Tokens / SamlEvidence.cs / 1305376 / SamlEvidence.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;
using System.Xml.Serialization;
using System.Runtime.Serialization;
using System.IdentityModel.Selectors;
public class SamlEvidence
{
readonly ImmutableCollection assertionIdReferences = new ImmutableCollection();
readonly ImmutableCollection assertions = new ImmutableCollection();
bool isReadOnly = false;
public SamlEvidence(IEnumerable assertionIdReferences)
: this(assertionIdReferences, null)
{
}
public SamlEvidence(IEnumerable assertions)
: this(null, assertions)
{
}
public SamlEvidence(IEnumerable assertionIdReferences, IEnumerable assertions)
{
if (assertionIdReferences == null && assertions == null)
throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgument(SR.GetString(SR.SAMLEvidenceShouldHaveOneAssertion));
if (assertionIdReferences != null)
{
foreach (string idReference in assertionIdReferences)
{
if (String.IsNullOrEmpty(idReference))
throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgument(SR.GetString(SR.SAMLEntityCannotBeNullOrEmpty, XD.SamlDictionary.AssertionIdReference.Value));
this.assertionIdReferences.Add(idReference);
}
}
if (assertions != null)
{
foreach (SamlAssertion assertion in assertions)
{
if (assertion == null)
throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgument(SR.GetString(SR.SAMLEntityCannotBeNullOrEmpty, XD.SamlDictionary.Assertion.Value));
this.assertions.Add(assertion);
}
}
}
public SamlEvidence()
{
}
public IList AssertionIdReferences
{
get {return this.assertionIdReferences; }
}
public IList Assertions
{
get {return this.assertions; }
}
public bool IsReadOnly
{
get { return this.isReadOnly; }
}
public void MakeReadOnly()
{
if (!this.isReadOnly)
{
foreach (SamlAssertion assertion in this.assertions)
{
assertion.MakeReadOnly();
}
this.assertionIdReferences.MakeReadOnly();
this.assertions.MakeReadOnly();
this.isReadOnly = true;
}
}
void CheckObjectValidity()
{
if ((this.assertions.Count == 0) && (this.assertionIdReferences.Count == 0))
throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new SecurityTokenException(SR.GetString(SR.SAMLEvidenceShouldHaveOneAssertion)));
}
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;
reader.MoveToContent();
reader.Read();
while (reader.IsStartElement())
{
if (reader.IsStartElement(dictionary.AssertionIdReference, dictionary.Namespace))
{
reader.MoveToContent();
this.assertionIdReferences.Add(reader.ReadString());
reader.ReadEndElement();
}
else if (reader.IsStartElement(dictionary.Assertion, dictionary.Namespace))
{
SamlAssertion assertion = new SamlAssertion();
assertion.ReadXml(reader, samlSerializer, keyInfoSerializer, outOfBandTokenResolver);
this.assertions.Add(assertion);
}
else
throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new SecurityTokenException(SR.GetString(SR.SAMLBadSchema, dictionary.Evidence.Value)));
}
if ((this.assertionIdReferences.Count == 0) && (this.assertions.Count == 0))
throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new SecurityTokenException(SR.GetString(SR.SAMLEvidenceShouldHaveOneAssertionOnRead)));
reader.MoveToContent();
reader.ReadEndElement();
}
public virtual void WriteXml(XmlDictionaryWriter writer, SamlSerializer samlSerializer, SecurityTokenSerializer keyInfoSerializer)
{
CheckObjectValidity();
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.Evidence.Value, dictionary.Namespace.Value);
for (int i = 0; i < this.assertionIdReferences.Count; i++)
{
writer.WriteStartElement(dictionary.PreferredPrefix.Value, dictionary.AssertionIdReference, dictionary.Namespace);
writer.WriteString(this.assertionIdReferences[i]);
writer.WriteEndElement();
}
for (int i = 0; i < this.assertions.Count; i++)
{
this.assertions[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;
using System.Xml.Serialization;
using System.Runtime.Serialization;
using System.IdentityModel.Selectors;
public class SamlEvidence
{
readonly ImmutableCollection assertionIdReferences = new ImmutableCollection();
readonly ImmutableCollection assertions = new ImmutableCollection();
bool isReadOnly = false;
public SamlEvidence(IEnumerable assertionIdReferences)
: this(assertionIdReferences, null)
{
}
public SamlEvidence(IEnumerable assertions)
: this(null, assertions)
{
}
public SamlEvidence(IEnumerable assertionIdReferences, IEnumerable assertions)
{
if (assertionIdReferences == null && assertions == null)
throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgument(SR.GetString(SR.SAMLEvidenceShouldHaveOneAssertion));
if (assertionIdReferences != null)
{
foreach (string idReference in assertionIdReferences)
{
if (String.IsNullOrEmpty(idReference))
throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgument(SR.GetString(SR.SAMLEntityCannotBeNullOrEmpty, XD.SamlDictionary.AssertionIdReference.Value));
this.assertionIdReferences.Add(idReference);
}
}
if (assertions != null)
{
foreach (SamlAssertion assertion in assertions)
{
if (assertion == null)
throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgument(SR.GetString(SR.SAMLEntityCannotBeNullOrEmpty, XD.SamlDictionary.Assertion.Value));
this.assertions.Add(assertion);
}
}
}
public SamlEvidence()
{
}
public IList AssertionIdReferences
{
get {return this.assertionIdReferences; }
}
public IList Assertions
{
get {return this.assertions; }
}
public bool IsReadOnly
{
get { return this.isReadOnly; }
}
public void MakeReadOnly()
{
if (!this.isReadOnly)
{
foreach (SamlAssertion assertion in this.assertions)
{
assertion.MakeReadOnly();
}
this.assertionIdReferences.MakeReadOnly();
this.assertions.MakeReadOnly();
this.isReadOnly = true;
}
}
void CheckObjectValidity()
{
if ((this.assertions.Count == 0) && (this.assertionIdReferences.Count == 0))
throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new SecurityTokenException(SR.GetString(SR.SAMLEvidenceShouldHaveOneAssertion)));
}
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;
reader.MoveToContent();
reader.Read();
while (reader.IsStartElement())
{
if (reader.IsStartElement(dictionary.AssertionIdReference, dictionary.Namespace))
{
reader.MoveToContent();
this.assertionIdReferences.Add(reader.ReadString());
reader.ReadEndElement();
}
else if (reader.IsStartElement(dictionary.Assertion, dictionary.Namespace))
{
SamlAssertion assertion = new SamlAssertion();
assertion.ReadXml(reader, samlSerializer, keyInfoSerializer, outOfBandTokenResolver);
this.assertions.Add(assertion);
}
else
throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new SecurityTokenException(SR.GetString(SR.SAMLBadSchema, dictionary.Evidence.Value)));
}
if ((this.assertionIdReferences.Count == 0) && (this.assertions.Count == 0))
throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new SecurityTokenException(SR.GetString(SR.SAMLEvidenceShouldHaveOneAssertionOnRead)));
reader.MoveToContent();
reader.ReadEndElement();
}
public virtual void WriteXml(XmlDictionaryWriter writer, SamlSerializer samlSerializer, SecurityTokenSerializer keyInfoSerializer)
{
CheckObjectValidity();
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.Evidence.Value, dictionary.Namespace.Value);
for (int i = 0; i < this.assertionIdReferences.Count; i++)
{
writer.WriteStartElement(dictionary.PreferredPrefix.Value, dictionary.AssertionIdReference, dictionary.Namespace);
writer.WriteString(this.assertionIdReferences[i]);
writer.WriteEndElement();
}
for (int i = 0; i < this.assertions.Count; i++)
{
this.assertions[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
- CompiledXpathExpr.cs
- WebPartConnectVerb.cs
- SqlClientWrapperSmiStreamChars.cs
- RootBrowserWindow.cs
- BinaryObjectInfo.cs
- SqlTypesSchemaImporter.cs
- SqlCommandBuilder.cs
- ListViewSortEventArgs.cs
- SecurityTokenException.cs
- Odbc32.cs
- CollectionEditVerbManager.cs
- ValidationSummary.cs
- QilLiteral.cs
- ProfileBuildProvider.cs
- HtmlElementErrorEventArgs.cs
- SmtpMail.cs
- StringFunctions.cs
- TemplateColumn.cs
- ItemCheckedEvent.cs
- UserPrincipalNameElement.cs
- HttpListenerResponse.cs
- EmbossBitmapEffect.cs
- Figure.cs
- NeutralResourcesLanguageAttribute.cs
- DbDataReader.cs
- BasicExpressionVisitor.cs
- SystemInformation.cs
- DisposableCollectionWrapper.cs
- __FastResourceComparer.cs
- SoapReflector.cs
- TextStore.cs
- LocalBuilder.cs
- GetWinFXPath.cs
- IndentedTextWriter.cs
- AssertFilter.cs
- Timeline.cs
- CatalogPart.cs
- WorkflowValidationFailedException.cs
- embossbitmapeffect.cs
- DelegateTypeInfo.cs
- Decimal.cs
- XmlSchemaSimpleContentRestriction.cs
- StrokeCollectionConverter.cs
- DesignSurfaceServiceContainer.cs
- Rotation3DAnimation.cs
- _FtpDataStream.cs
- DataGridViewComboBoxEditingControl.cs
- ScriptingRoleServiceSection.cs
- MasterPageBuildProvider.cs
- DataTemplateKey.cs
- BitmapEffectDrawingContent.cs
- ObjectListSelectEventArgs.cs
- RequestCachePolicy.cs
- UseLicense.cs
- ContextMenuStripGroupCollection.cs
- RolePrincipal.cs
- Animatable.cs
- DSASignatureDeformatter.cs
- DeclarationUpdate.cs
- XmlSchemaSimpleTypeRestriction.cs
- EntitySetDataBindingList.cs
- XmlSchemaNotation.cs
- PopupControlService.cs
- ISAPIApplicationHost.cs
- OleDbParameter.cs
- ImageSource.cs
- SoapSchemaMember.cs
- PartialTrustHelpers.cs
- MailHeaderInfo.cs
- SQLInt32.cs
- ConfigurationValues.cs
- SigningProgress.cs
- X509Utils.cs
- FontSizeConverter.cs
- OleDbRowUpdatedEvent.cs
- BinaryMethodMessage.cs
- FailedToStartupUIException.cs
- ObjectViewFactory.cs
- QilLiteral.cs
- FunctionQuery.cs
- BlurEffect.cs
- NavigationHelper.cs
- RemoteWebConfigurationHostServer.cs
- PointAnimation.cs
- WebSysDisplayNameAttribute.cs
- DataRelationPropertyDescriptor.cs
- COM2Enum.cs
- Model3D.cs
- ToolStripContentPanel.cs
- EndOfStreamException.cs
- WaitHandleCannotBeOpenedException.cs
- SqlMethodCallConverter.cs
- DetailsViewRowCollection.cs
- InfoCardRSACryptoProvider.cs
- CrossAppDomainChannel.cs
- ThicknessAnimationUsingKeyFrames.cs
- ObfuscateAssemblyAttribute.cs
- TreeNodeSelectionProcessor.cs
- DelegatingTypeDescriptionProvider.cs
- WizardStepBase.cs