Code:
/ WCF / WCF / 3.5.30729.1 / untmp / Orcas / SP / ndp / cdf / src / WCF / ServiceModel / System / ServiceModel / Security / IssuedTokensHeader.cs / 1 / IssuedTokensHeader.cs
//------------------------------------------------------------ // Copyright (c) Microsoft Corporation. All rights reserved. //----------------------------------------------------------- namespace System.ServiceModel.Security { using System.Collections.Generic; using System.ServiceModel.Channels; using System.Collections.ObjectModel; using System.Globalization; using System.ServiceModel; using System.Xml; using System.IdentityModel.Selectors; using System.ServiceModel.Diagnostics; sealed class IssuedTokensHeader : MessageHeader { ReadOnlyCollectiontokenIssuances; SecurityStandardsManager standardsManager; string actor; bool mustUnderstand; bool relay; bool isRefParam; public IssuedTokensHeader(RequestSecurityTokenResponse tokenIssuance, MessageSecurityVersion version, SecurityTokenSerializer tokenSerializer) : this(tokenIssuance, new SecurityStandardsManager(version, tokenSerializer)) { } public IssuedTokensHeader(RequestSecurityTokenResponse tokenIssuance, SecurityStandardsManager standardsManager) : base() { if (tokenIssuance == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("tokenIssuance"); } Collection coll = new Collection (); coll.Add(tokenIssuance); Initialize(coll, standardsManager); } public IssuedTokensHeader(IEnumerable tokenIssuances, SecurityStandardsManager standardsManager) : base() { if (tokenIssuances == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("tokenIssuances"); } int index = 0; Collection coll = new Collection (); foreach (RequestSecurityTokenResponse rstr in tokenIssuances) { if (rstr == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(String.Format(CultureInfo.InvariantCulture, "tokenIssuances[{0}]", index)); } coll.Add(rstr); ++index; } Initialize(coll, standardsManager); } void Initialize(Collection coll, SecurityStandardsManager standardsManager) { if (standardsManager == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentNullException("standardsManager")); } this.standardsManager = standardsManager; this.tokenIssuances = new ReadOnlyCollection (coll); this.actor = base.Actor; this.mustUnderstand = base.MustUnderstand; this.relay = base.Relay; } public IssuedTokensHeader(XmlReader xmlReader, MessageVersion version, SecurityStandardsManager standardsManager) : base() { if (xmlReader == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("xmlReader"); } if (standardsManager == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentNullException("standardsManager")); } this.standardsManager = standardsManager; XmlDictionaryReader reader = XmlDictionaryReader.CreateDictionaryReader(xmlReader); MessageHeader.GetHeaderAttributes(reader, version, out this.actor, out this.mustUnderstand, out this.relay, out this.isRefParam); reader.ReadStartElement(this.Name, this.Namespace); Collection coll = new Collection (); if (this.standardsManager.TrustDriver.IsAtRequestSecurityTokenResponseCollection(reader)) { RequestSecurityTokenResponseCollection rstrColl = this.standardsManager.TrustDriver.CreateRequestSecurityTokenResponseCollection(reader); foreach (RequestSecurityTokenResponse rstr in rstrColl.RstrCollection) { coll.Add(rstr); } } else { RequestSecurityTokenResponse rstr = this.standardsManager.TrustDriver.CreateRequestSecurityTokenResponse(reader); coll.Add(rstr); } this.tokenIssuances = new ReadOnlyCollection (coll); reader.ReadEndElement(); } public ReadOnlyCollection TokenIssuances { get { return this.tokenIssuances; } } public override string Actor { get { return this.actor; } } public override bool IsReferenceParameter { get { return this.isRefParam; } } public override bool MustUnderstand { get { return this.mustUnderstand; } } public override bool Relay { get { return this.relay; } } public override string Name { get { return this.standardsManager.TrustDriver.IssuedTokensHeaderName; } } public override string Namespace { get { return this.standardsManager.TrustDriver.IssuedTokensHeaderNamespace; } } protected override void OnWriteHeaderContents(XmlDictionaryWriter writer, MessageVersion messageVersion) { if (this.tokenIssuances.Count == 1) { this.standardsManager.TrustDriver.WriteRequestSecurityTokenResponse(this.tokenIssuances[0], writer); } else { RequestSecurityTokenResponseCollection rstrCollection = new RequestSecurityTokenResponseCollection(this.tokenIssuances, this.standardsManager); rstrCollection.WriteTo(writer); } } internal static Collection ExtractIssuances(Message message, MessageSecurityVersion version, WSSecurityTokenSerializer tokenSerializer, string[] actors, XmlQualifiedName expectedAppliesToQName) { return ExtractIssuances(message, new SecurityStandardsManager(version, tokenSerializer), actors, expectedAppliesToQName); } // if expectedAppliesToQName is null all issuances matching the actors are returned. internal static Collection ExtractIssuances(Message message, SecurityStandardsManager standardsManager, string[] actors, XmlQualifiedName expectedAppliesToQName) { if (message == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("message"); } if (standardsManager == null) { standardsManager = SecurityStandardsManager.DefaultInstance; } if (actors == null) { throw TraceUtility.ThrowHelperArgumentNull("actors", message); } Collection issuances = new Collection (); for (int i = 0; i < message.Headers.Count; ++i) { if (message.Headers[i].Name == standardsManager.TrustDriver.IssuedTokensHeaderName && message.Headers[i].Namespace == standardsManager.TrustDriver.IssuedTokensHeaderNamespace) { bool isValidActor = false; for (int j = 0; j < actors.Length; ++j) { if (actors[j] == message.Headers[i].Actor) { isValidActor = true; break; } } if (!isValidActor) { continue; } IssuedTokensHeader issuedTokensHeader = new IssuedTokensHeader(message.Headers.GetReaderAtHeader(i), message.Version, standardsManager); for (int k = 0; k < issuedTokensHeader.TokenIssuances.Count; ++k) { bool isMatch; if (expectedAppliesToQName != null) { string issuanceAppliesToName; string issuanceAppliesToNs; issuedTokensHeader.TokenIssuances[k].GetAppliesToQName(out issuanceAppliesToName, out issuanceAppliesToNs); if (issuanceAppliesToName == expectedAppliesToQName.Name && issuanceAppliesToNs == expectedAppliesToQName.Namespace) { isMatch = true; } else { isMatch = false; } } else { isMatch = true; } if (isMatch) { issuances.Add(issuedTokensHeader.TokenIssuances[k]); } } } } return issuances; } } } // 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
- TransformationRules.cs
- CatalogPart.cs
- PublisherIdentityPermission.cs
- StructuredTypeEmitter.cs
- UserControl.cs
- GcHandle.cs
- CodeAccessPermission.cs
- FragmentQuery.cs
- WebPartTransformer.cs
- TokenizerHelper.cs
- _OverlappedAsyncResult.cs
- TitleStyle.cs
- BlurBitmapEffect.cs
- CharStorage.cs
- TypeUtil.cs
- SortQuery.cs
- HeaderedItemsControl.cs
- InvokeBase.cs
- ContextBase.cs
- Point4DValueSerializer.cs
- FacetDescription.cs
- ProgressBar.cs
- WebScriptEnablingBehavior.cs
- ACE.cs
- ConversionValidationRule.cs
- GiveFeedbackEvent.cs
- MDIWindowDialog.cs
- DataGridPageChangedEventArgs.cs
- TextStore.cs
- Rect.cs
- ValueQuery.cs
- DbLambda.cs
- CurrentChangingEventArgs.cs
- IndexedGlyphRun.cs
- IOThreadTimer.cs
- Brush.cs
- TextViewDesigner.cs
- SectionVisual.cs
- XmlSchemaNotation.cs
- TextElementCollectionHelper.cs
- RepeaterItemCollection.cs
- ControlValuePropertyAttribute.cs
- AppDomainEvidenceFactory.cs
- ExeConfigurationFileMap.cs
- WindowsImpersonationContext.cs
- FixUpCollection.cs
- CachedResourceDictionaryExtension.cs
- Rect3DValueSerializer.cs
- StrokeFIndices.cs
- XmlKeywords.cs
- shaperfactoryquerycacheentry.cs
- FileUtil.cs
- AuthorizationSection.cs
- CLSCompliantAttribute.cs
- SerialPort.cs
- NetworkInformationPermission.cs
- SqlDataSourceCommandEventArgs.cs
- GroupBox.cs
- SQLMoney.cs
- DispatcherOperation.cs
- InspectionWorker.cs
- RequestCachingSection.cs
- FieldNameLookup.cs
- TextEditorLists.cs
- StrokeCollectionDefaultValueFactory.cs
- SystemDiagnosticsSection.cs
- ResourceAttributes.cs
- PolygonHotSpot.cs
- CallContext.cs
- TrayIconDesigner.cs
- HtmlTextArea.cs
- TraceListener.cs
- CLRBindingWorker.cs
- TableHeaderCell.cs
- QueryReaderSettings.cs
- RuntimeEnvironment.cs
- BrowserCapabilitiesCompiler.cs
- FrameworkPropertyMetadata.cs
- DataGridViewCellStyleConverter.cs
- AttachedPropertyBrowsableForChildrenAttribute.cs
- CustomAttributeFormatException.cs
- NotFiniteNumberException.cs
- _BasicClient.cs
- CustomValidator.cs
- InheritanceContextChangedEventManager.cs
- VisualStyleInformation.cs
- Literal.cs
- ListViewUpdateEventArgs.cs
- DeploymentExceptionMapper.cs
- IdentifierCreationService.cs
- DisplayMemberTemplateSelector.cs
- Label.cs
- DesignerMetadata.cs
- BaseContextMenu.cs
- KeyedHashAlgorithm.cs
- ISessionStateStore.cs
- HttpContext.cs
- ListViewUpdatedEventArgs.cs
- SqlUserDefinedTypeAttribute.cs
- ApplicationFileParser.cs