Code:
/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / cdf / src / WCF / IdentityModel / System / IdentityModel / Tokens / SamlAttributeStatement.cs / 1305376 / SamlAttributeStatement.cs
//------------------------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
//-----------------------------------------------------------------------------
namespace System.IdentityModel.Tokens
{
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Globalization;
using System.IdentityModel;
using System.IdentityModel.Claims;
using System.IdentityModel.Selectors;
using System.Runtime.Serialization;
using System.Xml.Serialization;
using System.Xml;
public class SamlAttributeStatement : SamlSubjectStatement
{
readonly ImmutableCollection attributes = new ImmutableCollection();
bool isReadOnly = false;
public SamlAttributeStatement()
{
}
public SamlAttributeStatement(SamlSubject samlSubject, IEnumerable attributes)
: base(samlSubject)
{
if (attributes == null)
throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentNullException("attributes"));
foreach (SamlAttribute attribute in attributes)
{
if (attribute == null)
throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgument(SR.GetString(SR.SAMLEntityCannotBeNullOrEmpty, XD.SamlDictionary.Attribute.Value));
this.attributes.Add(attribute);
}
CheckObjectValidity();
}
public IList Attributes
{
get { return this.attributes; }
}
public override bool IsReadOnly
{
get { return this.isReadOnly; }
}
public override void MakeReadOnly()
{
if (!this.isReadOnly)
{
foreach (SamlAttribute attribute in attributes)
{
attribute.MakeReadOnly();
}
this.attributes.MakeReadOnly();
this.isReadOnly = true;
}
}
void CheckObjectValidity()
{
if (this.SamlSubject == null)
throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new SecurityTokenException(SR.GetString(SR.SAMLSubjectStatementRequiresSubject)));
if (this.attributes.Count == 0)
throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new SecurityTokenException(SR.GetString(SR.SAMLAttributeShouldHaveOneValue)));
}
public override 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();
if (reader.IsStartElement(dictionary.Subject, dictionary.Namespace))
{
SamlSubject subject = new SamlSubject();
subject.ReadXml(reader, samlSerializer, keyInfoSerializer, outOfBandTokenResolver);
base.SamlSubject = subject;
}
else
{
// SAML Subject is a required Attribute Statement clause.
throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new SecurityTokenException(SR.GetString(SR.SAMLAttributeStatementMissingSubjectOnRead)));
}
while (reader.IsStartElement())
{
if (reader.IsStartElement(dictionary.Attribute, dictionary.Namespace))
{
// SAML Attribute is a extensibility point. So ask the SAML serializer
// to load this part.
SamlAttribute attribute = samlSerializer.LoadAttribute(reader, keyInfoSerializer, outOfBandTokenResolver);
if (attribute == null)
throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new SecurityTokenException(SR.GetString(SR.SAMLUnableToLoadAttribute)));
this.attributes.Add(attribute);
}
else
{
break;
}
}
if (this.attributes.Count == 0)
{
// Each Attribute statement should have at least one attribute.
throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new SecurityTokenException(SR.GetString(SR.SAMLAttributeStatementMissingAttributeOnRead)));
}
reader.MoveToContent();
reader.ReadEndElement();
}
public override 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.AttributeStatement, dictionary.Namespace);
this.SamlSubject.WriteXml(writer, samlSerializer, keyInfoSerializer);
for (int i = 0; i < this.attributes.Count; i++)
{
this.attributes[i].WriteXml(writer, samlSerializer, keyInfoSerializer);
}
writer.WriteEndElement();
}
protected override void AddClaimsToList(IList claims)
{
if (claims == null)
throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("claims");
for (int i = 0; i < attributes.Count; i++)
{
if (attributes[i] != null)
{
ReadOnlyCollection attributeClaims = attributes[i].ExtractClaims();
if (attributeClaims != null)
{
for (int j = 0; j < attributeClaims.Count; ++j)
if (attributeClaims[j] != null)
claims.Add(attributeClaims[j]);
}
}
}
}
}
}
// 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.Generic;
using System.Collections.ObjectModel;
using System.Globalization;
using System.IdentityModel;
using System.IdentityModel.Claims;
using System.IdentityModel.Selectors;
using System.Runtime.Serialization;
using System.Xml.Serialization;
using System.Xml;
public class SamlAttributeStatement : SamlSubjectStatement
{
readonly ImmutableCollection attributes = new ImmutableCollection();
bool isReadOnly = false;
public SamlAttributeStatement()
{
}
public SamlAttributeStatement(SamlSubject samlSubject, IEnumerable attributes)
: base(samlSubject)
{
if (attributes == null)
throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentNullException("attributes"));
foreach (SamlAttribute attribute in attributes)
{
if (attribute == null)
throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgument(SR.GetString(SR.SAMLEntityCannotBeNullOrEmpty, XD.SamlDictionary.Attribute.Value));
this.attributes.Add(attribute);
}
CheckObjectValidity();
}
public IList Attributes
{
get { return this.attributes; }
}
public override bool IsReadOnly
{
get { return this.isReadOnly; }
}
public override void MakeReadOnly()
{
if (!this.isReadOnly)
{
foreach (SamlAttribute attribute in attributes)
{
attribute.MakeReadOnly();
}
this.attributes.MakeReadOnly();
this.isReadOnly = true;
}
}
void CheckObjectValidity()
{
if (this.SamlSubject == null)
throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new SecurityTokenException(SR.GetString(SR.SAMLSubjectStatementRequiresSubject)));
if (this.attributes.Count == 0)
throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new SecurityTokenException(SR.GetString(SR.SAMLAttributeShouldHaveOneValue)));
}
public override 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();
if (reader.IsStartElement(dictionary.Subject, dictionary.Namespace))
{
SamlSubject subject = new SamlSubject();
subject.ReadXml(reader, samlSerializer, keyInfoSerializer, outOfBandTokenResolver);
base.SamlSubject = subject;
}
else
{
// SAML Subject is a required Attribute Statement clause.
throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new SecurityTokenException(SR.GetString(SR.SAMLAttributeStatementMissingSubjectOnRead)));
}
while (reader.IsStartElement())
{
if (reader.IsStartElement(dictionary.Attribute, dictionary.Namespace))
{
// SAML Attribute is a extensibility point. So ask the SAML serializer
// to load this part.
SamlAttribute attribute = samlSerializer.LoadAttribute(reader, keyInfoSerializer, outOfBandTokenResolver);
if (attribute == null)
throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new SecurityTokenException(SR.GetString(SR.SAMLUnableToLoadAttribute)));
this.attributes.Add(attribute);
}
else
{
break;
}
}
if (this.attributes.Count == 0)
{
// Each Attribute statement should have at least one attribute.
throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new SecurityTokenException(SR.GetString(SR.SAMLAttributeStatementMissingAttributeOnRead)));
}
reader.MoveToContent();
reader.ReadEndElement();
}
public override 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.AttributeStatement, dictionary.Namespace);
this.SamlSubject.WriteXml(writer, samlSerializer, keyInfoSerializer);
for (int i = 0; i < this.attributes.Count; i++)
{
this.attributes[i].WriteXml(writer, samlSerializer, keyInfoSerializer);
}
writer.WriteEndElement();
}
protected override void AddClaimsToList(IList claims)
{
if (claims == null)
throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("claims");
for (int i = 0; i < attributes.Count; i++)
{
if (attributes[i] != null)
{
ReadOnlyCollection attributeClaims = attributes[i].ExtractClaims();
if (attributeClaims != null)
{
for (int j = 0; j < attributeClaims.Count; ++j)
if (attributeClaims[j] != null)
claims.Add(attributeClaims[j]);
}
}
}
}
}
}
// 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
- _ScatterGatherBuffers.cs
- CompilationRelaxations.cs
- DocumentViewerHelper.cs
- CurrencyWrapper.cs
- AutomationAttributeInfo.cs
- XmlBoundElement.cs
- RowToFieldTransformer.cs
- InternalConfigRoot.cs
- SqlConnectionManager.cs
- DispatcherOperation.cs
- PermissionAttributes.cs
- ToolStripOverflowButton.cs
- MetadataPropertyAttribute.cs
- LayoutDump.cs
- SqlMethodTransformer.cs
- MediaScriptCommandRoutedEventArgs.cs
- GroupBox.cs
- Size.cs
- IntAverageAggregationOperator.cs
- FrameworkElementAutomationPeer.cs
- ToolStripPanelRenderEventArgs.cs
- HttpApplicationStateWrapper.cs
- XmlBoundElement.cs
- ObjectItemNoOpAssemblyLoader.cs
- XmlILIndex.cs
- XmlSchemaParticle.cs
- HtmlSelect.cs
- WinEventQueueItem.cs
- OletxTransactionFormatter.cs
- CheckBoxField.cs
- TemplateBindingExtensionConverter.cs
- ModelTreeManager.cs
- RoleGroup.cs
- RoutedEventConverter.cs
- MetadataException.cs
- ViewEvent.cs
- RepeatBehavior.cs
- GatewayIPAddressInformationCollection.cs
- RadialGradientBrush.cs
- RawStylusInputCustomData.cs
- StylusCaptureWithinProperty.cs
- SizeConverter.cs
- OleDbException.cs
- OutputCacheSettings.cs
- SafeLibraryHandle.cs
- ResolveNameEventArgs.cs
- externdll.cs
- TextRange.cs
- ConfigurationManager.cs
- ByteAnimationUsingKeyFrames.cs
- CopyCodeAction.cs
- ETagAttribute.cs
- TraceSource.cs
- Pair.cs
- SystemGatewayIPAddressInformation.cs
- SecureUICommand.cs
- TreeBuilderBamlTranslator.cs
- AsyncInvokeContext.cs
- ConnectionConsumerAttribute.cs
- SamlAssertionKeyIdentifierClause.cs
- AudioFileOut.cs
- AddInStore.cs
- FrameworkTextComposition.cs
- XDRSchema.cs
- Control.cs
- OperationCanceledException.cs
- DependencyPropertyHelper.cs
- ParentUndoUnit.cs
- Stackframe.cs
- QueryResponse.cs
- OracleBoolean.cs
- MembershipUser.cs
- SmtpException.cs
- MaterialGroup.cs
- ListBoxAutomationPeer.cs
- SelectionPatternIdentifiers.cs
- ISAPIWorkerRequest.cs
- BitArray.cs
- PeerNodeAddress.cs
- SecurityRuntime.cs
- DateTimePickerDesigner.cs
- SqlNotificationRequest.cs
- IProvider.cs
- FrameworkRichTextComposition.cs
- SoapCommonClasses.cs
- UIInitializationException.cs
- TypeGeneratedEventArgs.cs
- ListSortDescription.cs
- EventSinkHelperWriter.cs
- CustomGrammar.cs
- newinstructionaction.cs
- DataList.cs
- TextSpanModifier.cs
- Activator.cs
- InputLanguageCollection.cs
- _HTTPDateParse.cs
- FigureParaClient.cs
- XmlSchemaInfo.cs
- Helper.cs
- DbTransaction.cs