Skip to content

Commit 54195b0

Browse files
committed
Add secure tag helper to samples.
1 parent c3f11bd commit 54195b0

File tree

6 files changed

+83
-13
lines changed

6 files changed

+83
-13
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
using DynamicAuthorization.Mvc.Core;
2+
using DynamicAuthorization.Mvc.Core.Models;
3+
using Microsoft.AspNetCore.Razor.TagHelpers;
4+
using SampleMvc2WebApp.Data;
5+
6+
namespace SampleMvc2WebApp
7+
{
8+
[HtmlTargetElement("secure-content")]
9+
public class MySecureContentTagHelper : SecureContentTagHelper<ApplicationDbContext>
10+
{
11+
public MySecureContentTagHelper(
12+
ApplicationDbContext dbContext,
13+
DynamicAuthorizationOptions authorizationOptions,
14+
IRoleAccessStore roleAccessStore
15+
)
16+
: base(dbContext, authorizationOptions, roleAccessStore)
17+
{
18+
}
19+
}
20+
}

samples/netcore2.2/SampleMvc2WebApp/Views/Shared/_Layout.cshtml

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -41,19 +41,33 @@
4141
Access
4242
</a>
4343
<div class="dropdown-menu" aria-labelledby="navbarDropdownMenuLink">
44-
<a class="dropdown-item text-dark" asp-area="Access" asp-controller="Role" asp-action="Index">Role List</a>
45-
<a class="dropdown-item text-dark" asp-area="Access" asp-controller="UserRole" asp-action="Index">User Role List</a>
44+
<secure-content asp-area="Access" asp-controller="Role" asp-action="Index">
45+
<a class="dropdown-item text-dark" asp-area="Access" asp-controller="Role" asp-action="Index">Role List</a>
46+
</secure-content>
47+
<secure-content asp-area="Access" asp-controller="UserRole" asp-action="Index">
48+
<a class="dropdown-item text-dark" asp-area="Access" asp-controller="UserRole" asp-action="Index">User Role List</a>
49+
</secure-content>
4650
</div>
4751
</li>
4852
<li class="nav-item dropdown">
4953
<a class="nav-link dropdown-toggle" href="#" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
5054
Protected Links
5155
</a>
5256
<div class="dropdown-menu" aria-labelledby="navbarDropdownMenuLink">
53-
<a class="dropdown-item text-dark" asp-area="" asp-controller="ProtectedOne" asp-action="Index">Protected 1</a>
54-
<a class="dropdown-item text-dark" asp-area="" asp-controller="ProtectedOne" asp-action="Detail">Protected Detail 1</a>
55-
<a class="dropdown-item text-dark" asp-area="" asp-controller="ProtectedTwo" asp-action="Index">Protected 2</a>
56-
<a class="dropdown-item text-dark" asp-area="" asp-controller="ProtectedTwo" asp-action="Detail">Protected Detail 2</a>
57+
<secure-content asp-area="" asp-controller="ProtectedOne" asp-action="Index">
58+
<a class="dropdown-item text-dark" asp-area="" asp-controller="ProtectedOne" asp-action="Index">Protected 1</a>
59+
</secure-content>
60+
<secure-content asp-area="" asp-controller="ProtectedOne" asp-action="Detail">
61+
<a class="dropdown-item text-dark" asp-area="" asp-controller="ProtectedOne" asp-action="Detail">Protected Detail 1</a>
62+
</secure-content>
63+
<secure-content asp-area="" asp-controller="ProtectedTwo" asp-action="Index">
64+
<a class="dropdown-item text-dark" asp-area="" asp-controller="ProtectedTwo" asp-action="Index">
65+
Protected 2
66+
</a>
67+
</secure-content>
68+
<secure-content asp-area="" asp-controller="ProtectedTwo" asp-action="Detail">
69+
<a class="dropdown-item text-dark" asp-area="" asp-controller="ProtectedTwo" asp-action="Detail">Protected Detail 2</a>
70+
</secure-content>
5771
</div>
5872
</li>
5973
</ul>
@@ -98,4 +112,4 @@
98112

