Skip to content

Commit

Permalink
Added missing methods to manager classes. (#18)
Browse files Browse the repository at this point in the history
mgernand authored Mar 31, 2023
1 parent e9931a3 commit 2be1221
Showing 14 changed files with 169 additions and 120 deletions.
14 changes: 14 additions & 0 deletions AspNetCore.Authorization.Permissions.sln
Original file line number Diff line number Diff line change
@@ -44,6 +44,10 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MongoSamplePermissions", "s
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MongoSampleTenant", "samples\MongoSampleTenant\MongoSampleTenant.csproj", "{B7172410-2A68-4DB9-9538-036C8FFC7DE4}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AspNetCore.Identity.Permissions.MongoDB.IntegrationTests", "tests\AspNetCore.Identity.Permissions.MongoDB.IntegrationTests\AspNetCore.Identity.Permissions.MongoDB.IntegrationTests.csproj", "{61ADF77F-B1DB-4489-AD46-DD6956605D41}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AspNetCore.Identity.Permissions.EntityFrameworkCore.IntegrationTests", "tests\AspNetCore.Identity.Permissions.EntityFrameworkCore.IntegrationTests\AspNetCore.Identity.Permissions.EntityFrameworkCore.IntegrationTests.csproj", "{637FE076-7CDE-49B1-BB14-1A6CE85382A8}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@@ -98,6 +102,14 @@ Global
{B7172410-2A68-4DB9-9538-036C8FFC7DE4}.Debug|Any CPU.Build.0 = Debug|Any CPU
{B7172410-2A68-4DB9-9538-036C8FFC7DE4}.Release|Any CPU.ActiveCfg = Release|Any CPU
{B7172410-2A68-4DB9-9538-036C8FFC7DE4}.Release|Any CPU.Build.0 = Release|Any CPU
{61ADF77F-B1DB-4489-AD46-DD6956605D41}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{61ADF77F-B1DB-4489-AD46-DD6956605D41}.Debug|Any CPU.Build.0 = Debug|Any CPU
{61ADF77F-B1DB-4489-AD46-DD6956605D41}.Release|Any CPU.ActiveCfg = Release|Any CPU
{61ADF77F-B1DB-4489-AD46-DD6956605D41}.Release|Any CPU.Build.0 = Release|Any CPU
{637FE076-7CDE-49B1-BB14-1A6CE85382A8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{637FE076-7CDE-49B1-BB14-1A6CE85382A8}.Debug|Any CPU.Build.0 = Debug|Any CPU
{637FE076-7CDE-49B1-BB14-1A6CE85382A8}.Release|Any CPU.ActiveCfg = Release|Any CPU
{637FE076-7CDE-49B1-BB14-1A6CE85382A8}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
@@ -117,6 +129,8 @@ Global
{074DB0DE-2F0B-4C8C-95B1-E8D1BE71077E} = {FA57E06B-CC0E-459C-A993-1D41ADF99ECF}
{3273907D-2D59-42AC-81C1-8B8F4617A7FA} = {24F9EFE8-010B-48D9-B5D2-EF194BDEAC31}
{B7172410-2A68-4DB9-9538-036C8FFC7DE4} = {24F9EFE8-010B-48D9-B5D2-EF194BDEAC31}
{61ADF77F-B1DB-4489-AD46-DD6956605D41} = {9BE8804F-BCC0-48CF-9AEC-ED97414B0C78}
{637FE076-7CDE-49B1-BB14-1A6CE85382A8} = {9BE8804F-BCC0-48CF-9AEC-ED97414B0C78}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {A52A2019-EEE6-4DAB-B111-C10693C9E03B}
Original file line number Diff line number Diff line change
@@ -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.2.0</Version>
<AssemblyVersion>8.2.0</AssemblyVersion>
<FileVersion>8.2.0</FileVersion>
<Version>8.2.1</Version>
<AssemblyVersion>8.2.1</AssemblyVersion>
<FileVersion>8.2.1</FileVersion>
<Authors>Matthias Gernand</Authors>
<Description>A libary that adds permission-based authorization.</Description>
<NeutralLanguage>en</NeutralLanguage>
Original file line number Diff line number Diff line change
@@ -14,9 +14,9 @@
<RootNamespace>MadEyeMatt.$(MSBuildProjectName.Replace(" ", "_"))</RootNamespace>
<IncludeSymbols>false</IncludeSymbols>
<Copyright>Copyright © 2022-2023 Matthias Gernand. All rights reserved.</Copyright>
<Version>8.2.0</Version>
<AssemblyVersion>8.2.0</AssemblyVersion>
<FileVersion>8.2.0</FileVersion>
<Version>8.2.1</Version>
<AssemblyVersion>8.2.1</AssemblyVersion>
<FileVersion>8.2.1</FileVersion>
<Authors>Matthias Gernand</Authors>
<Description>A libary that adds permission-based authorization.</Description>
<NeutralLanguage>en</NeutralLanguage>
Original file line number Diff line number Diff line change
@@ -14,9 +14,9 @@
<RootNamespace>MadEyeMatt.$(MSBuildProjectName.Replace(" ", "_"))</RootNamespace>
<IncludeSymbols>false</IncludeSymbols>
<Copyright>Copyright © 2022-2023 Matthias Gernand. All rights reserved.</Copyright>
<Version>8.2.0</Version>
<AssemblyVersion>8.2.0</AssemblyVersion>
<FileVersion>8.2.0</FileVersion>
<Version>8.2.1</Version>
<AssemblyVersion>8.2.1</AssemblyVersion>
<FileVersion>8.2.1</FileVersion>
<Authors>Matthias Gernand</Authors>
<Description>A libary that adds permission-based authorization.</Description>
<NeutralLanguage>en</NeutralLanguage>
Original file line number Diff line number Diff line change
@@ -14,9 +14,9 @@
<RootNamespace>MadEyeMatt.$(MSBuildProjectName.Replace(" ", "_"))</RootNamespace>
<IncludeSymbols>false</IncludeSymbols>
<Copyright>Copyright © 2022-2023 Matthias Gernand. All rights reserved.</Copyright>
<Version>8.2.0</Version>
<AssemblyVersion>8.2.0</AssemblyVersion>
<FileVersion>8.2.0</FileVersion>
<Version>8.2.1</Version>
<AssemblyVersion>8.2.1</AssemblyVersion>
<FileVersion>8.2.1</FileVersion>
<Authors>Matthias Gernand</Authors>
<Description>A libary that adds permission-based authorization.</Description>
<NeutralLanguage>en</NeutralLanguage>
Original file line number Diff line number Diff line change
@@ -14,9 +14,9 @@
<RootNamespace>MadEyeMatt.AspNetCore.Identity.Permissions</RootNamespace>
<IncludeSymbols>false</IncludeSymbols>
<Copyright>Copyright © 2022-2023 Matthias Gernand. All rights reserved.</Copyright>
<Version>8.2.0</Version>
<AssemblyVersion>8.2.0</AssemblyVersion>
<FileVersion>8.2.0</FileVersion>
<Version>8.2.1</Version>
<AssemblyVersion>8.2.1</AssemblyVersion>
<FileVersion>8.2.1</FileVersion>
<Authors>Matthias Gernand</Authors>
<Description>A libary that adds permission-based authorization.</Description>
<NeutralLanguage>en</NeutralLanguage>
Original file line number Diff line number Diff line change
@@ -14,9 +14,9 @@
<RootNamespace>MadEyeMatt.AspNetCore.Identity.Permissions</RootNamespace>
<IncludeSymbols>false</IncludeSymbols>
<Copyright>Copyright © 2022-2023 Matthias Gernand. All rights reserved.</Copyright>
<Version>8.2.0</Version>
<AssemblyVersion>8.2.0</AssemblyVersion>
<FileVersion>8.2.0</FileVersion>
<Version>8.2.1</Version>
<AssemblyVersion>8.2.1</AssemblyVersion>
<FileVersion>8.2.1</FileVersion>
<Authors>Matthias Gernand</Authors>
<Description>A libary that adds permission-based authorization.</Description>
<NeutralLanguage>en</NeutralLanguage>
93 changes: 51 additions & 42 deletions src/Extensions.Identity.Permissions.Core/PermissionManager.cs
Original file line number Diff line number Diff line change
@@ -158,10 +158,7 @@ public void Dispose()
public virtual async Task<IdentityResult> CreateAsync(TPermission permission)
{
this.ThrowIfDisposed();
if(permission == null)
{
throw new ArgumentNullException(nameof(permission));
}
ArgumentNullException.ThrowIfNull(permission);

IdentityResult result = await this.ValidatePermissionAsync(permission);
if(!result.Succeeded)
@@ -185,12 +182,9 @@ public virtual async Task<IdentityResult> CreateAsync(TPermission permission)
public virtual Task<IdentityResult> UpdateAsync(TPermission permission)
{
this.ThrowIfDisposed();
if(permission == null)
{
throw new ArgumentNullException(nameof(permission));
}
ArgumentNullException.ThrowIfNull(permission);

return this.UpdatePermissionAsync(permission);
return this.UpdatePermissionAsync(permission);
}

/// <summary>
@@ -204,10 +198,7 @@ public virtual Task<IdentityResult> UpdateAsync(TPermission permission)
public virtual Task<IdentityResult> DeleteAsync(TPermission permission)
{
this.ThrowIfDisposed();
if(permission == null)
{
throw new ArgumentNullException(nameof(permission));
}
ArgumentNullException.ThrowIfNull(permission);

return this.Store.DeleteAsync(permission, this.CancellationToken);
}
@@ -223,12 +214,9 @@ public virtual Task<IdentityResult> DeleteAsync(TPermission permission)
public virtual async Task<bool> PermissionExistsAsync(string permissionName)
{
this.ThrowIfDisposed();
if(permissionName == null)
{
throw new ArgumentNullException(nameof(permissionName));
}
ArgumentNullException.ThrowIfNull(permissionName);

return await this.FindByNameAsync(permissionName) != null;
return await this.FindByNameAsync(permissionName) != null;
}

/// <summary>
@@ -290,23 +278,50 @@ public virtual Task<string> GetPermissionIdAsync(TPermission permission)
return this.Store.GetPermissionIdAsync(permission, this.CancellationToken);
}

/// <summary>
/// Finds the role associated with the specified <paramref name="permissionName" /> if any.
/// </summary>
/// <param name="permissionName">The permission ID whose permission should be returned.</param>
/// <returns>
/// The <see cref="Task" /> that represents the asynchronous operation, containing the permission
/// associated with the specified <paramref name="permissionName" />
/// </returns>
public Task<TPermission> FindByNameAsync(string permissionName)
/// <summary>
/// Gets a list of role names the specified <paramref name="permission" /> belongs to.
/// </summary>
/// <param name="permission">The permission whose role names to retrieve.</param>
/// <returns>The <see cref="Task" /> that represents the asynchronous operation, containing a list of role names.</returns>
public virtual async Task<IList<string>> GetRolesAsync(TPermission permission)
{
this.ThrowIfDisposed();
if(permissionName == null)
{
throw new ArgumentNullException(nameof(permissionName));
}
ArgumentNullException.ThrowIfNull(permission);

return this.Store.FindByNameAsync(this.NormalizeName(permissionName), this.CancellationToken);
IRolePermissionStore<TPermission> store = this.GetRolePermissionStore();
return await store.GetRolesAsync(permission, this.CancellationToken);
}

/// <summary>
/// Finds the role associated with the specified <paramref name="permissionId" /> if any.
/// </summary>
/// <param name="permissionId">The permission ID whose permission should be returned.</param>
/// <returns>
/// The <see cref="Task" /> that represents the asynchronous operation, containing the permission
/// associated with the specified <paramref name="permissionId" />
/// </returns>
public Task<TPermission> FindByIdAsync(string permissionId)
{
this.ThrowIfDisposed();
ArgumentNullException.ThrowIfNull(permissionId);

return this.Store.FindByIdAsync(permissionId, this.CancellationToken);
}

/// <summary>
/// Finds the role associated with the specified <paramref name="permissionName" /> if any.
/// </summary>
/// <param name="permissionName">The permission name whose permission should be returned.</param>
/// <returns>
/// The <see cref="Task" /> that represents the asynchronous operation, containing the permission
/// associated with the specified <paramref name="permissionName" />
/// </returns>
public Task<TPermission> FindByNameAsync(string permissionName)
{
this.ThrowIfDisposed();
ArgumentNullException.ThrowIfNull(permissionName);

return this.Store.FindByNameAsync(this.NormalizeName(permissionName), this.CancellationToken);
}

/// <summary>
@@ -323,12 +338,9 @@ public virtual Task<IList<TPermission>> GetPermissionsInRoleAsync(string roleNam
{
this.ThrowIfDisposed();
IRolePermissionStore<TPermission> store = this.GetRolePermissionStore();
if(roleName == null)
{
throw new ArgumentNullException(nameof(roleName));
}
ArgumentNullException.ThrowIfNull(roleName);

return store.GetPermissionsInRoleAsync(this.NormalizeName(roleName), this.CancellationToken);
return store.GetPermissionsInRoleAsync(this.NormalizeName(roleName), this.CancellationToken);
}

/// <summary>
@@ -343,12 +355,9 @@ public virtual Task<IList<TPermission>> GetPermissionsInRoleAsync(string roleNam
public IList<string> GetPermissions(ClaimsPrincipal principal)
{
this.ThrowIfDisposed();
if(principal == null)
{
throw new ArgumentNullException(nameof(principal));
}
ArgumentNullException.ThrowIfNull(principal);

return principal.GetPermissions().ToList();
return principal.GetPermissions().ToList();
}

/// <summary>
47 changes: 13 additions & 34 deletions src/Extensions.Identity.Permissions.Core/TenantManager.cs
Original file line number Diff line number Diff line change
@@ -156,10 +156,7 @@ public void Dispose()
public virtual async Task<IdentityResult> CreateAsync(TTenant tenant)
{
this.ThrowIfDisposed();
if(tenant == null)
{
throw new ArgumentNullException(nameof(tenant));
}
ArgumentNullException.ThrowIfNull(tenant);

IdentityResult result = await this.ValidateTenantAsync(tenant);
if(!result.Succeeded)
@@ -183,12 +180,9 @@ public virtual async Task<IdentityResult> CreateAsync(TTenant tenant)
public virtual Task<IdentityResult> UpdateAsync(TTenant tenant)
{
this.ThrowIfDisposed();
if(tenant == null)
{
throw new ArgumentNullException(nameof(tenant));
}
ArgumentNullException.ThrowIfNull(tenant);

return this.UpdateTenantAsync(tenant);
return this.UpdateTenantAsync(tenant);
}

/// <summary>
@@ -202,12 +196,9 @@ public virtual Task<IdentityResult> UpdateAsync(TTenant tenant)
public virtual Task<IdentityResult> DeleteAsync(TTenant tenant)
{
this.ThrowIfDisposed();
if(tenant == null)
{
throw new ArgumentNullException(nameof(tenant));
}
ArgumentNullException.ThrowIfNull(tenant);

return this.Store.DeleteAsync(tenant, this.CancellationToken);
return this.Store.DeleteAsync(tenant, this.CancellationToken);
}

/// <summary>
@@ -221,12 +212,9 @@ public virtual Task<IdentityResult> DeleteAsync(TTenant tenant)
public virtual async Task<bool> TenantExistsAsync(string tenantName)
{
this.ThrowIfDisposed();
if(tenantName == null)
{
throw new ArgumentNullException(nameof(tenantName));
}
ArgumentNullException.ThrowIfNull(tenantName);

return await this.FindByNameAsync(tenantName) != null;
return await this.FindByNameAsync(tenantName) != null;
}

/// <summary>
@@ -240,10 +228,7 @@ public virtual async Task<bool> TenantExistsAsync(string tenantName)
public Task<TTenant> FindByIdAsync(string tenantId)
{
this.ThrowIfDisposed();
if(tenantId == null)
{
throw new ArgumentNullException(nameof(tenantId));
}
ArgumentNullException.ThrowIfNull(tenantId);

return this.Store.FindByIdAsync(tenantId, this.CancellationToken);
}
@@ -259,12 +244,9 @@ public Task<TTenant> FindByIdAsync(string tenantId)
public Task<TTenant> FindByNameAsync(string tenantName)
{
this.ThrowIfDisposed();
if(tenantName == null)
{
throw new ArgumentNullException(nameof(tenantName));
}
ArgumentNullException.ThrowIfNull(tenantName);

return this.Store.FindByNameAsync(this.NormalizeName(tenantName), this.CancellationToken);
return this.Store.FindByNameAsync(this.NormalizeName(tenantName), this.CancellationToken);
}

/// <summary>
@@ -348,13 +330,10 @@ public virtual async Task<IdentityResult> SetTenantNameAsync(TTenant tenant, str
public virtual async Task<IList<string>> GetRolesAsync(TTenant tenant)
{
this.ThrowIfDisposed();
ITenantRoleStore<TTenant> store = this.GetTenantRoleStore();
if(tenant == null)
{
throw new ArgumentNullException(nameof(tenant));
}
ArgumentNullException.ThrowIfNull(tenant);

return await store.GetRolesAsync(tenant, this.CancellationToken);
ITenantRoleStore<TTenant> store = this.GetTenantRoleStore();
return await store.GetRolesAsync(tenant, this.CancellationToken);
}

/// <summary>
Loading

0 comments on commit 2be1221

Please sign in to comment.