-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add sample for migrating efcore adapter.
- Loading branch information
1 parent
e73d261
commit c047b35
Showing
71 changed files
with
40,589 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Binary file not shown.
Binary file not shown.
3 changes: 3 additions & 0 deletions
3
samples/WebApplicationWithEfcoreSample/Areas/Identity/Pages/_ViewStart.cshtml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
@{ | ||
Layout = "/Views/Shared/_Layout.cshtml"; | ||
} |
11 changes: 11 additions & 0 deletions
11
samples/WebApplicationWithEfcoreSample/CasbinConfigs/basic_model.conf
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
[request_definition] | ||
r = sub, obj, act | ||
|
||
[policy_definition] | ||
p = sub, obj, act | ||
|
||
[policy_effect] | ||
e = some(where (p.eft == allow)) | ||
|
||
[matchers] | ||
m = r.sub == p.sub && r.obj == p.obj && r.act == p.act |
8 changes: 8 additions & 0 deletions
8
samples/WebApplicationWithEfcoreSample/CasbinConfigs/basic_policy.csv
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# Policy below will only match using both BasicRequestTransformer and CustomRequestTransformer | ||
p, alice@example.com, BasicTest, Get | ||
|
||
# Policy below will only match if using the CustomRequestTransformer | ||
p, alice@example.com, /attribtest, GET | ||
|
||
# Policy below will only match if using the CustomRequestTransformer | ||
#p, alice@example.com, /home/privacy, GET |
21 changes: 21 additions & 0 deletions
21
samples/WebApplicationWithEfcoreSample/Controllers/ApiController.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
using Casbin.AspNetCore.Authorization; | ||
using Microsoft.AspNetCore.Mvc; | ||
|
||
namespace WebApplicationSample.Controllers | ||
{ | ||
[ApiController] | ||
[Route("/api")] | ||
public class ApiController : Controller | ||
{ | ||
|
||
[HttpGet("index")] | ||
[CasbinAuthorize] | ||
public IActionResult Index() | ||
{ | ||
return new JsonResult(new | ||
{ | ||
Message = "You passed the casbin authorize." | ||
}); | ||
} | ||
} | ||
} |
50 changes: 50 additions & 0 deletions
50
samples/WebApplicationWithEfcoreSample/Controllers/HomeController.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
using System.Diagnostics; | ||
using Casbin.AspNetCore.Authorization; | ||
using Casbin.AspNetCore.Authorization.Transformers; | ||
using Microsoft.AspNetCore.Mvc; | ||
using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http; | ||
using Microsoft.Extensions.Logging; | ||
using WebApplicationSample.Models; | ||
|
||
namespace WebApplicationSample.Controllers | ||
{ | ||
public class HomeController : Controller | ||
{ | ||
private readonly ILogger<HomeController> _logger; | ||
|
||
public HomeController(ILogger<HomeController> logger) | ||
{ | ||
_logger = logger; | ||
} | ||
|
||
public IActionResult Index() | ||
{ | ||
return View(); | ||
} | ||
|
||
[HttpGet("attribtest")] | ||
[CasbinAuthorize("/attribtest", "GET")] | ||
public IActionResult AttribRouteTest(string tenantId) | ||
{ | ||
return View(); | ||
} | ||
|
||
[CasbinAuthorize(nameof(BasicTest), nameof(HttpMethod.Get))] | ||
public IActionResult BasicTest() | ||
{ | ||
return View(); | ||
} | ||
|
||
[CasbinAuthorize] | ||
public IActionResult Privacy() | ||
{ | ||
return View(); | ||
} | ||
|
||
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)] | ||
public IActionResult Error() | ||
{ | ||
return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier }); | ||
} | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
samples/WebApplicationWithEfcoreSample/Data/ApplicationDbContext.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
using Microsoft.AspNetCore.Identity.EntityFrameworkCore; | ||
using Microsoft.EntityFrameworkCore; | ||
|
||
namespace WebApplicationSample.Data | ||
{ | ||
public class ApplicationDbContext : IdentityDbContext | ||
{ | ||
public ApplicationDbContext(DbContextOptions<ApplicationDbContext> options) | ||
: base(options) | ||
{ | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
#See https://aka.ms/containerfastmode to understand how Visual Studio uses this Dockerfile to build your images for faster debugging. | ||
|
||
FROM mcr.microsoft.com/dotnet/core/aspnet:3.1-buster-slim AS base | ||
WORKDIR /app | ||
EXPOSE 80 | ||
EXPOSE 443 | ||
|
||
FROM mcr.microsoft.com/dotnet/core/sdk:3.1-buster AS build | ||
WORKDIR /src | ||
COPY ["samples/WebApplicationSample/WebApplicationSample.csproj", "samples/WebApplicationSample/"] | ||
RUN dotnet restore "samples/WebApplicationSample/WebApplicationSample.csproj" | ||
COPY . . | ||
WORKDIR "/src/samples/WebApplicationSample" | ||
RUN dotnet build "WebApplicationSample.csproj" -c Release -o /app/build | ||
|
||
FROM build AS publish | ||
RUN dotnet publish "WebApplicationSample.csproj" -c Release -o /app/publish | ||
|
||
FROM base AS final | ||
WORKDIR /app | ||
COPY --from=publish /app/publish . | ||
ENTRYPOINT ["dotnet", "WebApplicationSample.dll"] |
Oops, something went wrong.