Browse Source
Merge pull request #23059 from abpframework/permission-provider-relation
Set provider names to permission groups and permissions
issue-#6768
maliming
1 year ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with
51 additions and
2 deletions
-
framework/src/Volo.Abp.Authorization.Abstractions/Properties/AssemblyInfo.cs
-
framework/src/Volo.Abp.Authorization.Abstractions/Volo/Abp/Authorization/Permissions/PermissionDefinition.cs
-
framework/src/Volo.Abp.Authorization.Abstractions/Volo/Abp/Authorization/Permissions/PermissionDefinitionContext.cs
-
framework/src/Volo.Abp.Authorization.Abstractions/Volo/Abp/Authorization/Permissions/PermissionGroupDefinition.cs
-
framework/src/Volo.Abp.Authorization/Volo/Abp/Authorization/Permissions/StaticPermissionDefinitionStore.cs
-
framework/test/Volo.Abp.Authorization.Tests/Volo/Abp/Authorization/TestServices/AuthorizationTestPermissionDefinitionProvider.cs
|
|
|
@ -0,0 +1,20 @@ |
|
|
|
using System.Reflection; |
|
|
|
using System.Runtime.CompilerServices; |
|
|
|
using System.Runtime.InteropServices; |
|
|
|
|
|
|
|
// General Information about an assembly is controlled through the following
|
|
|
|
// set of attributes. Change these attribute values to modify the information
|
|
|
|
// associated with an assembly.
|
|
|
|
[assembly: AssemblyConfiguration("")] |
|
|
|
[assembly: AssemblyCompany("")] |
|
|
|
[assembly: AssemblyProduct("Volo.Abp.Authorization.Abstractions")] |
|
|
|
[assembly: AssemblyTrademark("")] |
|
|
|
[assembly: InternalsVisibleTo("Volo.Abp.Authorization")] |
|
|
|
|
|
|
|
// Setting ComVisible to false makes the types in this assembly not visible
|
|
|
|
// to COM components. If you need to access a type in this assembly from
|
|
|
|
// COM, set the ComVisible attribute to true on that type.
|
|
|
|
[assembly: ComVisible(false)] |
|
|
|
|
|
|
|
// The following GUID is for the ID of the typelib if this project is exposed to COM
|
|
|
|
[assembly: Guid("83632bec-2f60-4c2b-b964-30e8b37fa9d8")] |
|
|
|
@ -107,6 +107,8 @@ public class PermissionDefinition : |
|
|
|
{ |
|
|
|
Parent = this |
|
|
|
}; |
|
|
|
|
|
|
|
child[PermissionDefinitionContext.KnownPropertyNames.CurrentProviderName] = this[PermissionDefinitionContext.KnownPropertyNames.CurrentProviderName]; |
|
|
|
|
|
|
|
_children.Add(child); |
|
|
|
|
|
|
|
|
|
|
|
@ -11,6 +11,13 @@ public class PermissionDefinitionContext : IPermissionDefinitionContext |
|
|
|
|
|
|
|
public Dictionary<string, PermissionGroupDefinition> Groups { get; } |
|
|
|
|
|
|
|
internal IPermissionDefinitionProvider? CurrentProvider { get; set; } |
|
|
|
|
|
|
|
public static class KnownPropertyNames |
|
|
|
{ |
|
|
|
public const string CurrentProviderName = "_CurrentProviderName"; |
|
|
|
} |
|
|
|
|
|
|
|
public PermissionDefinitionContext(IServiceProvider serviceProvider) |
|
|
|
{ |
|
|
|
ServiceProvider = serviceProvider; |
|
|
|
@ -27,8 +34,17 @@ public class PermissionDefinitionContext : IPermissionDefinitionContext |
|
|
|
{ |
|
|
|
throw new AbpException($"There is already an existing permission group with name: {name}"); |
|
|
|
} |
|
|
|
|
|
|
|
var group = new PermissionGroupDefinition(name, displayName); |
|
|
|
|
|
|
|
return Groups[name] = new PermissionGroupDefinition(name, displayName); |
|
|
|
if (CurrentProvider != null) |
|
|
|
{ |
|
|
|
group[KnownPropertyNames.CurrentProviderName] = CurrentProvider.GetType().FullName; |
|
|
|
} |
|
|
|
|
|
|
|
Groups[name] = group; |
|
|
|
|
|
|
|
return group; |
|
|
|
} |
|
|
|
|
|
|
|
[NotNull] |
|
|
|
|
|
|
|
@ -61,6 +61,8 @@ public class PermissionGroupDefinition : ICanAddChildPermission |
|
|
|
isEnabled |
|
|
|
); |
|
|
|
|
|
|
|
permission[PermissionDefinitionContext.KnownPropertyNames.CurrentProviderName] = this[PermissionDefinitionContext.KnownPropertyNames.CurrentProviderName]; |
|
|
|
|
|
|
|
_permissions.Add(permission); |
|
|
|
|
|
|
|
return permission; |
|
|
|
|
|
|
|
@ -84,18 +84,23 @@ public class StaticPermissionDefinitionStore : IStaticPermissionDefinitionStore, |
|
|
|
|
|
|
|
foreach (var provider in providers) |
|
|
|
{ |
|
|
|
context.CurrentProvider = provider; |
|
|
|
provider.PreDefine(context); |
|
|
|
} |
|
|
|
|
|
|
|
foreach (var provider in providers) |
|
|
|
{ |
|
|
|
context.CurrentProvider = provider; |
|
|
|
provider.Define(context); |
|
|
|
} |
|
|
|
|
|
|
|
foreach (var provider in providers) |
|
|
|
{ |
|
|
|
context.CurrentProvider = provider; |
|
|
|
provider.PostDefine(context); |
|
|
|
} |
|
|
|
|
|
|
|
context.CurrentProvider = null; |
|
|
|
|
|
|
|
return context.Groups; |
|
|
|
} |
|
|
|
|
|
|
|
@ -14,8 +14,12 @@ public class AuthorizationTestPermissionDefinitionProvider : PermissionDefinitio |
|
|
|
} |
|
|
|
|
|
|
|
var group = context.AddGroup("TestGroup"); |
|
|
|
|
|
|
|
group[PermissionDefinitionContext.KnownPropertyNames.CurrentProviderName].ShouldBe(typeof(AuthorizationTestPermissionDefinitionProvider).FullName); |
|
|
|
|
|
|
|
group.AddPermission("MyAuthorizedService1"); |
|
|
|
var permission1 = group.AddPermission("MyAuthorizedService1"); |
|
|
|
|
|
|
|
permission1[PermissionDefinitionContext.KnownPropertyNames.CurrentProviderName].ShouldBe(typeof(AuthorizationTestPermissionDefinitionProvider).FullName); |
|
|
|
|
|
|
|
group.AddPermission("MyPermission1").StateCheckers.Add(new TestRequireEditionPermissionSimpleStateChecker()); |
|
|
|
group.AddPermission("MyPermission2"); |
|
|
|
|