From fd17481a73662ba225398fc39224e0d3df64e22b Mon Sep 17 00:00:00 2001 From: Hao Kung Date: Wed, 14 Oct 2015 17:04:31 -0700 Subject: [PATCH] React to AuthZ changes --- src/Microsoft.AspNet.Mvc.Core/Filters/AuthorizeFilter.cs | 6 +++--- .../WebSites/FiltersWebSite/BasicAuthenticationHandler.cs | 6 +++--- test/WebSites/FiltersWebSite/Startup.cs | 8 ++++---- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/Microsoft.AspNet.Mvc.Core/Filters/AuthorizeFilter.cs b/src/Microsoft.AspNet.Mvc.Core/Filters/AuthorizeFilter.cs index 95da8565ef..85540e341a 100644 --- a/src/Microsoft.AspNet.Mvc.Core/Filters/AuthorizeFilter.cs +++ b/src/Microsoft.AspNet.Mvc.Core/Filters/AuthorizeFilter.cs @@ -44,10 +44,10 @@ namespace Microsoft.AspNet.Mvc.Filters } // Build a ClaimsPrincipal with the Policy's required authentication types - if (Policy.ActiveAuthenticationSchemes != null && Policy.ActiveAuthenticationSchemes.Any()) + if (Policy.AuthenticationSchemes != null && Policy.AuthenticationSchemes.Any()) { ClaimsPrincipal newPrincipal = null; - foreach (var scheme in Policy.ActiveAuthenticationSchemes) + foreach (var scheme in Policy.AuthenticationSchemes) { var result = await context.HttpContext.Authentication.AuthenticateAsync(scheme); if (result != null) @@ -77,7 +77,7 @@ namespace Microsoft.AspNet.Mvc.Filters !httpContext.User.Identities.Any(i => i.IsAuthenticated) || !await authService.AuthorizeAsync(httpContext.User, context, Policy)) { - context.Result = new ChallengeResult(Policy.ActiveAuthenticationSchemes.ToArray()); + context.Result = new ChallengeResult(Policy.AuthenticationSchemes.ToArray()); } } } diff --git a/test/WebSites/FiltersWebSite/BasicAuthenticationHandler.cs b/test/WebSites/FiltersWebSite/BasicAuthenticationHandler.cs index 3ef05090e2..29815d5307 100644 --- a/test/WebSites/FiltersWebSite/BasicAuthenticationHandler.cs +++ b/test/WebSites/FiltersWebSite/BasicAuthenticationHandler.cs @@ -13,7 +13,7 @@ namespace FiltersWebSite { public class BasicAuthenticationHandler : AuthenticationHandler { - protected override Task HandleAuthenticateAsync() + protected override Task HandleAuthenticateAsync() { var principal = new ClaimsPrincipal(); principal.AddIdentity(new ClaimsIdentity( @@ -24,8 +24,8 @@ namespace FiltersWebSite new Claim(ClaimTypes.NameIdentifier, "John") }, Options.AuthenticationScheme)); - return Task.FromResult(new AuthenticationTicket(principal, - new AuthenticationProperties(), Options.AuthenticationScheme)); + return Task.FromResult(AuthenticateResult.Success(new AuthenticationTicket(principal, + new AuthenticationProperties(), Options.AuthenticationScheme))); } } } \ No newline at end of file diff --git a/test/WebSites/FiltersWebSite/Startup.cs b/test/WebSites/FiltersWebSite/Startup.cs index 8ac03d1343..9941df83db 100644 --- a/test/WebSites/FiltersWebSite/Startup.cs +++ b/test/WebSites/FiltersWebSite/Startup.cs @@ -20,22 +20,22 @@ namespace FiltersWebSite // This policy cannot succeed since the claim is never added options.AddPolicy("Impossible", policy => { - policy.ActiveAuthenticationSchemes.Add("Interactive"); + policy.AuthenticationSchemes.Add("Interactive"); policy.RequireClaim("Never"); }); options.AddPolicy("Api", policy => { - policy.ActiveAuthenticationSchemes.Add("Api"); + policy.AuthenticationSchemes.Add("Api"); policy.RequireClaim(ClaimTypes.NameIdentifier); }); options.AddPolicy("Api-Manager", policy => { - policy.ActiveAuthenticationSchemes.Add("Api"); + policy.AuthenticationSchemes.Add("Api"); policy.Requirements.Add(Operations.Edit); }); options.AddPolicy("Interactive", policy => { - policy.ActiveAuthenticationSchemes.Add("Interactive"); + policy.AuthenticationSchemes.Add("Interactive"); policy.RequireClaim(ClaimTypes.NameIdentifier) .RequireClaim("Permission", "CanViewPage"); });