React to MVC/Auth changes

This commit is contained in:
Hao Kung 2015-01-15 23:52:52 -08:00
parent ad5cfb9e6e
commit ef22f9fb30
7 changed files with 34 additions and 5 deletions

View File

@ -88,7 +88,7 @@ namespace MusicStore.Apis
}
[HttpPost]
[Authorize("app-ManageStore", "Allowed")]
[Authorize("app-ManageStore")]
public async Task<ActionResult> CreateAlbum([FromBody]AlbumChangeDto album)
{
if (!ModelState.IsValid)
@ -112,7 +112,7 @@ namespace MusicStore.Apis
}
[HttpPut("{albumId:int}/update")]
[Authorize("app-ManageStore", "Allowed")]
[Authorize("app-ManageStore")]
public async Task<ActionResult> UpdateAlbum(int albumId, [FromBody]AlbumChangeDto album)
{
if (!ModelState.IsValid)
@ -145,7 +145,7 @@ namespace MusicStore.Apis
}
[HttpDelete("{albumId:int}")]
[Authorize("app-ManageStore", "Allowed")]
[Authorize("app-ManageStore")]
public async Task<ActionResult> DeleteAlbum(int albumId)
{
var album = await _storeContext.Albums.SingleOrDefaultAsync(a => a.AlbumId == albumId);

View File

@ -13,7 +13,7 @@ namespace MusicStore.Spa.Controllers
}
[HttpGet("admin")]
[Authorize("app-ManageStore", "Allowed")]
[Authorize("app-ManageStore")]
public IActionResult Admin()
{
return View("/Pages/Admin.cshtml");

View File

@ -7,6 +7,7 @@ using Microsoft.AspNet.Mvc;
using Microsoft.AspNet.Mvc.ModelBinding;
using Microsoft.AspNet.Mvc.Rendering;
using Microsoft.AspNet.Routing;
using Microsoft.AspNet.Security;
using Microsoft.AspNet.Security.Cookies;
using Microsoft.AspNet.StaticFiles;
using Microsoft.Data.Entity;
@ -61,6 +62,13 @@ namespace MusicStore.Spa
// Add application services to the service container
//services.AddTransient<IModelMetadataProvider, BuddyModelMetadataProvider>();
// Configure Auth
services.Configure<AuthorizationOptions>(options =>
{
options.AddPolicy("app-ManageStore", new AuthorizationPolicyBuilder().RequiresClaim("Allowed").Build());
});
}
public void Configure(IApplicationBuilder app)

View File

@ -14,7 +14,7 @@ using MusicStore.ViewModels;
namespace MusicStore.Areas.Admin.Controllers
{
[Area("Admin")]
[Microsoft.AspNet.Mvc.Authorize("ManageStore", "Allowed")]
[Microsoft.AspNet.Mvc.Authorize("ManageStore")]
public class StoreManagerController : Controller
{
private readonly MusicStoreContext _dbContext;

View File

@ -4,6 +4,7 @@ using Microsoft.AspNet.Diagnostics;
using Microsoft.AspNet.Diagnostics.Entity;
using Microsoft.AspNet.Identity;
using Microsoft.AspNet.Routing;
using Microsoft.AspNet.Security;
using Microsoft.Framework.Cache.Memory;
using Microsoft.Framework.ConfigurationModel;
using Microsoft.Framework.DependencyInjection;
@ -85,6 +86,12 @@ namespace MusicStore
//Add InMemoryCache
services.AddSingleton<IMemoryCache, MemoryCache>();
// Configure Auth
services.Configure<AuthorizationOptions>(options =>
{
options.AddPolicy("ManageStore", new AuthorizationPolicyBuilder().RequiresClaim("Allowed").Build());
});
}
//This method is invoked when ASPNET_ENV is 'Development' or is not defined

View File

@ -5,6 +5,7 @@ using Microsoft.AspNet.Builder;
using Microsoft.AspNet.Diagnostics;
using Microsoft.AspNet.Diagnostics.Entity;
using Microsoft.AspNet.Routing;
using Microsoft.AspNet.Security;
using Microsoft.AspNet.Server.WebListener;
using Microsoft.Framework.Cache.Memory;
using Microsoft.Framework.ConfigurationModel;
@ -88,6 +89,12 @@ namespace MusicStore
//Add InMemoryCache
services.AddSingleton<IMemoryCache, MemoryCache>();
// Configure Auth
services.Configure<AuthorizationOptions>(options =>
{
options.AddPolicy("ManageStore", new AuthorizationPolicyBuilder().RequiresClaim("Allowed").Build());
});
});
//Configure SignalR

View File

@ -4,6 +4,7 @@ using Microsoft.AspNet.Diagnostics;
using Microsoft.AspNet.Diagnostics.Entity;
using Microsoft.AspNet.Identity;
using Microsoft.AspNet.Routing;
using Microsoft.AspNet.Security;
using Microsoft.Framework.Cache.Memory;
using Microsoft.Framework.ConfigurationModel;
using Microsoft.Framework.DependencyInjection;
@ -73,6 +74,12 @@ namespace MusicStore
//Add InMemoryCache
services.AddSingleton<IMemoryCache, MemoryCache>();
// Configure Auth
services.Configure<AuthorizationOptions>(options =>
{
options.AddPolicy("ManageStore", new AuthorizationPolicyBuilder().RequiresClaim("Allowed").Build());
});
}
//This method is invoked when ASPNET_ENV is 'Development' or is not defined