Skip to content
This repository has been archived by the owner on May 29, 2019. It is now read-only.

Commit

Permalink
React to MVC/Auth changes
Browse files Browse the repository at this point in the history
  • Loading branch information
HaoK committed Jan 16, 2015
1 parent ad5cfb9 commit ef22f9f
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 5 deletions.
6 changes: 3 additions & 3 deletions src/MusicStore.Spa/Apis/AlbumsApiController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public async Task<ActionResult> Details(int albumId)
}

[HttpPost]
[Authorize("app-ManageStore", "Allowed")]
[Authorize("app-ManageStore")]
public async Task<ActionResult> CreateAlbum([FromBody]AlbumChangeDto album)
{
if (!ModelState.IsValid)
Expand All @@ -112,7 +112,7 @@ public async Task<ActionResult> CreateAlbum([FromBody]AlbumChangeDto album)
}

[HttpPut("{albumId:int}/update")]
[Authorize("app-ManageStore", "Allowed")]
[Authorize("app-ManageStore")]
public async Task<ActionResult> UpdateAlbum(int albumId, [FromBody]AlbumChangeDto album)
{
if (!ModelState.IsValid)
Expand Down Expand Up @@ -145,7 +145,7 @@ public async Task<ActionResult> UpdateAlbum(int albumId, [FromBody]AlbumChangeDt
}

[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);
Expand Down
2 changes: 1 addition & 1 deletion src/MusicStore.Spa/Controllers/PageController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public IActionResult Home()
}

[HttpGet("admin")]
[Authorize("app-ManageStore", "Allowed")]
[Authorize("app-ManageStore")]
public IActionResult Admin()
{
return View("/Pages/Admin.cshtml");
Expand Down
8 changes: 8 additions & 0 deletions src/MusicStore.Spa/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
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;
Expand Down Expand Up @@ -61,6 +62,13 @@ public void ConfigureServices(IServiceCollection services)

// 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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
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;
Expand Down
7 changes: 7 additions & 0 deletions src/MusicStore/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
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;
Expand Down Expand Up @@ -85,6 +86,12 @@ public void ConfigureServices(IServiceCollection services)

//Add InMemoryCache
services.AddSingleton<IMemoryCache, MemoryCache>();

// Configure Auth
services.Configure<AuthorizationOptions>(options =>

This comment has been minimized.

Copy link
@Praburaj

Praburaj Jan 16, 2015

Contributor

How do we conditionally add this only for the Admin user?

This comment has been minimized.

Copy link
@HaoK

HaoK Jan 16, 2015

Author Member

You add a RequireClaim(ClaimsType.Name, "Admin") to the policy

{
options.AddPolicy("ManageStore", new AuthorizationPolicyBuilder().RequiresClaim("Allowed").Build());

This comment has been minimized.

Copy link
@Praburaj

Praburaj Jan 16, 2015

Contributor

There is another Startup class SocialTesting in the test project

This comment has been minimized.

Copy link
@HaoK

HaoK Jan 16, 2015

Author Member

Doh, good catch

});
}

//This method is invoked when ASPNET_ENV is 'Development' or is not defined
Expand Down
7 changes: 7 additions & 0 deletions src/MusicStore/StartupNtlmAuthentication.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
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;
Expand Down Expand Up @@ -88,6 +89,12 @@ public void Configure(IApplicationBuilder app, ILoggerFactory loggerFactory)
//Add InMemoryCache
services.AddSingleton<IMemoryCache, MemoryCache>();
// Configure Auth
services.Configure<AuthorizationOptions>(options =>
{
options.AddPolicy("ManageStore", new AuthorizationPolicyBuilder().RequiresClaim("Allowed").Build());
});
});

//Configure SignalR
Expand Down
7 changes: 7 additions & 0 deletions src/MusicStore/StartupOpenIdConnect.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
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;
Expand Down Expand Up @@ -73,6 +74,12 @@ public void ConfigureServices(IServiceCollection services)

//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
Expand Down

0 comments on commit ef22f9f

Please sign in to comment.