99113
@RenderSection("Scripts", required: false)
100114
</body>
101-
</html>
115+
</html>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
@using SampleMvc2WebApp
22
@using SampleMvc2WebApp.Models
33
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
4+
@addTagHelper *, SampleMvc2WebApp
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
using DynamicAuthorization.Mvc.Core;
2+
using DynamicAuthorization.Mvc.Core.Models;
3+
using Microsoft.AspNetCore.Razor.TagHelpers;
4+
using SampleMvcWebApp.Data;
5+
6+
namespace SampleMvcWebApp
7+
{
8+
[HtmlTargetElement("secure-content")]
9+
public class MySecureContentTagHelper : SecureContentTagHelper<ApplicationDbContext>
10+
{
11+
public MySecureContentTagHelper(
12+
ApplicationDbContext dbContext,
13+
DynamicAuthorizationOptions authorizationOptions,
14+
IRoleAccessStore roleAccessStore
15+
)
16+
: base(dbContext, authorizationOptions, roleAccessStore)
17+
{
18+
}
19+
}
20+
}

samples/netcore3.x/SampleMvcWebApp/Views/Shared/_Layout.cshtml

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,19 +28,33 @@
2828
Access
2929
</a>
3030
<div class="dropdown-menu" aria-labelledby="navbarDropdownMenuLink">
31-
<a class="dropdown-item text-dark" asp-area="Access" asp-controller="Role" asp-action="Index">Role List</a>
32-
<a class="dropdown-item text-dark" asp-area="Access" asp-controller="UserRole" asp-action="Index">User Role List</a>
31+
<secure-content asp-area="Access" asp-controller="Role" asp-action="Index">
32+
<a class="dropdown-item text-dark" asp-area="Access" asp-controller="Role" asp-action="Index">Role List</a>
33+
</secure-content>
34+
<secure-content asp-area="Access" asp-controller="UserRole" asp-action="Index">
35+
<a class="dropdown-item text-dark" asp-area="Access" asp-controller="UserRole" asp-action="Index">User Role List</a>
36+
</secure-content>
3337
</div>
3438
</li>
3539
<li class="nav-item dropdown">
3640
<a class="nav-link dropdown-toggle" href="#" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
3741
Protected Links
3842
</a>
3943
<div class="dropdown-menu" aria-labelledby="navbarDropdownMenuLink">
40-
<a class="dropdown-item text-dark" asp-area="" asp-controller="ProtectedOne" asp-action="Index">Protected 1</a>
41-
<a class="dropdown-item text-dark" asp-area="" asp-controller="ProtectedOne" asp-action="Detail">Protected Detail 1</a>
42-
<a class="dropdown-item text-dark" asp-area="" asp-controller="ProtectedTwo" asp-action="Index">Protected 2</a>
43-
<a class="dropdown-item text-dark" asp-area="" asp-controller="ProtectedTwo" asp-action="Detail">Protected Detail 2</a>
44+
<secure-content asp-area="" asp-controller="ProtectedOne" asp-action="Index">
45+
<a class="dropdown-item text-dark" asp-area="" asp-controller="ProtectedOne" asp-action="Index">Protected 1</a>
46+
</secure-content>
47+
<secure-content asp-area="" asp-controller="ProtectedOne" asp-action="Detail">
48+
<a class="dropdown-item text-dark" asp-area="" asp-controller="ProtectedOne" asp-action="Detail">Protected Detail 1</a>
49+
</secure-content>
50+
<secure-content asp-area="" asp-controller="ProtectedTwo" asp-action="Index">
51+
<a class="dropdown-item text-dark" asp-area="" asp-controller="ProtectedTwo" asp-action="Index">
52+
Protected 2
53+
</a>
54+
</secure-content>
55+
<secure-content asp-area="" asp-controller="ProtectedTwo" asp-action="Detail">
56+
<a class="dropdown-item text-dark" asp-area="" asp-controller="ProtectedTwo" asp-action="Detail">Protected Detail 2</a>
57+
</secure-content>
4458
</div>
4559
</li>
4660
</ul>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
@using SampleMvcWebApp
22
@using SampleMvcWebApp.Models
33
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
4+
@addTagHelper *, SampleMvcWebApp

0 commit comments

Comments
 (0)