Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Clean up the sample case #60

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Policy below will only match using the BasicRequestTransformer
# Policy below will only match if using the BasicRequestTransformer
p, [email protected], BasicTest, Get

# Policy below will only match if using the KeyMatchRequestTransformer
Expand Down
4 changes: 0 additions & 4 deletions samples/WebApplicationSample/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,6 @@ public void ConfigureServices(IServiceCollection services)
options.PreferSubClaimType = ClaimTypes.Name;
options.DefaultModelPath = Path.Combine("CasbinConfigs", "basic_model.conf");
options.DefaultPolicyPath = Path.Combine("CasbinConfigs", "basic_policy.csv");

// Comment line below to use the default BasicRequestTransformer
// Note: Commenting the line means that the action methods MUST have [CasbinAuthorize()] attribute which explicitly specifies obj and policy. Otherwise authorization will be denied
options.DefaultRequestTransformerType = typeof(KeyMatchRequestTransformer);
});
}

Expand Down
4 changes: 2 additions & 2 deletions samples/WebApplicationSample/Views/Home/Index.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@

<div class="text-center">
<h1 class="display-4">Welcome</h1>
<p>Basic Model : Policy is "p, [email protected], BasicTest, GET" - <a asp-controller="Home" asp-action="BasicTest">Basic Test</a>.</p>
<p>Attrib Route : Policy is "p, [email protected], /Attribute, GET" - <a asp-controller="Home" asp-action="AttributeTest">Attribute Test</a>.</p>
<p>Basic Transformer: Policy is "p, [email protected], BasicTest, Get" - <a asp-controller="Home" asp-action="BasicTest">Basic Test</a>.</p>
<p>KeyMatch Transformer: Policy is "p, [email protected], /Attribute, GET" - <a asp-controller="Home" asp-action="AttributeTest">Attribute Test</a>.</p>
</div>
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
# Policy below will only match using both BasicRequestTransformer and CustomRequestTransformer
# Policy below will only match if using the BasicRequestTransformer
p, [email protected], BasicTest, Get

# Policy below will only match if using the CustomRequestTransformer
p, [email protected], /attribtest, GET

# Policy below will only match if using the CustomRequestTransformer
#p, [email protected], /home/privacy, GET
# Policy below will only match if using the KeyMatchRequestTransformer
p, [email protected], /AttributeTest, GET
Original file line number Diff line number Diff line change
Expand Up @@ -22,20 +22,19 @@ public IActionResult Index()
return View();
}

[HttpGet("attribtest")]
[CasbinAuthorize("/attribtest", "GET")]
public IActionResult AttribRouteTest(string tenantId)
[HttpGet("AttributeTest")]
[CasbinAuthorize(RequestTransformerType = typeof(KeyMatchRequestTransformer))]
public IActionResult AttributeTest(string tenantId)
{
return View();
}

[CasbinAuthorize(nameof(BasicTest), nameof(HttpMethod.Get))]
[CasbinAuthorize(nameof(BasicTest), nameof(HttpMethod.Get), RequestTransformerType = typeof(BasicRequestTransformer))]
public IActionResult BasicTest()
{
return View();
}

[CasbinAuthorize]
public IActionResult Privacy()
{
return View();
Expand Down
3 changes: 0 additions & 3 deletions samples/WebApplicationWithEfcoreSample/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,8 @@ public void ConfigureServices(IServiceCollection services)
{
options.PreferSubClaimType = ClaimTypes.Name;
options.DefaultModelPath = Path.Combine("CasbinConfigs", "basic_model.conf");
//options.DefaultPolicyPath = Path.Combine("CasbinConfigs", "basic_policy.csv");

options.DefaultEnforcerFactory = (p, m) =>
new Enforcer(m, new EFCoreAdapter<string>(p.GetRequiredService<CasbinDbContext<string>>()));
options.DefaultRequestTransformerType = typeof(BasicRequestTransformer);
});
services.AddDefaultIdentity<IdentityUser>(options =>
{
Expand Down

This file was deleted.

Empty file.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@

<div class="text-center">
<h1 class="display-4">Welcome</h1>
<p>Basic Model : Policy is "p, [email protected], BasicTest, GET" - <a asp-controller="Home" asp-action="BasicTest">Test</a>.</p>
<p>Attrib Route : Policy is "p, [email protected], /attribtest, GET" - <a asp-controller="Home" asp-action="AttribRouteTest">Attribute Route Test</a>.</p>
<p>Basic Transformer: Policy is "p, [email protected], BasicTest, Get" - <a asp-controller="Home" asp-action="BasicTest">Basic Test</a>.</p>
<p>KeyMatch Transformer: Policy is "p, [email protected], /Attribute, GET" - <a asp-controller="Home" asp-action="AttributeTest">Attribute Test</a>.</p>
</div>