Code:
/ WCF / WCF / 3.5.30729.1 / untmp / Orcas / SP / ndp / cdf / src / WCF / ServiceModel / System / ServiceModel / Dispatcher / AuthorizationBehavior.cs / 1 / AuthorizationBehavior.cs
//------------------------------------------------------------------------------ // Copyright (c) Microsoft Corporation. All rights reserved. //----------------------------------------------------------------------------- namespace System.ServiceModel.Dispatcher { using System.Diagnostics; using System.Collections.Generic; using System.ServiceModel.Channels; using System.ServiceModel; using System.ServiceModel.Description; using System.Collections.ObjectModel; using System.Globalization; using System.ServiceModel.Diagnostics; using System.ServiceModel.Security; using System.ServiceModel.Security.Tokens; using System.IdentityModel.Claims; using System.IdentityModel.Policy; using System.Security.Principal; using System.Runtime.CompilerServices; sealed class AuthorizationBehavior { static ServiceAuthorizationManager DefaultServiceAuthorizationManager = new ServiceAuthorizationManager(); ReadOnlyCollectionexternalAuthorizationPolicies; ServiceAuthorizationManager serviceAuthorizationManager; AuditLogLocation auditLogLocation; bool suppressAuditFailure; AuditLevel serviceAuthorizationAuditLevel; AuthorizationBehavior() { } public void Authorize(ref MessageRpc rpc) { SecurityMessageProperty security = SecurityMessageProperty.GetOrCreate(rpc.Request); security.ExternalAuthorizationPolicies = this.externalAuthorizationPolicies; ServiceAuthorizationManager serviceAuthorizationManager = this.serviceAuthorizationManager ?? DefaultServiceAuthorizationManager; try { if (!serviceAuthorizationManager.CheckAccess(rpc.OperationContext, ref rpc.Request)) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(CreateAccessDeniedFaultException()); } } catch (Exception ex) { if (DiagnosticUtility.IsFatal(ex)) { throw; } if (PerformanceCounters.PerformanceCountersEnabled) { PerformanceCounters.AuthorizationFailed(rpc.Operation.Name); } if (AuditLevel.Failure == (this.serviceAuthorizationAuditLevel & AuditLevel.Failure)) { try { string primaryIdentity; string authContextId = null; AuthorizationContext authContext = security.ServiceSecurityContext.AuthorizationContext; if (authContext != null) { primaryIdentity = SecurityUtils.GetIdentityNamesFromContext(authContext); authContextId = authContext.Id; } else { primaryIdentity = SecurityUtils.AnonymousIdentity.Name; authContextId = " "; } SecurityAuditHelper.WriteServiceAuthorizationFailureEvent(this.auditLogLocation, this.suppressAuditFailure, rpc.Request, rpc.Request.Headers.To, rpc.Request.Headers.Action, primaryIdentity, authContextId, serviceAuthorizationManager == DefaultServiceAuthorizationManager ? " " : serviceAuthorizationManager.GetType().Name, ex); } #pragma warning suppress 56500 catch (Exception auditException) { if (DiagnosticUtility.IsFatal(auditException)) throw; DiagnosticUtility.ExceptionUtility.TraceHandledException(auditException, TraceEventType.Error); } } throw; } if (AuditLevel.Success == (this.serviceAuthorizationAuditLevel & AuditLevel.Success)) { string primaryIdentity; string authContextId; AuthorizationContext authContext = security.ServiceSecurityContext.AuthorizationContext; if (authContext != null) { primaryIdentity = SecurityUtils.GetIdentityNamesFromContext(authContext); authContextId = authContext.Id; } else { primaryIdentity = SecurityUtils.AnonymousIdentity.Name; authContextId = " "; } SecurityAuditHelper.WriteServiceAuthorizationSuccessEvent(this.auditLogLocation, this.suppressAuditFailure, rpc.Request, rpc.Request.Headers.To, rpc.Request.Headers.Action, primaryIdentity, authContextId, serviceAuthorizationManager == DefaultServiceAuthorizationManager ? " " : serviceAuthorizationManager.GetType().Name); } } [MethodImpl(MethodImplOptions.NoInlining)] static AuthorizationBehavior CreateAuthorizationBehavior(DispatchRuntime dispatch) { AuthorizationBehavior behavior = new AuthorizationBehavior(); behavior.externalAuthorizationPolicies = dispatch.ExternalAuthorizationPolicies; behavior.serviceAuthorizationManager = dispatch.ServiceAuthorizationManager; behavior.auditLogLocation = dispatch.SecurityAuditLogLocation; behavior.suppressAuditFailure = dispatch.SuppressAuditFailure; behavior.serviceAuthorizationAuditLevel = dispatch.ServiceAuthorizationAuditLevel; return behavior; } public static AuthorizationBehavior TryCreate(DispatchRuntime dispatch) { if (dispatch == null) throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentNullException("dispatch")); if (!dispatch.RequiresAuthorization) return null; return CreateAuthorizationBehavior(dispatch); } internal static Exception CreateAccessDeniedFaultException() { // always use default version? SecurityVersion wss = SecurityVersion.Default; FaultCode faultCode = FaultCode.CreateSenderFaultCode(wss.FailedAuthenticationFaultCode.Value, wss.HeaderNamespace.Value); FaultReason faultReason = new FaultReason(SR.GetString(SR.AccessDenied), CultureInfo.CurrentCulture); return new FaultException(faultReason, faultCode); } } } // 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
- OracleBinary.cs
- InvokePattern.cs
- ToolStripDropDownItem.cs
- precedingsibling.cs
- SizeF.cs
- ApplicationServiceManager.cs
- RSAPKCS1KeyExchangeDeformatter.cs
- TextRangeProviderWrapper.cs
- MasterPage.cs
- SchemaImporter.cs
- PopupEventArgs.cs
- DataControlPagerLinkButton.cs
- IsolatedStoragePermission.cs
- FixedSOMTable.cs
- _ListenerRequestStream.cs
- GeometryGroup.cs
- Baml2006Reader.cs
- ReadOnlyMetadataCollection.cs
- FeatureSupport.cs
- AccessDataSourceView.cs
- LayoutEngine.cs
- TagNameToTypeMapper.cs
- AxisAngleRotation3D.cs
- EntitySetDataBindingList.cs
- cookieexception.cs
- MetadataCache.cs
- ClipboardProcessor.cs
- RichTextBox.cs
- ColumnReorderedEventArgs.cs
- ISCIIEncoding.cs
- FieldNameLookup.cs
- Group.cs
- CurrencyManager.cs
- CodeGroup.cs
- SQLMembershipProvider.cs
- IIS7WorkerRequest.cs
- GridViewPageEventArgs.cs
- PackagePart.cs
- WebBrowserSiteBase.cs
- DateTimeParse.cs
- ConfigXmlCDataSection.cs
- SubqueryTrackingVisitor.cs
- CustomAttributeFormatException.cs
- While.cs
- ToolStripSeparator.cs
- Parser.cs
- RowToFieldTransformer.cs
- PersonalizationEntry.cs
- GlyphRun.cs
- DataGridViewSelectedRowCollection.cs
- ViewManager.cs
- BufferedReadStream.cs
- ZipIOBlockManager.cs
- ObjectSpanRewriter.cs
- ResourceDisplayNameAttribute.cs
- DefaultParameterValueAttribute.cs
- MatrixKeyFrameCollection.cs
- PtsContext.cs
- GeometryModel3D.cs
- StylesEditorDialog.cs
- MsmqHostedTransportConfiguration.cs
- CurrentChangedEventManager.cs
- IDReferencePropertyAttribute.cs
- NamespaceExpr.cs
- StreamInfo.cs
- WebControlAdapter.cs
- PrtTicket_Public.cs
- SimpleBitVector32.cs
- GrammarBuilderDictation.cs
- BasicExpandProvider.cs
- SettingsProperty.cs
- InnerItemCollectionView.cs
- JumpTask.cs
- StreamGeometry.cs
- PenThreadWorker.cs
- ResourceLoader.cs
- DriveInfo.cs
- DataGridViewCellCancelEventArgs.cs
- SpotLight.cs
- XhtmlBasicPanelAdapter.cs
- ThreadAttributes.cs
- JapaneseCalendar.cs
- IdlingCommunicationPool.cs
- WebPartCloseVerb.cs
- TableLayoutColumnStyleCollection.cs
- SingleObjectCollection.cs
- Accessors.cs
- RefreshResponseInfo.cs
- SettingsProviderCollection.cs
- FontFaceLayoutInfo.cs
- JournalEntry.cs
- httpstaticobjectscollection.cs
- Compiler.cs
- WebPartAuthorizationEventArgs.cs
- CompressEmulationStream.cs
- HttpCookie.cs
- StringAnimationBase.cs
- CustomCategoryAttribute.cs
- MetadataItem.cs
- FontNameConverter.cs