Code:
/ WCF / WCF / 3.5.30729.1 / untmp / Orcas / SP / ndp / cdf / src / WCF / ServiceModel / System / ServiceModel / Security / SecurityVersion.cs / 1 / SecurityVersion.cs
//------------------------------------------------------------ // Copyright (c) Microsoft Corporation. All rights reserved. //----------------------------------------------------------- namespace System.ServiceModel.Security { using System.Collections.Generic; using System.ServiceModel.Channels; using System.ServiceModel; using System.ServiceModel.Description; using System.IO; using System.IdentityModel.Claims; using System.IdentityModel.Policy; using System.ServiceModel.Security.Tokens; using System.Threading; using System.Globalization; using System.ServiceModel.Diagnostics; using System.Xml; using ISignatureValueSecurityElement = System.IdentityModel.ISignatureValueSecurityElement; public abstract class SecurityVersion { readonly XmlDictionaryString headerName; readonly XmlDictionaryString headerNamespace; readonly XmlDictionaryString headerPrefix; internal SecurityVersion(XmlDictionaryString headerName, XmlDictionaryString headerNamespace, XmlDictionaryString headerPrefix) { this.headerName = headerName; this.headerNamespace = headerNamespace; this.headerPrefix = headerPrefix; } internal XmlDictionaryString HeaderName { get { return this.headerName; } } internal XmlDictionaryString HeaderNamespace { get { return this.headerNamespace; } } internal XmlDictionaryString HeaderPrefix { get { return this.headerPrefix; } } internal abstract XmlDictionaryString FailedAuthenticationFaultCode { get; } internal abstract XmlDictionaryString InvalidSecurityTokenFaultCode { get; } internal abstract XmlDictionaryString InvalidSecurityFaultCode { get; } internal virtual bool SupportsSignatureConfirmation { get { return false; } } public static SecurityVersion WSSecurity10 { get { return SecurityVersion10.Instance; } } public static SecurityVersion WSSecurity11 { get { return SecurityVersion11.Instance; } } internal static SecurityVersion Default { get { return WSSecurity11; } } internal abstract ReceiveSecurityHeader CreateReceiveSecurityHeader(Message message, string actor, bool mustUnderstand, bool relay, SecurityStandardsManager standardsManager, SecurityAlgorithmSuite algorithmSuite, MessageDirection direction, int headerIndex); internal abstract SendSecurityHeader CreateSendSecurityHeader(Message message, string actor, bool mustUnderstand, bool relay, SecurityStandardsManager standardsManager, SecurityAlgorithmSuite algorithmSuite, MessageDirection direction); internal bool DoesMessageContainSecurityHeader(Message message) { return message.Headers.FindHeader(this.HeaderName.Value, this.HeaderNamespace.Value) >= 0; } internal int FindIndexOfSecurityHeader(Message message, string[] actors) { return message.Headers.FindHeader(this.HeaderName.Value, this.HeaderNamespace.Value, actors); } internal virtual bool IsReaderAtSignatureConfirmation(XmlDictionaryReader reader) { return false; } internal virtual ISignatureValueSecurityElement ReadSignatureConfirmation(XmlDictionaryReader reader) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException( SR.GetString(SR.SignatureConfirmationNotSupported))); } // The security always look for Empty soap role. If not found, we will also look for Ultimate actors (next incl). // In the future, till we support intermediary scenario, we should refactor this api to do not take actor parameter. internal ReceiveSecurityHeader TryCreateReceiveSecurityHeader(Message message, string actor, SecurityStandardsManager standardsManager, SecurityAlgorithmSuite algorithmSuite, MessageDirection direction) { int headerIndex = message.Headers.FindHeader(this.HeaderName.Value, this.HeaderNamespace.Value, actor); if (headerIndex < 0 && String.IsNullOrEmpty(actor)) { headerIndex = message.Headers.FindHeader(this.HeaderName.Value, this.HeaderNamespace.Value, message.Version.Envelope.UltimateDestinationActorValues); } if (headerIndex < 0) { return null; } MessageHeaderInfo headerInfo = message.Headers[headerIndex]; return CreateReceiveSecurityHeader(message, headerInfo.Actor, headerInfo.MustUnderstand, headerInfo.Relay, standardsManager, algorithmSuite, direction, headerIndex); } internal virtual void WriteSignatureConfirmation(XmlDictionaryWriter writer, string id, byte[] signatureConfirmation) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException( SR.GetString(SR.SignatureConfirmationNotSupported))); } internal void WriteStartHeader(XmlDictionaryWriter writer) { writer.WriteStartElement(this.HeaderPrefix.Value, this.HeaderName, this.HeaderNamespace); } class SecurityVersion10 : SecurityVersion { static readonly SecurityVersion10 instance = new SecurityVersion10(); protected SecurityVersion10() : base(XD.SecurityJan2004Dictionary.Security, XD.SecurityJan2004Dictionary.Namespace, XD.SecurityJan2004Dictionary.Prefix) { } public static SecurityVersion10 Instance { get { return instance; } } internal override XmlDictionaryString FailedAuthenticationFaultCode { get { return XD.SecurityJan2004Dictionary.FailedAuthenticationFaultCode; } } internal override XmlDictionaryString InvalidSecurityTokenFaultCode { get { return XD.SecurityJan2004Dictionary.InvalidSecurityTokenFaultCode; } } internal override XmlDictionaryString InvalidSecurityFaultCode { get { return XD.SecurityJan2004Dictionary.InvalidSecurityFaultCode; } } internal override SendSecurityHeader CreateSendSecurityHeader(Message message, string actor, bool mustUnderstand, bool relay, SecurityStandardsManager standardsManager, SecurityAlgorithmSuite algorithmSuite, MessageDirection direction) { return new WSSecurityOneDotZeroSendSecurityHeader(message, actor, mustUnderstand, relay, standardsManager, algorithmSuite, direction); } internal override ReceiveSecurityHeader CreateReceiveSecurityHeader(Message message, string actor, bool mustUnderstand, bool relay, SecurityStandardsManager standardsManager, SecurityAlgorithmSuite algorithmSuite, MessageDirection direction, int headerIndex) { return new WSSecurityOneDotZeroReceiveSecurityHeader( message, actor, mustUnderstand, relay, standardsManager, algorithmSuite, headerIndex, direction); } public override string ToString() { return "WSSecurity10"; } } sealed class SecurityVersion11 : SecurityVersion10 { static readonly SecurityVersion11 instance = new SecurityVersion11(); SecurityVersion11() : base() { } public new static SecurityVersion11 Instance { get { return instance; } } internal override bool SupportsSignatureConfirmation { get { return true; } } internal override ReceiveSecurityHeader CreateReceiveSecurityHeader(Message message, string actor, bool mustUnderstand, bool relay, SecurityStandardsManager standardsManager, SecurityAlgorithmSuite algorithmSuite, MessageDirection direction, int headerIndex) { return new WSSecurityOneDotOneReceiveSecurityHeader( message, actor, mustUnderstand, relay, standardsManager, algorithmSuite, headerIndex, direction); } internal override SendSecurityHeader CreateSendSecurityHeader(Message message, string actor, bool mustUnderstand, bool relay, SecurityStandardsManager standardsManager, SecurityAlgorithmSuite algorithmSuite, MessageDirection direction) { return new WSSecurityOneDotOneSendSecurityHeader(message, actor, mustUnderstand, relay, standardsManager, algorithmSuite, direction); } internal override bool IsReaderAtSignatureConfirmation(XmlDictionaryReader reader) { return reader.IsStartElement(XD.SecurityXXX2005Dictionary.SignatureConfirmation, XD.SecurityXXX2005Dictionary.Namespace); } internal override ISignatureValueSecurityElement ReadSignatureConfirmation(XmlDictionaryReader reader) { reader.MoveToStartElement(XD.SecurityXXX2005Dictionary.SignatureConfirmation, XD.SecurityXXX2005Dictionary.Namespace); bool isEmptyElement = reader.IsEmptyElement; string id = XmlHelper.GetRequiredNonEmptyAttribute(reader, XD.UtilityDictionary.IdAttribute, XD.UtilityDictionary.Namespace); byte[] signatureValue = XmlHelper.GetRequiredBase64Attribute(reader, XD.SecurityXXX2005Dictionary.ValueAttribute, null); reader.ReadStartElement(); if (!isEmptyElement) { reader.ReadEndElement(); } return new SignatureConfirmationElement(id, signatureValue, this); } internal override void WriteSignatureConfirmation(XmlDictionaryWriter writer, string id, byte[] signature) { if (id == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("id"); } if (signature == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("signature"); } writer.WriteStartElement(XD.SecurityXXX2005Dictionary.Prefix.Value, XD.SecurityXXX2005Dictionary.SignatureConfirmation, XD.SecurityXXX2005Dictionary.Namespace); writer.WriteAttributeString(XD.UtilityDictionary.Prefix.Value, XD.UtilityDictionary.IdAttribute, XD.UtilityDictionary.Namespace, id); writer.WriteStartAttribute(XD.SecurityXXX2005Dictionary.ValueAttribute, null); writer.WriteBase64(signature, 0, signature.Length); writer.WriteEndAttribute(); writer.WriteEndElement(); } public override string ToString() { return "WSSecurity11"; } } } } // 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
- DeadCharTextComposition.cs
- CmsInterop.cs
- PriorityRange.cs
- DataRowChangeEvent.cs
- TextView.cs
- FacetValueContainer.cs
- ComplexPropertyEntry.cs
- ProcessModule.cs
- XmlSignatureManifest.cs
- SqlDataSourceFilteringEventArgs.cs
- FieldBuilder.cs
- RtfToXamlLexer.cs
- Symbol.cs
- StringKeyFrameCollection.cs
- XmlWellformedWriter.cs
- BaseCollection.cs
- Function.cs
- DataTemplateSelector.cs
- SecurityHelper.cs
- PermissionRequestEvidence.cs
- PropertySourceInfo.cs
- DbException.cs
- QualifiedCellIdBoolean.cs
- UrlAuthFailedErrorFormatter.cs
- FontCollection.cs
- DataServiceQueryProvider.cs
- StaticFileHandler.cs
- FontUnitConverter.cs
- HtmlEncodedRawTextWriter.cs
- DataContractSerializer.cs
- ZipIOLocalFileDataDescriptor.cs
- SmtpMail.cs
- Soap12FormatExtensions.cs
- FormsIdentity.cs
- ContentHostHelper.cs
- DataSourceBooleanViewSchemaConverter.cs
- ExeContext.cs
- ToolStripPanelRenderEventArgs.cs
- BitStack.cs
- ParserContext.cs
- CodeCatchClauseCollection.cs
- XmlSchemaSimpleType.cs
- MetadataItemCollectionFactory.cs
- XmlTextReader.cs
- RotateTransform3D.cs
- ConfigurationLockCollection.cs
- IndentedWriter.cs
- DbQueryCommandTree.cs
- SettingsProperty.cs
- XmlReader.cs
- CapabilitiesSection.cs
- ToolTipService.cs
- LeaseManager.cs
- RecognitionResult.cs
- _AcceptOverlappedAsyncResult.cs
- UnsafeNativeMethods.cs
- ExtractedStateEntry.cs
- ComAwareEventInfo.cs
- TaskFormBase.cs
- HtmlElement.cs
- SqlServer2KCompatibilityAnnotation.cs
- DiagnosticStrings.cs
- CssClassPropertyAttribute.cs
- UrlParameterWriter.cs
- Point3D.cs
- SymbolMethod.cs
- CodeCommentStatement.cs
- VolatileResourceManager.cs
- SmtpFailedRecipientsException.cs
- UserPreferenceChangingEventArgs.cs
- DrawToolTipEventArgs.cs
- RadioButtonAutomationPeer.cs
- SqlGatherConsumedAliases.cs
- EncryptedKeyIdentifierClause.cs
- InputReferenceExpression.cs
- DSASignatureDeformatter.cs
- CodeComment.cs
- MessageContractMemberAttribute.cs
- ObjectTypeMapping.cs
- ResourcesBuildProvider.cs
- SetterBaseCollection.cs
- ValidationUtility.cs
- AttributeEmitter.cs
- RadioButton.cs
- DataGridViewRowCancelEventArgs.cs
- FlowLayoutPanelDesigner.cs
- GridEntryCollection.cs
- SimpleLine.cs
- UndirectedGraph.cs
- ConnectionsZoneAutoFormat.cs
- ColorContext.cs
- DrawingContextFlattener.cs
- SimpleType.cs
- XmlCharCheckingReader.cs
- HorizontalAlignConverter.cs
- InOutArgument.cs
- UpdatePanelTriggerCollection.cs
- CustomErrorsSectionWrapper.cs
- CommandConverter.cs
- CommonObjectSecurity.cs