Skip to content

Commit d891fc7

Browse files
committed
Fix merge conflict
2 parents 52b36cb + 477e324 commit d891fc7

File tree

13 files changed

+409
-19
lines changed

13 files changed

+409
-19
lines changed

DynamicRoleBasedAuthorization.sln

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,9 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SampleMvcWebAppWithUi", "sa
2929
EndProject
3030
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "net5", "net5", "{85C709D5-793A-4068-9937-4749BCF34267}"
3131
EndProject
32-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SampleMvcWebWithUi", "samples\net5\SampleMvcWebWithUi\SampleMvcWebWithUi.csproj", "{8CEDCB64-13BF-4AD1-B7F4-01A8BB42AB07}"
32+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SampleMvcWebWithUi", "samples\net5\SampleMvcWebWithUi\SampleMvcWebWithUi.csproj", "{8CEDCB64-13BF-4AD1-B7F4-01A8BB42AB07}"
33+
EndProject
34+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DynamicAuthorization.Mvc.MsSqlServerStore", "src\DynamicAuthorization.Mvc.MsSqlServerStore\DynamicAuthorization.Mvc.MsSqlServerStore.csproj", "{2CAEFC83-24BF-4C92-B6F1-B3C6714220F2}"
3335
EndProject
3436
Global
3537
GlobalSection(SolutionConfigurationPlatforms) = preSolution
@@ -69,6 +71,10 @@ Global
6971
{8CEDCB64-13BF-4AD1-B7F4-01A8BB42AB07}.Debug|Any CPU.Build.0 = Debug|Any CPU
7072
{8CEDCB64-13BF-4AD1-B7F4-01A8BB42AB07}.Release|Any CPU.ActiveCfg = Release|Any CPU
7173
{8CEDCB64-13BF-4AD1-B7F4-01A8BB42AB07}.Release|Any CPU.Build.0 = Release|Any CPU
74+
{2CAEFC83-24BF-4C92-B6F1-B3C6714220F2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
75+
{2CAEFC83-24BF-4C92-B6F1-B3C6714220F2}.Debug|Any CPU.Build.0 = Debug|Any CPU
76+
{2CAEFC83-24BF-4C92-B6F1-B3C6714220F2}.Release|Any CPU.ActiveCfg = Release|Any CPU
77+
{2CAEFC83-24BF-4C92-B6F1-B3C6714220F2}.Release|Any CPU.Build.0 = Release|Any CPU
7278
EndGlobalSection
7379
GlobalSection(SolutionProperties) = preSolution
7480
HideSolutionNode = FALSE
@@ -85,6 +91,7 @@ Global
8591
{803E1492-22FA-4F63-9687-A30902682C15} = {5FEB9007-1EFA-4814-BC15-DB0370B84E22}
8692
{85C709D5-793A-4068-9937-4749BCF34267} = {BAAF9837-1DB5-4032-AB2A-2901E6EE6EF8}
8793
{8CEDCB64-13BF-4AD1-B7F4-01A8BB42AB07} = {85C709D5-793A-4068-9937-4749BCF34267}
94+
{2CAEFC83-24BF-4C92-B6F1-B3C6714220F2} = {A7EEBB7E-C64D-4475-93D0-872E080A4E03}
8895
EndGlobalSection
8996
GlobalSection(ExtensibilityGlobals) = postSolution
9097
SolutionGuid = {18C80710-C9E9-488B-9100-1E4BF8B18038}

README.md

Lines changed: 41 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,20 +13,16 @@ But what if you don't want hardcode roles on the `Authorize` attribute or create
1313

1414
**DynamicAuthorization** helps you authorize users without hardcoding role(s) on the `Authorize` attribute with minimum effort. DynamicAuthorization is built at the top of ASP.NET Core Identity and uses identity mechanism for managing roles and authorizing users.
1515

16-
Install the _DynamicAuthorization.Mvc.Core_ [NuGet package](https://www.nuget.org/packages/DynamicAuthorization.Mvc.Core) and _DynamicAuthorization.Mvc.JsonStore_ [NuGet package](https://www.nuget.org/packages/DynamicAuthorization.Mvc.JsonStore)
17-
16+
Install the _DynamicAuthorization.Mvc.Core_ [NuGet package](https://www.nuget.org/packages/DynamicAuthorization.Mvc.Core)
1817
```powershell
1918
Install-Package DynamicAuthorization.Mvc.Core
20-
Install-Package DynamicAuthorization.Mvc.JsonStore
2119
```
2220
or
2321
```shell
2422
dotnet add package DynamicAuthorization.Mvc.Core
25-
dotnet add package DynamicAuthorization.Mvc.JsonStore
2623
```
2724

28-
Then, add `AddDynamicAuthorization()` to `IServiceCollection` in `ConfigureServices` method:
29-
25+
Then, add `AddDynamicAuthorization()` to `IServiceCollection` in `Startup.ConfigureServices` method:
3026
```csharp
3127
public void ConfigureServices(IServiceCollection services)
3228
{
@@ -38,14 +34,47 @@ public void ConfigureServices(IServiceCollection services)
3834

3935
services
4036
.AddDynamicAuthorization<ApplicationDbContext>(options => options.DefaultAdminUser = "UserName")
41-
.AddJsonStore(options => options.FilePath = "FilePath");
4237
```
38+
You can set the default admin username via `DefaultAdminUser` config to access everywhere without creating a default admin role and its access.
4339

44-
You can set default admin username via `DefaultAdminUser` config to access everywhere and wihtout needing create default admin role and it's access.
40+
Then install JSON or SQLSever store to save role access.
4541

46-
Role access will be saved in JSON file and you can specify the file path `FilePath` config.
42+
To install _DynamicAuthorization.Mvc.JsonStore_ [NuGet package](https://www.nuget.org/packages/DynamicAuthorization.Mvc.JsonStore)
43+
```powershell
44+
Install-Package DynamicAuthorization.Mvc.JsonStore
45+
```
46+
or
47+
```shell
48+
dotnet add package DynamicAuthorization.Mvc.JsonStore
49+
```
50+
```csharp
51+
public void ConfigureServices(IServiceCollection services)
52+
{
53+
54+
services
55+
.AddDynamicAuthorization<ApplicationDbContext>(options => options.DefaultAdminUser = "UserName")
56+
.AddJsonStore(options => options.FilePath = "FilePath");
57+
```
58+
Role access will be saved in a JSON file and you can specify the file path `FilePath` config.
59+
60+
Or install SQLServer store _DynamicAuthorization.Mvc.MsSqlServerStore_ [NuGet package](https://www.nuget.org/packages/DynamicAuthorization.Mvc.MsSqlServerStore)
61+
```powershell
62+
Install-Package DynamicAuthorization.Mvc.MsSqlServerStore
63+
```
64+
or
65+
```shell
66+
dotnet add package DynamicAuthorization.Mvc.MsSqlServerStore
67+
```
68+
```csharp
69+
public void ConfigureServices(IServiceCollection services)
70+
{
71+
72+
services
73+
.AddDynamicAuthorization<ApplicationDbContext>(options => options.DefaultAdminUser = "UserName")
74+
.AddSqlServerStore(options => options.ConnectionString = "ConnectionString");
75+
```
4776

48-
You can decorate controllers and actions with `DisplayName` attribute to show user a more meaningful name instead of controller and action name.
77+
You can decorate controllers and actions with `DisplayName` attribute to show the user a more meaningful name instead of controller and action name.
4978
```c#
5079
[DisplayName("Access Management")]
5180
public class AccessController : Controller
@@ -57,7 +86,7 @@ public class AccessController : Controller
5786
}
5887
```
5988

60-
You can also use default UI to for managing roles and assigning roles to users if you don't want to implement them by yourself.
89+
You can also the default UI for managing roles and assigning roles to users if you don't want to implement them by yourself.
6190

6291
Install the _DynamicAuthorization.Mvc.Ui_ [NuGet package](https://www.nuget.org/packages/DynamicAuthorization.Mvc.Ui)
6392
@@ -133,7 +162,7 @@ public class MySecureContentTagHelper : SecureContentTagHelper<ApplicationDbCont
133162
```
134163
#
135164

136-
If you don't want to use the default UI, follow the below steps to discover controller and actions and give access to role and then assign role to user.
165+
If you don't want to use the default UI, follow the below steps to discover controllers and actions and give access to the role and then assign role(s) to the user.
137166
The next step is discovering controllers and actions. `IMvcControllerDiscovery` return all controllers and actions that decorated with `[Authorize]` attribute. `IMvcControllerDiscovery.GetControllers()` method returns list of `MvcControllerInfo`:
138167

139168
```c#

src/DynamicAuthorization.Mvc.Core/DynamicAuthorization.Mvc.Core.nuspec

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<version>$version$</version>
66
<authors>Mohsen Esmailpour</authors>
77
<owners>mo.esmp</owners>
8-
<projectUrl>https://github.com/mo-esmp/serilog-ui</projectUrl>
8+
<projectUrl>https://github.com/mo-esmp/DynamicRoleBasedAuthorizationNETCore</projectUrl>
99
<license type="expression">MIT</license>
1010
<requireLicenseAcceptance>false</requireLicenseAcceptance>
1111
<description>Dynamically authorize users without hard coding roles</description>
@@ -34,7 +34,7 @@
3434
<group targetFramework=".NETCoreApp3.1">
3535
<frameworkReference name="Microsoft.AspNetCore.App" />
3636
</group>
37-
<group targetFramework=".NETCoreApp5.0">
37+
<group targetFramework=".NET5.0">
3838
<frameworkReference name="Microsoft.AspNetCore.App" />
3939
</group>
4040
</frameworkReferences>

src/DynamicAuthorization.Mvc.Core/Models/DynamicAuthorizationOptions.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
using System;
22
using System.Runtime.CompilerServices;
33

4-
[assembly: InternalsVisibleTo("DynamicAuthorization.Mvc.Ui")]
4+
[assembly: InternalsVisibleTo("DynamicAuthorization.Mvc.Ui"),
5+
InternalsVisibleTo("DynamicAuthorization.Mvc.MsSqlServerStore")]
56

67
namespace DynamicAuthorization.Mvc.Core.Models
78
{

src/DynamicAuthorization.Mvc.JsonStore/DynamicAuthorization.Mvc.JsonStore.nuspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<version>$version$</version>
66
<authors>Mohsen Esmailpour</authors>
77
<owners>mo.esmp</owners>
8-
<projectUrl>https://github.com/mo-esmp/serilog-ui</projectUrl>
8+
<projectUrl>https://github.com/mo-esmp/DynamicRoleBasedAuthorizationNETCore</projectUrl>
99
<license type="expression">MIT</license>
1010
<requireLicenseAcceptance>false</requireLicenseAcceptance>
1111
<description>JSON store for DynamicAuthorization</description>

src/DynamicAuthorization.Mvc.JsonStore/Extensions/DynamicAuthorizationJsonBuilderExtensions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
namespace DynamicAuthorization.Mvc.JsonStore.Extensions
99
{
10-
public static class ServiceCollectionExtensions
10+
public static class DynamicAuthorizationBuilderExtensions
1111
{
1212
private static readonly string Directory = Path.GetDirectoryName(typeof(RoleAccessStore).GetTypeInfo().Assembly.Location);
1313

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFramework>netstandard2.0</TargetFramework>
5+
</PropertyGroup>
6+
7+
<ItemGroup>
8+
<PackageReference Include="Microsoft.Data.SqlClient" Version="2.1.1" />
9+
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
10+
</ItemGroup>
11+
12+
<ItemGroup>
13+
<ProjectReference Include="..\DynamicAuthorization.Mvc.Core\DynamicAuthorization.Mvc.Core.csproj" />
14+
</ItemGroup>
15+
16+
</Project>
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<package xmlns="http://schemas.microsoft.com/packaging/2013/05/nuspec.xsd">
3+
<metadata>
4+
<id>DynamicAuthorization.Mvc.MsSqlServerStore</id>
5+
<version>$version$</version>
6+
<authors>Mohsen Esmailpour</authors>
7+
<owners>mo.esmp</owners>
8+
<projectUrl>https://github.com/mo-esmp/DynamicRoleBasedAuthorizationNETCore</projectUrl>
9+
<license type="expression">MIT</license>
10+
<requireLicenseAcceptance>false</requireLicenseAcceptance>
11+
<description>SQL Sever store for DynamicAuthorization</description>
12+
<tags>authorize authorization authentication dynamic-authorization dynamic-authentication identity membership</tags>
13+
<releaseNotes></releaseNotes>
14+
<copyright></copyright>
15+
<dependencies>
16+
<group targetFramework=".NETStandard2.0">
17+
<dependency id="DynamicAuthorization.Mvc.Core" version="1.0.2" exclude="Build,Analyzers" />
18+
<dependency id="Microsoft.Data.SqlClient" version="2.1.1" exclude="Build,Analyzers" />
19+
<dependency id="Newtonsoft.Json" version="12.0.3" exclude="Build,Analyzers" />
20+
</group>
21+
</dependencies>
22+
</metadata>
23+
<files>
24+
<file src="bin\release\netstandard2.0\DynamicAuthorization.Mvc.MsSqlServerStore.dll" target="lib/netstandard2.0" />
25+
</files>
26+
</package>
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
using DynamicAuthorization.Mvc.Core;
2+
using Microsoft.Extensions.DependencyInjection;
3+
using Microsoft.Extensions.Logging;
4+
using System;
5+
6+
namespace DynamicAuthorization.Mvc.MsSqlServerStore
7+
{
8+
public static class DynamicAuthorizationBuilderExtensions
9+
{
10+
public static IDynamicAuthorizationBuilder AddSqlServerStore(this IDynamicAuthorizationBuilder builder, Action<SqlOptions> options)
11+
{
12+
if (builder == null)
13+
throw new ArgumentNullException(nameof(builder));
14+
15+
var sqlOptions = new SqlOptions();
16+
options.Invoke(sqlOptions);
17+
18+
var serviceProvider = builder.Services.BuildServiceProvider();
19+
var scope = serviceProvider.CreateScope();
20+
var logger = scope.ServiceProvider.GetService<ILogger<SqlTableCreator>>();
21+
22+
var tableCreator = new SqlTableCreator(sqlOptions, logger);
23+
tableCreator.CreateTable();
24+
25+
scope.Dispose();
26+
serviceProvider.Dispose();
27+
28+
builder.Services.AddSingleton(sqlOptions);
29+
builder.Services.AddScoped<IRoleAccessStore, RoleAccessStore>();
30+
31+
return builder;
32+
}
33+
}
34+
}

0 commit comments

Comments
 (0)