Code:
/ WCF / WCF / 3.5.30729.1 / untmp / Orcas / SP / ndp / cdf / src / WCF / ServiceModel / System / ServiceModel / MessageSecurityOverMsmq.cs / 1 / MessageSecurityOverMsmq.cs
//------------------------------------------------------------ // Copyright (c) Microsoft Corporation. All rights reserved. //----------------------------------------------------------- namespace System.ServiceModel { using System.Net.Security; using System.ServiceModel.Channels; using System.ServiceModel.Security; using System.ServiceModel.Security.Tokens; using System.Runtime.CompilerServices; public sealed class MessageSecurityOverMsmq { internal const MessageCredentialType DefaultClientCredentialType = MessageCredentialType.Windows; MessageCredentialType clientCredentialType; SecurityAlgorithmSuite algorithmSuite; bool wasAlgorithmSuiteSet; internal MessageSecurityOverMsmq() { clientCredentialType = DefaultClientCredentialType; algorithmSuite = SecurityAlgorithmSuite.Default; } public MessageCredentialType ClientCredentialType { get { return this.clientCredentialType; } set { if (!MessageCredentialTypeHelper.IsDefined(value)) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException("value")); } this.clientCredentialType = value; } } public SecurityAlgorithmSuite AlgorithmSuite { get { return this.algorithmSuite; } set { if (value == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("value"); } this.algorithmSuite = value; wasAlgorithmSuiteSet = true; } } internal bool WasAlgorithmSuiteSet { get { return this.wasAlgorithmSuiteSet; } } [MethodImpl(MethodImplOptions.NoInlining)] internal SecurityBindingElement CreateSecurityBindingElement() { SymmetricSecurityBindingElement result; bool isKerberosSelected = false; switch (this.clientCredentialType) { case MessageCredentialType.None: result = SecurityBindingElement.CreateAnonymousForCertificateBindingElement(); break; case MessageCredentialType.UserName: result = SecurityBindingElement.CreateUserNameForCertificateBindingElement(); break; case MessageCredentialType.Certificate: result = (SymmetricSecurityBindingElement)SecurityBindingElement.CreateMutualCertificateBindingElement(); break; case MessageCredentialType.Windows: result = SecurityBindingElement.CreateKerberosBindingElement(); isKerberosSelected = true; break; case MessageCredentialType.IssuedToken: result = SecurityBindingElement.CreateIssuedTokenForCertificateBindingElement(IssuedSecurityTokenParameters.CreateInfoCardParameters(new SecurityStandardsManager(), this.algorithmSuite)); break; default: DiagnosticUtility.DebugAssert("unknown ClientCredentialType"); throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new NotSupportedException()); } result.MessageSecurityVersion = MessageSecurityVersion.WSSecurity11WSTrustFebruary2005WSSecureConversationFebruary2005WSSecurityPolicy11; // set the algorithm suite and issued token params if required if (wasAlgorithmSuiteSet || !isKerberosSelected) { result.DefaultAlgorithmSuite = this.AlgorithmSuite; } else if (isKerberosSelected) { result.DefaultAlgorithmSuite = SecurityAlgorithmSuite.KerberosDefault; } result.IncludeTimestamp = false; result.LocalServiceSettings.DetectReplays = false; result.LocalClientSettings.DetectReplays = false; return result; } internal static bool TryCreate(SecurityBindingElement sbe, out MessageSecurityOverMsmq messageSecurity) { messageSecurity = null; if (sbe == null) return false; SymmetricSecurityBindingElement ssbe = sbe as SymmetricSecurityBindingElement; if (ssbe == null) return false; if (sbe.MessageSecurityVersion != MessageSecurityVersion.WSSecurity11WSTrustFebruary2005WSSecureConversationFebruary2005WSSecurityPolicy11BasicSecurityProfile10 && sbe.MessageSecurityVersion != MessageSecurityVersion.WSSecurity11WSTrustFebruary2005WSSecureConversationFebruary2005WSSecurityPolicy11) { return false; } // do not check local settings: sbe.LocalServiceSettings and sbe.LocalClientSettings if (ssbe.IncludeTimestamp) return false; bool isKerberosSelected = false; MessageCredentialType clientCredentialType; IssuedSecurityTokenParameters issuedParameters; if (SecurityBindingElement.IsAnonymousForCertificateBinding(sbe)) { clientCredentialType = MessageCredentialType.None; } else if (SecurityBindingElement.IsUserNameForCertificateBinding(sbe)) { clientCredentialType = MessageCredentialType.UserName; } else if (SecurityBindingElement.IsMutualCertificateBinding(sbe)) { clientCredentialType = MessageCredentialType.Certificate; } else if (SecurityBindingElement.IsKerberosBinding(sbe)) { clientCredentialType = MessageCredentialType.Windows; isKerberosSelected = true; } else if (SecurityBindingElement.IsIssuedTokenForCertificateBinding(sbe, out issuedParameters)) { if (!IssuedSecurityTokenParameters.IsInfoCardParameters(issuedParameters)) return false; clientCredentialType = MessageCredentialType.IssuedToken; } else { return false; } messageSecurity = new MessageSecurityOverMsmq(); messageSecurity.ClientCredentialType = clientCredentialType; // set the algorithm suite and issued token params if required if (clientCredentialType != MessageCredentialType.IssuedToken && !isKerberosSelected) { messageSecurity.AlgorithmSuite = ssbe.DefaultAlgorithmSuite; } return true; } } } // 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
- PersistChildrenAttribute.cs
- XmlChildEnumerator.cs
- Mouse.cs
- DataViewSettingCollection.cs
- TextDecorations.cs
- CodeSnippetStatement.cs
- Activity.cs
- WindowsClaimSet.cs
- InternalsVisibleToAttribute.cs
- MouseGestureValueSerializer.cs
- PageContent.cs
- TypeDelegator.cs
- ServiceInstanceProvider.cs
- SafeFileMapViewHandle.cs
- WebPartMenuStyle.cs
- MemberProjectionIndex.cs
- RecognizerStateChangedEventArgs.cs
- DecoratedNameAttribute.cs
- Stroke.cs
- ObjectToken.cs
- DesignerTransactionCloseEvent.cs
- RunInstallerAttribute.cs
- PathFigure.cs
- LogWriteRestartAreaState.cs
- NativeMethods.cs
- EntityStoreSchemaFilterEntry.cs
- XmlSortKeyAccumulator.cs
- GiveFeedbackEventArgs.cs
- VisualStyleElement.cs
- EdmProviderManifest.cs
- Polygon.cs
- DesignerFrame.cs
- EntityContainerAssociationSetEnd.cs
- ListDictionaryInternal.cs
- BindingGroup.cs
- SBCSCodePageEncoding.cs
- OrderByExpression.cs
- CompensatableTransactionScopeActivityDesigner.cs
- AttachedAnnotationChangedEventArgs.cs
- LinqDataSourceView.cs
- EasingKeyFrames.cs
- BridgeDataRecord.cs
- EditCommandColumn.cs
- LinqDataSourceHelper.cs
- EditingCommands.cs
- MatrixTransform3D.cs
- UnauthorizedAccessException.cs
- EqualityComparer.cs
- XmlQueryTypeFactory.cs
- SerializableAuthorizationContext.cs
- RubberbandSelector.cs
- ScopedKnownTypes.cs
- SecurityCriticalDataForSet.cs
- ProtectedConfigurationSection.cs
- SoapMessage.cs
- FigureParagraph.cs
- FixedFlowMap.cs
- HttpModuleActionCollection.cs
- StringUtil.cs
- processwaithandle.cs
- ContainerSelectorGlyph.cs
- Pair.cs
- TextBreakpoint.cs
- ArrayListCollectionBase.cs
- ParsedAttributeCollection.cs
- NumericExpr.cs
- RepeatBehaviorConverter.cs
- ForeignKeyConstraint.cs
- CodeGotoStatement.cs
- DispatcherBuilder.cs
- ContentValidator.cs
- ConfigurationValue.cs
- HtmlDocument.cs
- XmlSerializerVersionAttribute.cs
- PartialTrustVisibleAssembly.cs
- Thumb.cs
- FixedMaxHeap.cs
- Substitution.cs
- FrameworkName.cs
- Set.cs
- KeyPullup.cs
- AuthenticationService.cs
- ListBox.cs
- WmlLiteralTextAdapter.cs
- TabControl.cs
- CreateUserErrorEventArgs.cs
- BuildManagerHost.cs
- HtmlAnchor.cs
- HttpProtocolReflector.cs
- WebPartConnection.cs
- PolyLineSegment.cs
- HwndAppCommandInputProvider.cs
- CompoundFileDeflateTransform.cs
- RegistrySecurity.cs
- DescendantBaseQuery.cs
- URIFormatException.cs
- ProfessionalColors.cs
- ValidatorUtils.cs
- CharKeyFrameCollection.cs
- TableLayoutPanelResizeGlyph.cs