Skip to content

Commit

Permalink
Added support for .NET 6 and .NET 7 (#34)
Browse files Browse the repository at this point in the history
  • Loading branch information
mgernand authored Nov 24, 2023
1 parent f10f3dc commit 39ed7b2
Show file tree
Hide file tree
Showing 16 changed files with 151 additions and 87 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<TargetFrameworks>net6.0;net7.0;net8.0</TargetFrameworks>
<LangVersion>latest</LangVersion>
<Nullable>disable</Nullable>
<ImplicitUsings>disable</ImplicitUsings>
Expand All @@ -14,9 +14,9 @@
<RootNamespace>MadEyeMatt.$(MSBuildProjectName.Replace(" ", "_").Replace(".Abstractions", ""))</RootNamespace>
<IncludeSymbols>false</IncludeSymbols>
<Copyright>Copyright © 2022-2023 Matthias Gernand. All rights reserved.</Copyright>
<Version>8.5.0</Version>
<AssemblyVersion>8.5.0</AssemblyVersion>
<FileVersion>8.5.0</FileVersion>
<Version>8.5.1</Version>
<AssemblyVersion>8.5.1</AssemblyVersion>
<FileVersion>8.5.1</FileVersion>
<Authors>Matthias Gernand</Authors>
<Description>A libary that adds permission-based authorization.</Description>
<NeutralLanguage>en</NeutralLanguage>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<TargetFrameworks>net6.0;net7.0;net8.0</TargetFrameworks>
<LangVersion>latest</LangVersion>
<Nullable>disable</Nullable>
<ImplicitUsings>disable</ImplicitUsings>
Expand All @@ -14,9 +14,9 @@
<RootNamespace>MadEyeMatt.$(MSBuildProjectName.Replace(" ", "_"))</RootNamespace>
<IncludeSymbols>false</IncludeSymbols>
<Copyright>Copyright © 2022-2023 Matthias Gernand. All rights reserved.</Copyright>
<Version>8.5.0</Version>
<AssemblyVersion>8.5.0</AssemblyVersion>
<FileVersion>8.5.0</FileVersion>
<Version>8.5.1</Version>
<AssemblyVersion>8.5.1</AssemblyVersion>
<FileVersion>8.5.1</FileVersion>
<Authors>Matthias Gernand</Authors>
<Description>A libary that adds permission-based authorization.</Description>
<NeutralLanguage>en</NeutralLanguage>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<TargetFrameworks>net6.0;net7.0;net8.0</TargetFrameworks>
<LangVersion>latest</LangVersion>
<Nullable>disable</Nullable>
<ImplicitUsings>disable</ImplicitUsings>
Expand All @@ -14,9 +14,9 @@
<RootNamespace>MadEyeMatt.$(MSBuildProjectName.Replace(" ", "_"))</RootNamespace>
<IncludeSymbols>false</IncludeSymbols>
<Copyright>Copyright © 2022-2023 Matthias Gernand. All rights reserved.</Copyright>
<Version>8.5.0</Version>
<AssemblyVersion>8.5.0</AssemblyVersion>
<FileVersion>8.5.0</FileVersion>
<Version>8.5.1</Version>
<AssemblyVersion>8.5.1</AssemblyVersion>
<FileVersion>8.5.1</FileVersion>
<Authors>Matthias Gernand</Authors>
<Description>A libary that adds permission-based authorization.</Description>
<NeutralLanguage>en</NeutralLanguage>
Expand Down Expand Up @@ -47,8 +47,14 @@

<ItemGroup>
<PackageReference Include="JetBrains.Annotations" Version="2023.3.0" />
<PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="8.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Relational" Version="8.0.0" />

<PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="6.0.25" Condition="'$(TargetFramework)' == 'net6.0'"/>
<PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="7.0.14" Condition="'$(TargetFramework)' == 'net7.0'"/>
<PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="8.0.0" Condition="'$(TargetFramework)' == 'net8.0'"/>

<PackageReference Include="Microsoft.EntityFrameworkCore" Version="6.0.25" Condition="'$(TargetFramework)' == 'net6.0'"/>
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="7.0.14" Condition="'$(TargetFramework)' == 'net7.0'"/>
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="8.0.0" Condition="'$(TargetFramework)' == 'net8.0'"/>
</ItemGroup>

<ItemGroup>
Expand Down
29 changes: 29 additions & 0 deletions src/AspNetCore.Identity.Permissions.EntityFrameworkCore/Guard.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
namespace MadEyeMatt.AspNetCore.Identity.Permissions.EntityFrameworkCore
{
using System;
using System.Diagnostics.CodeAnalysis;
using System.Runtime.CompilerServices;

internal static class Guard
{
internal static void ThrowIfNull([NotNull] object argument, [CallerArgumentExpression("argument")] string parameterName = null)
{
if (argument != null)
{
return;
}

throw new ArgumentNullException(parameterName);
}

public static void ThrowIfNullOrWhiteSpace([NotNull] string argument, [CallerArgumentExpression("argument")] string parameterName = null)
{
if (!string.IsNullOrWhiteSpace(argument))
{
return;
}

throw new ArgumentException(argument, parameterName);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ public class PermissionStore<TPermission, TRole, TContext, TKey, TRolePermission
public PermissionStore(TContext context, IdentityErrorDescriber describer = null)
: base(describer)
{
ArgumentNullException.ThrowIfNull(context);
Guard.ThrowIfNull(context);

this.Context = context;
}
Expand Down Expand Up @@ -133,7 +133,7 @@ public override async Task<IdentityResult> CreateAsync(TPermission permission, C
{
cancellationToken.ThrowIfCancellationRequested();
this.ThrowIfDisposed();
ArgumentNullException.ThrowIfNull(permission);
Guard.ThrowIfNull(permission);

permission.ConcurrencyStamp = Guid.NewGuid().ToString("N");
this.Context.Add(permission);
Expand All @@ -146,7 +146,7 @@ public override async Task<IdentityResult> UpdateAsync(TPermission permission, C
{
cancellationToken.ThrowIfCancellationRequested();
this.ThrowIfDisposed();
ArgumentNullException.ThrowIfNull(permission);
Guard.ThrowIfNull(permission);

this.Context.Attach(permission);
permission.ConcurrencyStamp = Guid.NewGuid().ToString("N");
Expand All @@ -168,7 +168,7 @@ public override async Task<IdentityResult> DeleteAsync(TPermission permission, C
{
cancellationToken.ThrowIfCancellationRequested();
this.ThrowIfDisposed();
ArgumentNullException.ThrowIfNull(permission);
Guard.ThrowIfNull(permission);

this.Context.Remove(permission);
try
Expand Down Expand Up @@ -207,7 +207,7 @@ public override Task<string> GetNormalizedPermissionNameAsync(TPermission permis
{
cancellationToken.ThrowIfCancellationRequested();
this.ThrowIfDisposed();
ArgumentNullException.ThrowIfNull(permission);
Guard.ThrowIfNull(permission);

return Task.FromResult(permission.NormalizedName);
}
Expand All @@ -217,8 +217,8 @@ public override async Task AddToRoleAsync(TPermission permission, string normali
{
cancellationToken.ThrowIfCancellationRequested();
this.ThrowIfDisposed();
ArgumentNullException.ThrowIfNull(permission);
ArgumentException.ThrowIfNullOrEmpty(normalizedRoleName);
Guard.ThrowIfNull(permission);
Guard.ThrowIfNullOrWhiteSpace(normalizedRoleName);

TRole role = await this.FindRoleAsync(normalizedRoleName, cancellationToken);
if (role == null)
Expand All @@ -234,8 +234,8 @@ public override async Task RemoveFromRoleAsync(TPermission permission, string no
{
cancellationToken.ThrowIfCancellationRequested();
this.ThrowIfDisposed();
ArgumentNullException.ThrowIfNull(permission);
ArgumentException.ThrowIfNullOrEmpty(normalizedRoleName);
Guard.ThrowIfNull(permission);
Guard.ThrowIfNullOrWhiteSpace(normalizedRoleName);

TRole role = await this.FindRoleAsync(normalizedRoleName, cancellationToken);
if (role != null)
Expand All @@ -253,7 +253,7 @@ public override async Task<IList<string>> GetRolesAsync(TPermission permission,
{
cancellationToken.ThrowIfCancellationRequested();
this.ThrowIfDisposed();
ArgumentNullException.ThrowIfNull(permission);
Guard.ThrowIfNull(permission);

TKey permissionId = permission.Id;
IQueryable<string> query = from rolePermission in this.RolePermissions
Expand All @@ -269,7 +269,7 @@ public override async Task<IList<string>> GetRoleIdsAsync(TPermission permission
{
cancellationToken.ThrowIfCancellationRequested();
this.ThrowIfDisposed();
ArgumentNullException.ThrowIfNull(permission);
Guard.ThrowIfNull(permission);

TKey permissionId = permission.Id;
IQueryable<TKey> query = from rolePermission in this.RolePermissions
Expand All @@ -286,8 +286,8 @@ public override async Task<bool> IsInRoleAsync(TPermission permission, string no
{
cancellationToken.ThrowIfCancellationRequested();
this.ThrowIfDisposed();
ArgumentNullException.ThrowIfNull(permission);
ArgumentException.ThrowIfNullOrEmpty(normalizedRoleName);
Guard.ThrowIfNull(permission);
Guard.ThrowIfNullOrWhiteSpace(normalizedRoleName);

TRole role = await this.FindRoleAsync(normalizedRoleName, cancellationToken);
if (role != null)
Expand All @@ -307,7 +307,7 @@ public override async Task<IList<TPermission>> GetPermissionsInRoleAsync(string
{
cancellationToken.ThrowIfCancellationRequested();
this.ThrowIfDisposed();
ArgumentException.ThrowIfNullOrEmpty(normalizedRoleName);
Guard.ThrowIfNullOrWhiteSpace(normalizedRoleName);

TRole role = await this.FindRoleAsync(normalizedRoleName, cancellationToken);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public class TenantStore<TTenant, TRole, TContext, TKey, TTenantRole> : TenantSt
public TenantStore(TContext context, IdentityErrorDescriber describer = null)
: base(describer)
{
ArgumentNullException.ThrowIfNull(context);
Guard.ThrowIfNull(context);

this.Context = context;
}
Expand Down Expand Up @@ -98,7 +98,7 @@ public override async Task<IdentityResult> CreateAsync(TTenant tenant, Cancellat
{
cancellationToken.ThrowIfCancellationRequested();
this.ThrowIfDisposed();
ArgumentNullException.ThrowIfNull(tenant);
Guard.ThrowIfNull(tenant);

tenant.ConcurrencyStamp = Guid.NewGuid().ToString("N");
this.Context.Add(tenant);
Expand All @@ -111,7 +111,7 @@ public override async Task<IdentityResult> UpdateAsync(TTenant tenant, Cancellat
{
cancellationToken.ThrowIfCancellationRequested();
this.ThrowIfDisposed();
ArgumentNullException.ThrowIfNull(tenant);
Guard.ThrowIfNull(tenant);

this.Context.Attach(tenant);
tenant.ConcurrencyStamp = Guid.NewGuid().ToString("N");
Expand All @@ -133,7 +133,7 @@ public override async Task<IdentityResult> DeleteAsync(TTenant tenant, Cancellat
{
cancellationToken.ThrowIfCancellationRequested();
this.ThrowIfDisposed();
ArgumentNullException.ThrowIfNull(tenant);
Guard.ThrowIfNull(tenant);

this.Context.Remove(tenant);
try
Expand Down Expand Up @@ -175,8 +175,8 @@ public override async Task AddToRoleAsync(TTenant tenant, string normalizedRoleN
{
cancellationToken.ThrowIfCancellationRequested();
this.ThrowIfDisposed();
ArgumentNullException.ThrowIfNull(tenant);
ArgumentException.ThrowIfNullOrEmpty(normalizedRoleName);
Guard.ThrowIfNull(tenant);
Guard.ThrowIfNullOrWhiteSpace(normalizedRoleName);

TRole role = await this.FindRoleAsync(normalizedRoleName, cancellationToken);
if(role == null)
Expand All @@ -192,8 +192,8 @@ public override async Task RemoveFromRoleAsync(TTenant tenant, string normalized
{
cancellationToken.ThrowIfCancellationRequested();
this.ThrowIfDisposed();
ArgumentNullException.ThrowIfNull(tenant);
ArgumentException.ThrowIfNullOrEmpty(normalizedRoleName);
Guard.ThrowIfNull(tenant);
Guard.ThrowIfNullOrWhiteSpace(normalizedRoleName);

TRole role = await this.FindRoleAsync(normalizedRoleName, cancellationToken);
if(role != null)
Expand All @@ -211,7 +211,7 @@ public override async Task<IList<string>> GetRolesAsync(TTenant tenant, Cancella
{
cancellationToken.ThrowIfCancellationRequested();
this.ThrowIfDisposed();
ArgumentNullException.ThrowIfNull(tenant);
Guard.ThrowIfNull(tenant);

TKey userId = tenant.Id;
IQueryable<string> query = from tenantRole in this.TenantRoles
Expand All @@ -227,7 +227,7 @@ public override async Task<IList<string>> GetRoleIdsAsync(TTenant tenant, Cancel
{
cancellationToken.ThrowIfCancellationRequested();
this.ThrowIfDisposed();
ArgumentNullException.ThrowIfNull(tenant);
Guard.ThrowIfNull(tenant);

TKey userId = tenant.Id;
IQueryable<TKey> query = from tenantRole in this.TenantRoles
Expand All @@ -244,8 +244,8 @@ public override async Task<bool> IsInRoleAsync(TTenant tenant, string normalized
{
cancellationToken.ThrowIfCancellationRequested();
this.ThrowIfDisposed();
ArgumentNullException.ThrowIfNull(tenant);
ArgumentException.ThrowIfNullOrEmpty(normalizedRoleName);
Guard.ThrowIfNull(tenant);
Guard.ThrowIfNullOrWhiteSpace(normalizedRoleName);

TRole role = await this.FindRoleAsync(normalizedRoleName, cancellationToken);
if(role != null)
Expand All @@ -262,7 +262,7 @@ public override async Task<IList<TTenant>> GetTenantsInRoleAsync(string normaliz
{
cancellationToken.ThrowIfCancellationRequested();
this.ThrowIfDisposed();
ArgumentException.ThrowIfNullOrEmpty(normalizedRoleName);
Guard.ThrowIfNullOrWhiteSpace(normalizedRoleName);

TRole role = await this.FindRoleAsync(normalizedRoleName, cancellationToken);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<TargetFrameworks>net6.0;net7.0;net8.0</TargetFrameworks>
<LangVersion>latest</LangVersion>
<Nullable>disable</Nullable>
<ImplicitUsings>disable</ImplicitUsings>
Expand All @@ -14,9 +14,9 @@
<RootNamespace>MadEyeMatt.$(MSBuildProjectName.Replace(" ", "_"))</RootNamespace>
<IncludeSymbols>false</IncludeSymbols>
<Copyright>Copyright © 2022-2023 Matthias Gernand. All rights reserved.</Copyright>
<Version>8.5.0</Version>
<AssemblyVersion>8.5.0</AssemblyVersion>
<FileVersion>8.5.0</FileVersion>
<Version>8.5.1</Version>
<AssemblyVersion>8.5.1</AssemblyVersion>
<FileVersion>8.5.1</FileVersion>
<Authors>Matthias Gernand</Authors>
<Description>A libary that adds permission-based authorization.</Description>
<NeutralLanguage>en</NeutralLanguage>
Expand Down Expand Up @@ -47,7 +47,7 @@

<ItemGroup>
<PackageReference Include="JetBrains.Annotations" Version="2023.3.0" />
<PackageReference Include="MadEyeMatt.AspNetCore.Identity.MongoDB" Version="8.0.0" />
<PackageReference Include="MadEyeMatt.AspNetCore.Identity.MongoDB" Version="8.0.1" />
</ItemGroup>

<ItemGroup>
Expand Down
29 changes: 29 additions & 0 deletions src/AspNetCore.Identity.Permissions.MongoDB/Guard.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
namespace MadEyeMatt.AspNetCore.Identity.Permissions.MongoDB
{
using System;
using System.Diagnostics.CodeAnalysis;
using System.Runtime.CompilerServices;

internal static class Guard
{
internal static void ThrowIfNull([NotNull] object argument, [CallerArgumentExpression("argument")] string parameterName = null)
{
if (argument != null)
{
return;
}

throw new ArgumentNullException(parameterName);
}

public static void ThrowIfNullOrWhiteSpace([NotNull] string argument, [CallerArgumentExpression("argument")] string parameterName = null)
{
if (!string.IsNullOrWhiteSpace(argument))
{
return;
}

throw new ArgumentException(argument, parameterName);
}
}
}
Loading

0 comments on commit 39ed7b2

Please sign in to comment.