Skip to content
This repository has been archived by the owner on Dec 14, 2018. It is now read-only.

Commit

Permalink
[Fixes #3979] AuthorizationContext conflicts with type in Microsoft.A…
Browse files Browse the repository at this point in the history
…spNet.Authorization
  • Loading branch information
javiercn committed Jan 26, 2016
1 parent f9ad93c commit 908106b
Show file tree
Hide file tree
Showing 25 changed files with 63 additions and 63 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@

namespace Microsoft.AspNetCore.Mvc.Filters
{
public class AuthorizationContext : FilterContext
public class AuthorizationFilterContext : FilterContext
{
public AuthorizationContext(
public AuthorizationFilterContext(
ActionContext actionContext,
IList<IFilterMetadata> filters)
: base(actionContext, filters)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ namespace Microsoft.AspNetCore.Mvc.Filters
{
public interface IAsyncAuthorizationFilter : IFilterMetadata
{
Task OnAuthorizationAsync(AuthorizationContext context);
Task OnAuthorizationAsync(AuthorizationFilterContext context);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ namespace Microsoft.AspNetCore.Mvc.Filters
{
public interface IAuthorizationFilter : IFilterMetadata
{
void OnAuthorization(AuthorizationContext context);
void OnAuthorization(AuthorizationFilterContext context);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public abstract class AuthorizationFilterAttribute :
{
public int Order { get; set; }

public virtual Task OnAuthorizationAsync(AuthorizationContext context)
public virtual Task OnAuthorizationAsync(AuthorizationFilterContext context)
{
if (context == null)
{
Expand All @@ -26,11 +26,11 @@ public virtual Task OnAuthorizationAsync(AuthorizationContext context)
return TaskCache.CompletedTask;
}

public virtual void OnAuthorization(AuthorizationContext context)
public virtual void OnAuthorization(AuthorizationFilterContext context)
{
}

protected virtual bool HasAllowAnonymous(AuthorizationContext context)
protected virtual bool HasAllowAnonymous(AuthorizationFilterContext context)
{
if (context == null)
{
Expand All @@ -40,7 +40,7 @@ protected virtual bool HasAllowAnonymous(AuthorizationContext context)
return context.Filters.Any(item => item is IAllowAnonymousFilter);
}

protected virtual void Fail(AuthorizationContext context)
protected virtual void Fail(AuthorizationFilterContext context)
{
if (context == null)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public AuthorizeFilter(AuthorizationPolicy policy)
public AuthorizationPolicy Policy { get; private set; }

/// <inheritdoc />
public virtual async Task OnAuthorizationAsync(Filters.AuthorizationContext context)
public virtual async Task OnAuthorizationAsync(Filters.AuthorizationFilterContext context)
{
if (context == null)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public abstract class FilterActionInvoker : IActionInvoker
private IFilterMetadata[] _filters;
private FilterCursor _cursor;

private AuthorizationContext _authorizationContext;
private AuthorizationFilterContext _authorizationContext;

private ResourceExecutingContext _resourceExecutingContext;
private ResourceExecutedContext _resourceExecutedContext;
Expand Down Expand Up @@ -186,7 +186,7 @@ private Task InvokeAllAuthorizationFiltersAsync()
{
_cursor.Reset();

_authorizationContext = new AuthorizationContext(Context, _filters);
_authorizationContext = new AuthorizationFilterContext(Context, _filters);
return InvokeAuthorizationFilterAsync();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public static void AfterAction(

public static void BeforeOnAuthorizationAsync(
this DiagnosticSource diagnosticSource,
AuthorizationContext authorizationContext,
AuthorizationFilterContext authorizationContext,
IAsyncAuthorizationFilter filter)
{
if (diagnosticSource.IsEnabled("Microsoft.AspNetCore.Mvc.BeforeOnAuthorization"))
Expand All @@ -60,7 +60,7 @@ public static void BeforeOnAuthorizationAsync(

public static void AfterOnAuthorizationAsync(
this DiagnosticSource diagnosticSource,
AuthorizationContext authorizationContext,
AuthorizationFilterContext authorizationContext,
IAsyncAuthorizationFilter filter)
{
if (diagnosticSource.IsEnabled("Microsoft.AspNetCore.Mvc.AfterOnAuthorization"))
Expand All @@ -78,7 +78,7 @@ public static void AfterOnAuthorizationAsync(

public static void BeforeOnAuthorization(
this DiagnosticSource diagnosticSource,
AuthorizationContext authorizationContext,
AuthorizationFilterContext authorizationContext,
IAuthorizationFilter filter)
{
if (diagnosticSource.IsEnabled("Microsoft.AspNetCore.Mvc.BeforeOnAuthorization"))
Expand All @@ -96,7 +96,7 @@ public static void BeforeOnAuthorization(

public static void AfterOnAuthorization(
this DiagnosticSource diagnosticSource,
AuthorizationContext authorizationContext,
AuthorizationFilterContext authorizationContext,
IAuthorizationFilter filter)
{
if (diagnosticSource.IsEnabled("Microsoft.AspNetCore.Mvc.AfterOnAuthorization"))
Expand Down
4 changes: 2 additions & 2 deletions src/Microsoft.AspNetCore.Mvc.Core/RequireHttpsAttribute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public class RequireHttpsAttribute : Attribute, IAuthorizationFilter, IOrderedFi
{
public int Order { get; set; }

public virtual void OnAuthorization(AuthorizationContext filterContext)
public virtual void OnAuthorization(AuthorizationFilterContext filterContext)
{
if (filterContext == null)
{
Expand All @@ -25,7 +25,7 @@ public virtual void OnAuthorization(AuthorizationContext filterContext)
}
}

protected virtual void HandleNonHttpsRequest(AuthorizationContext filterContext)
protected virtual void HandleNonHttpsRequest(AuthorizationFilterContext filterContext)
{
// only redirect for GET requests, otherwise the browser might not propagate the verb and request
// body correctly.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public int Order


/// <inheritdoc />
public async Task OnAuthorizationAsync(Filters.AuthorizationContext context)
public async Task OnAuthorizationAsync(Filters.AuthorizationFilterContext context)
{
if (context == null)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public int Order
}

/// <inheritdoc />
public Task OnAuthorizationAsync(AuthorizationContext context)
public Task OnAuthorizationAsync(AuthorizationFilterContext context)
{
if (context == null)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public AutoValidateAntiforgeryTokenAuthorizationFilter(IAntiforgery antiforgery,
{
}

protected override bool ShouldValidate(AuthorizationContext context)
protected override bool ShouldValidate(AuthorizationFilterContext context)
{
if (context == null)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public ValidateAntiforgeryTokenAuthorizationFilter(IAntiforgery antiforgery, ILo
_logger = loggerFactory.CreateLogger<ValidateAntiforgeryTokenAuthorizationFilter>();
}

public async Task OnAuthorizationAsync(AuthorizationContext context)
public async Task OnAuthorizationAsync(AuthorizationFilterContext context)
{
if (context == null)
{
Expand All @@ -48,7 +48,7 @@ public async Task OnAuthorizationAsync(AuthorizationContext context)
}
}

protected virtual bool ShouldValidate(AuthorizationContext context)
protected virtual bool ShouldValidate(AuthorizationFilterContext context)
{
if (context == null)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ public async Task Invoke_CanFilterToOnlyBearerScheme()
Assert.NotNull(authorizationContext.Result);
}

private Filters.AuthorizationContext GetAuthorizationContext(
private Filters.AuthorizationFilterContext GetAuthorizationContext(
Action<ServiceCollection> registerServices,
bool anonymous = false)
{
Expand Down Expand Up @@ -325,13 +325,13 @@ private Filters.AuthorizationContext GetAuthorizationContext(
auth.Setup(c => c.AuthenticateAsync("Basic")).ReturnsAsync(basicPrincipal);
auth.Setup(c => c.AuthenticateAsync("Fails")).ReturnsAsync(null);

// AuthorizationContext
// AuthorizationFilterContext
var actionContext = new ActionContext(
httpContext: httpContext.Object,
routeData: new RouteData(),
actionDescriptor: new ActionDescriptor());

var authorizationContext = new Filters.AuthorizationContext(
var authorizationContext = new Filters.AuthorizationFilterContext(
actionContext,
Enumerable.Empty<IFilterMetadata>().ToList()
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -254,15 +254,15 @@ public async Task InvokeAction_InvokesAuthorizationFilter()
{
// Arrange
var filter = new Mock<IAuthorizationFilter>(MockBehavior.Strict);
filter.Setup(f => f.OnAuthorization(It.IsAny<AuthorizationContext>())).Verifiable();
filter.Setup(f => f.OnAuthorization(It.IsAny<AuthorizationFilterContext>())).Verifiable();

var invoker = CreateInvoker(filter.Object);

// Act
await invoker.InvokeAsync();

// Assert
filter.Verify(f => f.OnAuthorization(It.IsAny<AuthorizationContext>()), Times.Once());
filter.Verify(f => f.OnAuthorization(It.IsAny<AuthorizationFilterContext>()), Times.Once());
}

[Fact]
Expand All @@ -271,8 +271,8 @@ public async Task InvokeAction_InvokesAsyncAuthorizationFilter()
// Arrange
var filter = new Mock<IAsyncAuthorizationFilter>(MockBehavior.Strict);
filter
.Setup(f => f.OnAuthorizationAsync(It.IsAny<AuthorizationContext>()))
.Returns<AuthorizationContext>(context => Task.FromResult(true))
.Setup(f => f.OnAuthorizationAsync(It.IsAny<AuthorizationFilterContext>()))
.Returns<AuthorizationFilterContext>(context => Task.FromResult(true))
.Verifiable();

var invoker = CreateInvoker(filter.Object);
Expand All @@ -282,7 +282,7 @@ public async Task InvokeAction_InvokesAsyncAuthorizationFilter()

// Assert
filter.Verify(
f => f.OnAuthorizationAsync(It.IsAny<AuthorizationContext>()),
f => f.OnAuthorizationAsync(It.IsAny<AuthorizationFilterContext>()),
Times.Once());
}

Expand All @@ -294,8 +294,8 @@ public async Task InvokeAction_InvokesAuthorizationFilter_ShortCircuit()

var filter1 = new Mock<IAuthorizationFilter>(MockBehavior.Strict);
filter1
.Setup(f => f.OnAuthorization(It.IsAny<AuthorizationContext>()))
.Callback<AuthorizationContext>(c => c.Result = challenge)
.Setup(f => f.OnAuthorization(It.IsAny<AuthorizationFilterContext>()))
.Callback<AuthorizationFilterContext>(c => c.Result = challenge)
.Verifiable();

var filter2 = new Mock<IAuthorizationFilter>(MockBehavior.Strict);
Expand All @@ -306,7 +306,7 @@ public async Task InvokeAction_InvokesAuthorizationFilter_ShortCircuit()
await invoker.InvokeAsync();

// Assert
filter1.Verify(f => f.OnAuthorization(It.IsAny<AuthorizationContext>()), Times.Once());
filter1.Verify(f => f.OnAuthorization(It.IsAny<AuthorizationFilterContext>()), Times.Once());
Assert.False(invoker.ControllerFactory.CreateCalled);
}

Expand All @@ -318,8 +318,8 @@ public async Task InvokeAction_InvokesAsyncAuthorizationFilter_ShortCircuit()

var filter1 = new Mock<IAsyncAuthorizationFilter>(MockBehavior.Strict);
filter1
.Setup(f => f.OnAuthorizationAsync(It.IsAny<AuthorizationContext>()))
.Returns<AuthorizationContext>((context) =>
.Setup(f => f.OnAuthorizationAsync(It.IsAny<AuthorizationFilterContext>()))
.Returns<AuthorizationFilterContext>((context) =>
{
context.Result = challenge;
return Task.FromResult(true);
Expand All @@ -335,7 +335,7 @@ public async Task InvokeAction_InvokesAsyncAuthorizationFilter_ShortCircuit()

// Assert
filter1.Verify(
f => f.OnAuthorizationAsync(It.IsAny<AuthorizationContext>()),
f => f.OnAuthorizationAsync(It.IsAny<AuthorizationFilterContext>()),
Times.Once());

Assert.False(invoker.ControllerFactory.CreateCalled);
Expand All @@ -359,8 +359,8 @@ public async Task InvokeAction_ExceptionInAuthorizationFilterCannotBeHandledByOt

var authorizationFilter1 = new Mock<IAuthorizationFilter>(MockBehavior.Strict);
authorizationFilter1
.Setup(f => f.OnAuthorization(It.IsAny<AuthorizationContext>()))
.Callback<AuthorizationContext>(c => { throw expected; })
.Setup(f => f.OnAuthorization(It.IsAny<AuthorizationFilterContext>()))
.Callback<AuthorizationFilterContext>(c => { throw expected; })
.Verifiable();

// None of these filters should run
Expand All @@ -385,7 +385,7 @@ public async Task InvokeAction_ExceptionInAuthorizationFilterCannotBeHandledByOt
// Assert
Assert.Same(expected, thrown);
exceptionFilter.Verify(f => f.OnException(It.IsAny<ExceptionContext>()), Times.Never());
authorizationFilter1.Verify(f => f.OnAuthorization(It.IsAny<AuthorizationContext>()), Times.Once());
authorizationFilter1.Verify(f => f.OnAuthorization(It.IsAny<AuthorizationFilterContext>()), Times.Once());
}

[Fact]
Expand All @@ -400,8 +400,8 @@ public async Task InvokeAction_InvokesAuthorizationFilter_ChallengeNotSeenByResu

var authorizationFilter = new Mock<IAuthorizationFilter>(MockBehavior.Strict);
authorizationFilter
.Setup(f => f.OnAuthorization(It.IsAny<AuthorizationContext>()))
.Callback<AuthorizationContext>(c => c.Result = challenge.Object)
.Setup(f => f.OnAuthorization(It.IsAny<AuthorizationFilterContext>()))
.Callback<AuthorizationFilterContext>(c => c.Result = challenge.Object)
.Verifiable();

var resultFilter = new Mock<IResultFilter>(MockBehavior.Strict);
Expand All @@ -412,7 +412,7 @@ public async Task InvokeAction_InvokesAuthorizationFilter_ChallengeNotSeenByResu
await invoker.InvokeAsync();

// Assert
authorizationFilter.Verify(f => f.OnAuthorization(It.IsAny<AuthorizationContext>()), Times.Once());
authorizationFilter.Verify(f => f.OnAuthorization(It.IsAny<AuthorizationFilterContext>()), Times.Once());
challenge.Verify(c => c.ExecuteResultAsync(It.IsAny<ActionContext>()), Times.Once());
}

Expand Down Expand Up @@ -1848,8 +1848,8 @@ public async Task InvokeAction_AuthorizationFilter_ChallengePreventsResourceFilt

var authorizationFilter = new Mock<IAuthorizationFilter>(MockBehavior.Strict);
authorizationFilter
.Setup(f => f.OnAuthorization(It.IsAny<AuthorizationContext>()))
.Callback<AuthorizationContext>((c) =>
.Setup(f => f.OnAuthorization(It.IsAny<AuthorizationFilterContext>()))
.Callback<AuthorizationFilterContext>((c) =>
{
c.Result = _result;
});
Expand Down Expand Up @@ -2283,7 +2283,7 @@ public MockAuthorizationFilter(int maxAllowedErrors)
_expectedMaxAllowedErrors = maxAllowedErrors;
}

public void OnAuthorization(AuthorizationContext context)
public void OnAuthorization(AuthorizationFilterContext context)
{
Assert.NotNull(context.ModelState.MaxAllowedErrors);
Assert.Equal(_expectedMaxAllowedErrors, context.ModelState.MaxAllowedErrors);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1191,7 +1191,7 @@ public void OnResultExecuting(ResultExecutingContext context)

private class UnsupportedFiltersController : IExceptionFilter, IAuthorizationFilter, IAsyncResourceFilter
{
public void OnAuthorization(AuthorizationContext context)
public void OnAuthorization(AuthorizationFilterContext context)
{
throw new NotImplementedException();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,16 +149,16 @@ public void HandleNonHttpsRequestExtensibility()

private class CustomRequireHttpsAttribute : RequireHttpsAttribute
{
protected override void HandleNonHttpsRequest(AuthorizationContext filterContext)
protected override void HandleNonHttpsRequest(AuthorizationFilterContext filterContext)
{
filterContext.Result = new HttpStatusCodeResult(StatusCodes.Status404NotFound);
}
}

private static AuthorizationContext CreateAuthorizationContext(HttpContext ctx)
private static AuthorizationFilterContext CreateAuthorizationContext(HttpContext ctx)
{
var actionContext = new ActionContext(ctx, new RouteData(), new ActionDescriptor());
return new AuthorizationContext(actionContext, new IFilterMetadata[0]);
return new AuthorizationFilterContext(actionContext, new IFilterMetadata[0]);
}
}
}
Loading

0 comments on commit 908106b

Please sign in to comment.