-
Notifications
You must be signed in to change notification settings - Fork 3.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add
SetForClientAsync
extension method to IPermissionManager
.
Resolve #17796
- Loading branch information
Showing
18 changed files
with
232 additions
and
7 deletions.
There are no files selected for viewing
31 changes: 31 additions & 0 deletions
31
....PermissionManagement.Domain.IdentityServer/Volo/Abp/ClientPermissionManagerExtensions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Threading.Tasks; | ||
using JetBrains.Annotations; | ||
using Volo.Abp.Authorization.Permissions; | ||
|
||
namespace Volo.Abp.PermissionManagement; | ||
|
||
public static class ClientPermissionManagerExtensions | ||
{ | ||
public static Task<PermissionWithGrantedProviders> GetForClientAsync([NotNull] this IPermissionManager permissionManager, string clientId, string permissionName) | ||
{ | ||
Check.NotNull(permissionManager, nameof(permissionManager)); | ||
|
||
return permissionManager.GetAsync(permissionName, ClientPermissionValueProvider.ProviderName, clientId); | ||
} | ||
|
||
public static Task<List<PermissionWithGrantedProviders>> GetAllForClientAsync([NotNull] this IPermissionManager permissionManager, string clientId) | ||
{ | ||
Check.NotNull(permissionManager, nameof(permissionManager)); | ||
|
||
return permissionManager.GetAllAsync(ClientPermissionValueProvider.ProviderName, clientId); | ||
} | ||
|
||
public static Task SetForClientAsync([NotNull] this IPermissionManager permissionManager, string clientId, [NotNull] string permissionName, bool isGranted) | ||
{ | ||
Check.NotNull(permissionManager, nameof(permissionManager)); | ||
|
||
return permissionManager.SetAsync(permissionName, ClientPermissionValueProvider.ProviderName, clientId, isGranted); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 5 additions & 1 deletion
6
....IdentityServer.Domain.Tests/Volo/Abp/IdentityServer/AbpIdentityServerDomainTestModule.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
...t/Volo.Abp.IdentityServer.Domain.Tests/Volo/Abp/IdentityServer/PermissionManager_Tests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
using System.Threading.Tasks; | ||
using Shouldly; | ||
using Volo.Abp.Authorization.Permissions; | ||
using Volo.Abp.IdentityServer; | ||
using Volo.Abp.PermissionManagement; | ||
using Xunit; | ||
|
||
namespace Volo.Abp.OpenIddict; | ||
|
||
public class PermissionManager_Tests : AbpIdentityServerDomainTestBase | ||
{ | ||
private readonly IPermissionManager _permissionManager; | ||
private readonly IPermissionStore _permissionStore; | ||
private readonly AbpIdentityServerTestData _testData; | ||
|
||
public PermissionManager_Tests() | ||
{ | ||
_permissionManager = GetRequiredService<IPermissionManager>(); | ||
_permissionStore = GetRequiredService<IPermissionStore>(); | ||
_testData = GetRequiredService<AbpIdentityServerTestData>(); | ||
} | ||
|
||
[Fact] | ||
public async Task Should_Grant_Permission_To_Client() | ||
{ | ||
(await _permissionManager.GetForClientAsync(_testData.Client1Name, TestPermissionNames.MyPermission1)).IsGranted.ShouldBeFalse(); | ||
(await _permissionStore.IsGrantedAsync(TestPermissionNames.MyPermission2, ClientPermissionValueProvider.ProviderName, _testData.Client1Name)).ShouldBeFalse(); | ||
|
||
await _permissionManager.SetForClientAsync(_testData.Client1Name, TestPermissionNames.MyPermission2, true); | ||
|
||
(await _permissionManager.GetForClientAsync(_testData.Client1Name, TestPermissionNames.MyPermission2)).IsGranted.ShouldBeTrue(); | ||
(await _permissionStore.IsGrantedAsync(TestPermissionNames.MyPermission2, ClientPermissionValueProvider.ProviderName, _testData.Client1Name)).ShouldBeTrue(); | ||
} | ||
|
||
[Fact] | ||
public async Task Should_Revoke_Permission_From_Client() | ||
{ | ||
await _permissionManager.SetForClientAsync(_testData.Client1Name, TestPermissionNames.MyPermission1, true); | ||
(await _permissionManager.GetForClientAsync(_testData.Client1Name, TestPermissionNames.MyPermission1)).IsGranted.ShouldBeTrue(); | ||
|
||
await _permissionManager.SetForClientAsync(_testData.Client1Name, TestPermissionNames.MyPermission1, false); | ||
(await _permissionManager.GetForClientAsync(_testData.Client1Name, TestPermissionNames.MyPermission1)).IsGranted.ShouldBeFalse(); | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
.../test/Volo.Abp.IdentityServer.Domain.Tests/Volo/Abp/IdentityServer/TestPermissionNames.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
namespace Volo.Abp.IdentityServer; | ||
|
||
public static class TestPermissionNames | ||
{ | ||
public static class Groups | ||
{ | ||
public const string TestGroup = "TestGroup"; | ||
} | ||
|
||
public const string MyPermission1 = "MyPermission1"; | ||
|
||
public const string MyPermission2 = "MyPermission2"; | ||
} |
13 changes: 13 additions & 0 deletions
13
...entityServer.Domain.Tests/Volo/Abp/IdentityServer/TestTestPermissionDefinitionProvider.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
using Volo.Abp.Authorization.Permissions; | ||
|
||
namespace Volo.Abp.IdentityServer; | ||
|
||
public class TestTestPermissionDefinitionProvider : PermissionDefinitionProvider | ||
{ | ||
public override void Define(IPermissionDefinitionContext context) | ||
{ | ||
var testGroup = context.AddGroup(TestPermissionNames.Groups.TestGroup); | ||
testGroup.AddPermission(TestPermissionNames.MyPermission1); | ||
testGroup.AddPermission(TestPermissionNames.MyPermission2); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
...ment.Domain.OpenIddict/Volo/Abp/PermissionManagement/ClientPermissionManagerExtensions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Threading.Tasks; | ||
using JetBrains.Annotations; | ||
using Volo.Abp.Authorization.Permissions; | ||
|
||
namespace Volo.Abp.PermissionManagement; | ||
|
||
public static class ClientPermissionManagerExtensions | ||
{ | ||
public static Task<PermissionWithGrantedProviders> GetForClientAsync([NotNull] this IPermissionManager permissionManager, string clientId, string permissionName) | ||
{ | ||
Check.NotNull(permissionManager, nameof(permissionManager)); | ||
|
||
return permissionManager.GetAsync(permissionName, ClientPermissionValueProvider.ProviderName, clientId); | ||
} | ||
|
||
public static Task<List<PermissionWithGrantedProviders>> GetAllForClientAsync([NotNull] this IPermissionManager permissionManager, string clientId) | ||
{ | ||
Check.NotNull(permissionManager, nameof(permissionManager)); | ||
|
||
return permissionManager.GetAllAsync(ClientPermissionValueProvider.ProviderName, clientId); | ||
} | ||
|
||
public static Task SetForClientAsync([NotNull] this IPermissionManager permissionManager, string clientId, [NotNull] string permissionName, bool isGranted) | ||
{ | ||
Check.NotNull(permissionManager, nameof(permissionManager)); | ||
|
||
return permissionManager.SetAsync(permissionName, ClientPermissionValueProvider.ProviderName, clientId, isGranted); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
...dict/test/Volo.Abp.OpenIddict.Domain.Tests/Volo/Abp/OpenIddict/PermissionManager_Tests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
using System.Threading.Tasks; | ||
using Shouldly; | ||
using Volo.Abp.Authorization.Permissions; | ||
using Volo.Abp.PermissionManagement; | ||
using Xunit; | ||
|
||
namespace Volo.Abp.OpenIddict; | ||
|
||
public class PermissionManager_Tests : OpenIddictDomainTestBase | ||
{ | ||
private readonly IPermissionManager _permissionManager; | ||
private readonly IPermissionStore _permissionStore; | ||
private readonly AbpOpenIddictTestData _testData; | ||
|
||
public PermissionManager_Tests() | ||
{ | ||
_permissionManager = GetRequiredService<IPermissionManager>(); | ||
_permissionStore = GetRequiredService<IPermissionStore>(); | ||
_testData = GetRequiredService<AbpOpenIddictTestData>(); | ||
} | ||
|
||
[Fact] | ||
public async Task Should_Grant_Permission_To_Client() | ||
{ | ||
(await _permissionManager.GetForClientAsync(_testData.App1ClientId, TestPermissionNames.MyPermission1)).IsGranted.ShouldBeFalse(); | ||
(await _permissionStore.IsGrantedAsync(TestPermissionNames.MyPermission2, ClientPermissionValueProvider.ProviderName, _testData.App1ClientId)).ShouldBeFalse(); | ||
|
||
await _permissionManager.SetForClientAsync(_testData.App1ClientId, TestPermissionNames.MyPermission2, true); | ||
|
||
(await _permissionManager.GetForClientAsync(_testData.App1ClientId, TestPermissionNames.MyPermission2)).IsGranted.ShouldBeTrue(); | ||
(await _permissionStore.IsGrantedAsync(TestPermissionNames.MyPermission2, ClientPermissionValueProvider.ProviderName, _testData.App1ClientId)).ShouldBeTrue(); | ||
} | ||
|
||
[Fact] | ||
public async Task Should_Revoke_Permission_From_Client() | ||
{ | ||
await _permissionManager.SetForClientAsync(_testData.App1ClientId, TestPermissionNames.MyPermission1, true); | ||
(await _permissionManager.GetForClientAsync(_testData.App1ClientId, TestPermissionNames.MyPermission1)).IsGranted.ShouldBeTrue(); | ||
|
||
await _permissionManager.SetForClientAsync(_testData.App1ClientId, TestPermissionNames.MyPermission1, false); | ||
(await _permissionManager.GetForClientAsync(_testData.App1ClientId, TestPermissionNames.MyPermission1)).IsGranted.ShouldBeFalse(); | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
.../Volo.Abp.OpenIddict.Domain.Tests/Volo/Abp/OpenIddict/TestPermissionDefinitionProvider.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
using Volo.Abp.Authorization.Permissions; | ||
|
||
namespace Volo.Abp.OpenIddict; | ||
|
||
public class TestPermissionDefinitionProvider : PermissionDefinitionProvider | ||
{ | ||
public override void Define(IPermissionDefinitionContext context) | ||
{ | ||
var testGroup = context.AddGroup(TestPermissionNames.Groups.TestGroup); | ||
testGroup.AddPermission(TestPermissionNames.MyPermission1); | ||
testGroup.AddPermission(TestPermissionNames.MyPermission2); | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
...eniddict/test/Volo.Abp.OpenIddict.Domain.Tests/Volo/Abp/OpenIddict/TestPermissionNames.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
namespace Volo.Abp.OpenIddict; | ||
|
||
public static class TestPermissionNames | ||
{ | ||
public static class Groups | ||
{ | ||
public const string TestGroup = "TestGroup"; | ||
} | ||
|
||
public const string MyPermission1 = "MyPermission1"; | ||
|
||
public const string MyPermission2 = "MyPermission2"; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters