public AuthFilterWrapper(IAsyncAuthorizationFilter filter) { Filter = filter; if (filter is AuthorizeFilter af) { _authorizedRoleNames = new List <string>(); _others = new List <IAuthorizationRequirement>(af.Policy.Requirements.Count); foreach (var r in af.Policy.Requirements) { var ra = r as RolesAuthorizationRequirement; if (r is RolesAuthorizationRequirement rar) { if (_authorizedRoleNames.Count > 0) { throw new NotSupportedException("Expected Policy.Requirements to contain only a single RolesAuthorizationRequirement within the collection."); } _authorizedRoleNames.AddRange(rar.AllowedRoles); } else { _others.Add(r); } } } }
public AuthoriseFilterTests() { _authenticationScheme = "scheme"; _policy = new AuthorizationPolicy(new [] { Substitute.For <IAuthorizationRequirement>() }, new [] { _authenticationScheme }); _filter = new AuthoriseFilter(_policy); _actionContext = new ActionContext { HttpContext = new DefaultHttpContext(), RouteData = new RouteData(), ActionDescriptor = new ActionDescriptor() }; }
public static void BeforeOnAuthorizationAsync( this DiagnosticListener diagnosticListener, AuthorizationFilterContext authorizationContext, IAsyncAuthorizationFilter filter) { Debug.Assert(diagnosticListener != null); Debug.Assert(authorizationContext != null); Debug.Assert(filter != null); // Inlinable fast-path check if diagnostic listener is enabled if (diagnosticListener.IsEnabled()) { BeforeOnAuthorizationAsyncImpl(diagnosticListener, authorizationContext, filter); } }
public static void AfterOnAuthorizationAsync( this DiagnosticSource diagnosticSource, AuthorizationFilterContext authorizationContext, IAsyncAuthorizationFilter filter) { if (diagnosticSource.IsEnabled("Microsoft.AspNetCore.Mvc.AfterOnAuthorization")) { diagnosticSource.Write( "Microsoft.AspNetCore.Mvc.AfterOnAuthorization", new { actionDescriptor = authorizationContext.ActionDescriptor, authorizationContext = authorizationContext, filter = filter }); } }
public static void AfterOnAuthorizationAsync( this DiagnosticSource diagnosticSource, AuthorizationFilterContext authorizationContext, IAsyncAuthorizationFilter filter) { if (diagnosticSource.IsEnabled("Microsoft.AspNetCore.Mvc.AfterOnAuthorization")) { diagnosticSource.Write( "Microsoft.AspNetCore.Mvc.AfterOnAuthorization", new { actionDescriptor = authorizationContext.ActionDescriptor, authorizationContext = authorizationContext, filter = filter }); } }
public static void BeforeOnAuthorizationAsync( this DiagnosticSource diagnosticSource, AuthorizationFilterContext authorizationContext, IAsyncAuthorizationFilter filter) { Debug.Assert(diagnosticSource != null); Debug.Assert(authorizationContext != null); Debug.Assert(filter != null); if (diagnosticSource.IsEnabled("Microsoft.AspNetCore.Mvc.BeforeOnAuthorization")) { diagnosticSource.Write( "Microsoft.AspNetCore.Mvc.BeforeOnAuthorization", new { actionDescriptor = authorizationContext.ActionDescriptor, authorizationContext = authorizationContext, filter = filter }); } }
private static void BeforeOnAuthorizationAsyncImpl(DiagnosticListener diagnosticListener, AuthorizationFilterContext authorizationContext, IAsyncAuthorizationFilter filter) { if (diagnosticListener.IsEnabled(Diagnostics.BeforeAuthorizationFilterOnAuthorizationEventData.EventName)) { diagnosticListener.Write( Diagnostics.BeforeAuthorizationFilterOnAuthorizationEventData.EventName, new BeforeAuthorizationFilterOnAuthorizationEventData( authorizationContext.ActionDescriptor, authorizationContext, filter )); } }
public PerRequestFilter(IAsyncAuthorizationFilter filter) { Filter = filter; }
public static void BeforeOnAuthorizationAsync( this DiagnosticSource diagnosticSource, AuthorizationFilterContext authorizationContext, IAsyncAuthorizationFilter filter) { Debug.Assert(diagnosticSource != null); Debug.Assert(authorizationContext != null); Debug.Assert(filter != null); if (diagnosticSource.IsEnabled("Microsoft.AspNetCore.Mvc.BeforeOnAuthorization")) { diagnosticSource.Write( "Microsoft.AspNetCore.Mvc.BeforeOnAuthorization", new { actionDescriptor = authorizationContext.ActionDescriptor, authorizationContext = authorizationContext, filter = filter }); } }
private static void BeforeOnAuthorizationAsyncImpl(DiagnosticListener diagnosticListener, AuthorizationFilterContext authorizationContext, IAsyncAuthorizationFilter filter) { if (diagnosticListener.IsEnabled("Microsoft.AspNetCore.Mvc.BeforeOnAuthorization")) { diagnosticListener.Write( "Microsoft.AspNetCore.Mvc.BeforeOnAuthorization", new { actionDescriptor = authorizationContext.ActionDescriptor, authorizationContext = authorizationContext, filter = filter }); } }