From 26aca2b99c46f3f1d724b769c58aac4a7ce555fc Mon Sep 17 00:00:00 2001 From: Eilon Lipton Date: Thu, 1 Oct 2015 18:00:38 -0700 Subject: [PATCH] Remove unneeded namespaces, use new startup APIs --- .../Controllers/StoreManagerController.cs | 3 ++- src/MusicStore/Startup.cs | 18 ++++++++---------- src/MusicStore/StartupNtlmAuthentication.cs | 17 ++++++++--------- src/MusicStore/StartupOpenIdConnect.cs | 14 +++++++------- .../Account/_ExternalLoginsListPartial.cshtml | 7 +++---- .../Views/Manage/ManageLogins.cshtml | 7 +++---- 6 files changed, 31 insertions(+), 35 deletions(-) diff --git a/src/MusicStore/Areas/Admin/Controllers/StoreManagerController.cs b/src/MusicStore/Areas/Admin/Controllers/StoreManagerController.cs index 12388f032b..05e2fda3ba 100644 --- a/src/MusicStore/Areas/Admin/Controllers/StoreManagerController.cs +++ b/src/MusicStore/Areas/Admin/Controllers/StoreManagerController.cs @@ -2,6 +2,7 @@ using System.Linq; using System.Threading; using System.Threading.Tasks; +using Microsoft.AspNet.Authorization; using Microsoft.AspNet.Cors.Core; using Microsoft.AspNet.Mvc; using Microsoft.AspNet.Mvc.Rendering; @@ -13,7 +14,7 @@ using MusicStore.ViewModels; namespace MusicStore.Areas.Admin.Controllers { [Area("Admin")] - [Microsoft.AspNet.Authorization.Authorize("ManageStore")] + [Authorize("ManageStore")] public class StoreManagerController : Controller { [FromServices] diff --git a/src/MusicStore/Startup.cs b/src/MusicStore/Startup.cs index fdd1433944..b65cabc54b 100644 --- a/src/MusicStore/Startup.cs +++ b/src/MusicStore/Startup.cs @@ -1,12 +1,8 @@ -using Microsoft.AspNet.Authorization; using Microsoft.AspNet.Builder; -using Microsoft.AspNet.Cors.Core; using Microsoft.AspNet.Diagnostics.Entity; -using Microsoft.AspNet.Http; using Microsoft.AspNet.Identity.EntityFramework; using Microsoft.Data.Entity; using Microsoft.Dnx.Runtime; -using Microsoft.Framework.Caching.Memory; using Microsoft.Framework.Configuration; using Microsoft.Framework.DependencyInjection; using Microsoft.Framework.Logging; @@ -63,13 +59,13 @@ namespace MusicStore // Add Identity services to the services container services.AddIdentity(options => { - options.Cookies.ApplicationCookie.AccessDeniedPath = new PathString("/Home/AccessDenied"); + options.Cookies.ApplicationCookie.AccessDeniedPath = "/Home/AccessDenied"; }) .AddEntityFrameworkStores() .AddDefaultTokenProviders(); - services.Configure(options => + services.AddCors(options => { options.AddPolicy("CorsPolicy", builder => { @@ -80,11 +76,10 @@ namespace MusicStore // Add MVC services to the services container services.AddMvc(); - //Add InMemoryCache - services.AddSingleton(); + // Add memory cache services + services.AddCaching(); // Add session related services. - services.AddCaching(); services.AddSession(); // Add the system clock service @@ -94,7 +89,10 @@ namespace MusicStore services.AddAuthorization(options => { options.AddPolicy( - "ManageStore", new AuthorizationPolicyBuilder().RequireClaim("ManageStore", "Allowed").Build()); + "ManageStore", + authBuilder => { + authBuilder.RequireClaim("ManageStore", "Allowed"); + }); }); } diff --git a/src/MusicStore/StartupNtlmAuthentication.cs b/src/MusicStore/StartupNtlmAuthentication.cs index 00ec32f5d3..8a464a8023 100644 --- a/src/MusicStore/StartupNtlmAuthentication.cs +++ b/src/MusicStore/StartupNtlmAuthentication.cs @@ -1,13 +1,10 @@ using System; using System.Security.Claims; -using Microsoft.AspNet.Authorization; using Microsoft.AspNet.Builder; -using Microsoft.AspNet.Cors.Core; using Microsoft.AspNet.Diagnostics.Entity; using Microsoft.AspNet.Http.Features; using Microsoft.Data.Entity; using Microsoft.Dnx.Runtime; -using Microsoft.Framework.Caching.Memory; using Microsoft.Framework.Configuration; using Microsoft.Framework.DependencyInjection; using Microsoft.Framework.Logging; @@ -61,7 +58,7 @@ namespace MusicStore .AddDbContext(options => options.UseSqlServer(Configuration["Data:DefaultConnection:ConnectionString"])); - services.Configure(options => + services.AddCors(options => { options.AddPolicy("CorsPolicy", builder => { @@ -72,21 +69,23 @@ namespace MusicStore // Add MVC services to the services container services.AddMvc(); - //Add InMemoryCache - services.AddSingleton(); + // Add memory cache services + services.AddCaching(); // Add session related services. - services.AddCaching(); services.AddSession(); // Add the system clock service services.AddSingleton(); // Configure Auth - services.Configure(options => + services.AddAuthorization(options => { options.AddPolicy( - "ManageStore", new AuthorizationPolicyBuilder().RequireClaim("ManageStore", "Allowed").Build()); + "ManageStore", + authBuilder => { + authBuilder.RequireClaim("ManageStore", "Allowed"); + }); }); } diff --git a/src/MusicStore/StartupOpenIdConnect.cs b/src/MusicStore/StartupOpenIdConnect.cs index d6414315c7..1bec946c46 100644 --- a/src/MusicStore/StartupOpenIdConnect.cs +++ b/src/MusicStore/StartupOpenIdConnect.cs @@ -1,10 +1,8 @@ -using Microsoft.AspNet.Authorization; using Microsoft.AspNet.Builder; using Microsoft.AspNet.Diagnostics.Entity; using Microsoft.AspNet.Identity.EntityFramework; using Microsoft.Data.Entity; using Microsoft.Dnx.Runtime; -using Microsoft.Framework.Caching.Memory; using Microsoft.Framework.Configuration; using Microsoft.Framework.DependencyInjection; using Microsoft.Framework.Logging; @@ -89,21 +87,23 @@ namespace MusicStore // Add MVC services to the services container services.AddMvc(); - //Add InMemoryCache - services.AddSingleton(); + // Add memory cache services + services.AddCaching(); // Add session related services. - services.AddCaching(); services.AddSession(); // Add the system clock service services.AddSingleton(); // Configure Auth - services.Configure(options => + services.AddAuthorization(options => { options.AddPolicy( - "ManageStore", new AuthorizationPolicyBuilder().RequireClaim("ManageStore", "Allowed").Build()); + "ManageStore", + authBuilder => { + authBuilder.RequireClaim("ManageStore", "Allowed"); + }); }); } diff --git a/src/MusicStore/Views/Account/_ExternalLoginsListPartial.cshtml b/src/MusicStore/Views/Account/_ExternalLoginsListPartial.cshtml index b2f5d220ce..fa2dd99da1 100644 --- a/src/MusicStore/Views/Account/_ExternalLoginsListPartial.cshtml +++ b/src/MusicStore/Views/Account/_ExternalLoginsListPartial.cshtml @@ -1,11 +1,10 @@ -@using Microsoft.AspNet.Http.Authentication; -@model ExternalLoginListViewModel +@model ExternalLoginListViewModel @inject SignInManager SignInManager

Use another service to log in.


@{ var loginProviders = SignInManager.GetExternalAuthenticationSchemes(); - if (loginProviders.Count() == 0) + if (!loginProviders.Any()) {

@@ -19,7 +18,7 @@

- @foreach (AuthenticationDescription p in loginProviders) + @foreach (var p in loginProviders) { } diff --git a/src/MusicStore/Views/Manage/ManageLogins.cshtml b/src/MusicStore/Views/Manage/ManageLogins.cshtml index 5155eb76ec..28e03baedf 100644 --- a/src/MusicStore/Views/Manage/ManageLogins.cshtml +++ b/src/MusicStore/Views/Manage/ManageLogins.cshtml @@ -1,5 +1,4 @@ -@using Microsoft.AspNet.Http.Authentication; -@model ManageLoginsViewModel +@model ManageLoginsViewModel @{ ViewBag.Title = "Manage your external logins"; } @@ -37,14 +36,14 @@ } -@if (Model.OtherLogins.Count > 0) +@if (Model.OtherLogins.Any()) {

Add another service to log in.


- @foreach (AuthenticationDescription p in Model.OtherLogins) + @foreach (var p in Model.OtherLogins) { }