Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add client security rule #508

Merged
merged 5 commits into from
Oct 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 25 additions & 24 deletions src/Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -14,55 +14,56 @@
<PackageVersion Include="coverlet.collector" Version="6.0.2" />
<PackageVersion Include="Dapper" Version="2.1.35" />
<PackageVersion Include="Dapper.Contrib" Version="2.0.78" />
<PackageVersion Include="Luxoft.Bss.Platform.Api.Documentation" Version="1.5.5" />
<PackageVersion Include="Luxoft.Bss.Platform.Api.Middlewares" Version="1.5.5" />
<PackageVersion Include="Luxoft.Bss.Platform.Events" Version="1.5.5" />
<PackageVersion Include="Luxoft.Bss.Platform.Events.Abstractions" Version="1.5.5" />
<PackageVersion Include="Luxoft.Bss.Platform.Logging" Version="1.5.5" />
<PackageVersion Include="Luxoft.Bss.Platform.Api.Documentation" Version="1.5.6" />
<PackageVersion Include="Luxoft.Bss.Platform.Api.Middlewares" Version="1.5.6" />
<PackageVersion Include="Luxoft.Bss.Platform.Events" Version="1.5.6" />
<PackageVersion Include="Luxoft.Bss.Platform.Events.Abstractions" Version="1.5.6" />
<PackageVersion Include="Luxoft.Bss.Platform.Logging" Version="1.5.6" />
<PackageVersion Include="Microsoft.AspNetCore.Mvc" Version="2.2.0" />
<PackageVersion Include="FluentValidation" Version="11.9.2" />
<PackageVersion Include="FluentAssertions" Version="6.12.0" />
<PackageVersion Include="FluentMigrator" Version="5.2.0" />
<PackageVersion Include="FluentMigrator.Runner" Version="5.2.0" />
<PackageVersion Include="FluentValidation" Version="11.10.0" />
<PackageVersion Include="FluentAssertions" Version="6.12.1" />
<PackageVersion Include="FluentMigrator" Version="6.2.0" />
<PackageVersion Include="FluentMigrator.Runner" Version="6.2.0" />
<PackageVersion Include="FluentNHibernate" Version="3.4.0" />
<PackageVersion Include="Hangfire.AspNetCore" Version="1.8.14" />
<PackageVersion Include="Hangfire.SqlServer" Version="1.8.14" />
<PackageVersion Include="MartinCostello.SqlLocalDb" Version="3.4.0" />
<PackageVersion Include="Microsoft.AspNetCore.Authentication.Negotiate" Version="8.0.7" />
<PackageVersion Include="Microsoft.AspNetCore.Authentication.Negotiate" Version="8.0.10" />
<PackageVersion Include="Microsoft.AspNetCore.Mvc.Versioning" Version="5.1.0" />
<PackageVersion Include="Microsoft.CodeAnalysis.CSharp" Version="4.10.0" />
<PackageVersion Include="Microsoft.Data.SqlClient" Version="5.2.1" />
<PackageVersion Include="Microsoft.CodeAnalysis.CSharp" Version="4.11.0" />
<PackageVersion Include="Microsoft.Data.SqlClient" Version="5.2.2" />
<PackageVersion Include="Microsoft.Extensions.Configuration" Version="8.0.0" />
<PackageVersion Include="Microsoft.Extensions.Configuration.Abstractions" Version="8.0.0" />
<PackageVersion Include="Microsoft.Extensions.Configuration.Binder" Version="8.0.2" />
<PackageVersion Include="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="8.0.0" />
<PackageVersion Include="Microsoft.Extensions.Configuration.Json" Version="8.0.0" />
<PackageVersion Include="Microsoft.Extensions.DependencyInjection" Version="8.0.0" />
<PackageVersion Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="8.0.1" />
<PackageVersion Include="Microsoft.Extensions.Hosting" Version="8.0.0" />
<PackageVersion Include="Microsoft.Extensions.Logging.Abstractions" Version="8.0.1" />
<PackageVersion Include="Microsoft.Extensions.Configuration.Json" Version="8.0.1" />
<PackageVersion Include="Microsoft.Extensions.DependencyInjection" Version="8.0.1" />
<PackageVersion Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="8.0.2" />
<PackageVersion Include="Microsoft.Extensions.Hosting" Version="8.0.1" />
<PackageVersion Include="Microsoft.Extensions.Logging.Abstractions" Version="8.0.2" />
<PackageVersion Include="Microsoft.Extensions.Options" Version="8.0.2" />
<PackageVersion Include="Microsoft.Extensions.Options.ConfigurationExtensions" Version="8.0.0" />
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.10.0" />
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.11.1" />
<PackageVersion Include="Microsoft.SqlServer.SqlManagementObjects" Version="171.30.0" />
<PackageVersion Include="MSTest.TestAdapter" Version="3.5.1" />
<PackageVersion Include="MSTest.TestFramework" Version="3.5.1" />
<PackageVersion Include="MSTest.TestAdapter" Version="3.6.1" />
<PackageVersion Include="MSTest.TestFramework" Version="3.6.1" />
<PackageVersion Include="NHibernate" Version="5.5.2" />
<PackageVersion Include="NHibernate.Envers" Version="5.5.2" />
<PackageVersion Include="NSubstitute" Version="5.1.0" />
<PackageVersion Include="NUnit" Version="4.1.0" />
<PackageVersion Include="NUnit.ConsoleRunner" Version="3.18.1" />
<PackageVersion Include="NUnit" Version="4.2.2" />
<PackageVersion Include="NUnit.ConsoleRunner" Version="3.18.3" />
<PackageVersion Include="NUnit3TestAdapter" Version="4.6.0" />
<PackageVersion Include="nuSpec.Abstraction" Version="1.3.0" />
<PackageVersion Include="nuSpec.NHibernate" Version="1.3.0" />
<PackageVersion Include="Swashbuckle.AspNetCore.SwaggerGen" Version="6.8.1" />
<PackageVersion Include="System.CodeDom" Version="8.0.0" />
<PackageVersion Include="System.Reflection.Emit" Version="4.7.0" />
<PackageVersion Include="System.Runtime.Loader" Version="4.3.0" />
<PackageVersion Include="Unity" Version="5.11.10" />
<PackageVersion Include="Unity.Interception" Version="5.11.1" />
<PackageVersion Include="xunit" Version="2.9.0" />
<PackageVersion Include="xunit" Version="2.9.2" />
<PackageVersion Include="xunit.runner.visualstudio" Version="2.8.2" />
<PackageVersion Include="xunit.abstractions" Version="2.0.3" />
<PackageVersion Include="xunit.core" Version="2.9.0" />
<PackageVersion Include="xunit.core" Version="2.9.2" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
namespace Framework.SecuritySystem.AvailableSecurity;

public interface IAvailableClientSecurityRuleSource
{
Task<List<ClientSecurityRuleHeader>> GetAvailableSecurityRules(CancellationToken cancellationToken = default);
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace Framework.SecuritySystem;
namespace Framework.SecuritySystem.AvailableSecurity;

public interface IAvailableSecurityOperationSource
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace Framework.SecuritySystem;
namespace Framework.SecuritySystem.AvailableSecurity;

public interface IAvailableSecurityRoleSource
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
namespace Framework.SecuritySystem.Expanders;

public interface IRoleFactorySecurityRuleExpander
{
DomainSecurityRule.RoleBaseSecurityRule Expand(DomainSecurityRule.RoleFactorySecurityRule securityRule);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
namespace Framework.SecuritySystem.Expanders;

public interface ISecurityModeExpander
{
DomainSecurityRule? TryExpand(DomainSecurityRule.DomainModeSecurityRule securityRule);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
namespace Framework.SecuritySystem.Expanders;

public interface ISecurityOperationExpander
{
DomainSecurityRule.NonExpandedRolesSecurityRule Expand(DomainSecurityRule.OperationSecurityRule securityRule);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
namespace Framework.SecuritySystem.Expanders;

public interface ISecurityRoleExpander
{
DomainSecurityRule.ExpandedRolesSecurityRule Expand(DomainSecurityRule.NonExpandedRolesSecurityRule securityRule);
}
Original file line number Diff line number Diff line change
@@ -1,14 +1,6 @@
namespace Framework.SecuritySystem.Expanders;

public interface ISecurityRuleExpander
public interface ISecurityRuleExpander : ISecurityModeExpander, ISecurityOperationExpander, ISecurityRoleExpander, IRoleFactorySecurityRuleExpander
{
DomainSecurityRule? TryExpand<TDomainObject>(SecurityRule.ModeSecurityRule securityRule);

DomainSecurityRule.NonExpandedRolesSecurityRule Expand(DomainSecurityRule.OperationSecurityRule securityRule);

DomainSecurityRule.ExpandedRolesSecurityRule Expand(DomainSecurityRule.NonExpandedRolesSecurityRule securityRule);

DomainSecurityRule.RoleBaseSecurityRule Expand(DomainSecurityRule.RoleFactorySecurityRule securityRule);

DomainSecurityRule.ExpandedRolesSecurityRule FullExpand(DomainSecurityRule.RoleBaseSecurityRule securityRule);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
namespace Framework.SecuritySystem.Expanders;

public static class SecurityModeExpanderExtensions
{
public static DomainSecurityRule Expand(this ISecurityModeExpander expander, DomainSecurityRule.DomainModeSecurityRule securityRule)
{
return expander.TryExpand(securityRule)
?? throw new ArgumentOutOfRangeException(
nameof(securityRule),
$"{nameof(SecurityRule)} with mode '{securityRule}' not found for type '{securityRule.DomainType.Name}'");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
namespace Framework.SecuritySystem;

public record ClientSecurityRuleHeader(string Name)
{
public override string ToString() => this.Name;
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ public abstract record DomainSecurityRule : SecurityRule

public static implicit operator DomainSecurityRule(SecurityRole[] securityRoles) => securityRoles.ToSecurityRule();

public record DomainModeSecurityRule(Type DomainType, ModeSecurityRule Mode) : DomainSecurityRule
{
public override string ToString() => $"{this.Mode} ({this.DomainType.Name})";
}

public record CurrentUserSecurityRule(string? RelativePathKey = null) : DomainSecurityRule
{
public override string ToString() => this.RelativePathKey ?? nameof(CurrentUser);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
namespace Framework.SecuritySystem.SecurityRuleInfo;

public record ClientSecurityRuleInfo(ClientSecurityRuleHeader Header, DomainSecurityRule Implementation)
{
public ClientSecurityRuleInfo(string name, DomainSecurityRule implementation)
: this(new ClientSecurityRuleHeader(name), implementation)
{
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
namespace Framework.SecuritySystem.SecurityRuleInfo;

public record DomainModeSecurityRuleInfo(DomainSecurityRule.DomainModeSecurityRule SecurityRule, DomainSecurityRule Implementation);
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
namespace Framework.SecuritySystem.SecurityRuleInfo;

public interface IClientDomainModeSecurityRuleSource
{
IEnumerable<DomainSecurityRule.DomainModeSecurityRule> GetRules();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
namespace Framework.SecuritySystem.SecurityRuleInfo;

public interface IClientSecurityRuleInfoSource
{
IEnumerable<ClientSecurityRuleInfo> GetInfos();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
using System.Reflection;

namespace Framework.SecuritySystem.SecurityRuleInfo;

public interface IClientSecurityRuleNameExtractor
{
string ExtractName(PropertyInfo propertyInfo);

string ExtractName(DomainSecurityRule.DomainModeSecurityRule securityRule);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
namespace Framework.SecuritySystem.SecurityRuleInfo;

public interface IClientSecurityRuleResolver
{
IEnumerable<ClientSecurityRuleHeader> Resolve(SecurityRole securityRole);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
namespace Framework.SecuritySystem.SecurityRuleInfo;

public interface IDomainModeSecurityRuleResolver
{
IEnumerable<DomainSecurityRule.DomainModeSecurityRule> Resolve(SecurityRole securityRole);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
namespace Framework.SecuritySystem.SecurityRuleInfo;

public interface IDomainSecurityRoleExtractor
{
IEnumerable<SecurityRole> Extract(DomainSecurityRule securityRule);
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
using Framework.SecuritySystem;

namespace Framework.DomainDriven;
namespace Framework.SecuritySystem.SecurityRuleInfo;

public interface ISecurityRuleParser
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public void AdministratorRole_ShouldNotContains_SystemIntegrationRole()
public void SecurityRoleExpander_ExpandDeepChild_AllRolesExpanded()
{
// Arrange
var expander = this.rootServiceProvider.GetRequiredService<SecurityRoleExpander>();
var expander = this.rootServiceProvider.GetRequiredService<ISecurityRoleExpander>();

// Act
var expandResult = expander.Expand(ExampleSecurityRole.TestRole3);
Expand All @@ -44,7 +44,7 @@ public void SecurityRoleExpander_ExpandDeepChild_AllRolesExpanded()
public void SecurityRoleExpander_ExpandWithDefaultExpandType_RoleResolved()
{
// Arrange
var expander = this.rootServiceProvider.GetRequiredService<SecurityOperationExpander>();
var expander = this.rootServiceProvider.GetRequiredService<ISecurityOperationExpander>();

// Act
var expandResult = expander.Expand(new DomainSecurityRule.OperationSecurityRule(ExampleSecurityOperation.EmployeeView));
Expand All @@ -57,7 +57,7 @@ public void SecurityRoleExpander_ExpandWithDefaultExpandType_RoleResolved()
public void SecurityRoleExpander_ExpandWithCustomExpandType_SecurityRuleCorrected()
{
// Arrange
var expander = this.rootServiceProvider.GetRequiredService<SecurityOperationExpander>();
var expander = this.rootServiceProvider.GetRequiredService<ISecurityOperationExpander>();

// Act
var expandResult = expander.Expand(ExampleSecurityOperation.EmployeeView.ToSecurityRule(HierarchicalExpandType.None));
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using Framework.SecuritySystem.SecurityRuleInfo;

namespace Framework.SecuritySystem.AvailableSecurity;

public class AvailableClientSecurityRuleSource(
IAvailableSecurityRoleSource availableSecurityRoleSource,
IClientSecurityRuleResolver clientSecurityRuleResolver) : IAvailableClientSecurityRuleSource
{
public async Task<List<ClientSecurityRuleHeader>> GetAvailableSecurityRules(CancellationToken cancellationToken = default)
{
var roles = await availableSecurityRoleSource.GetAvailableSecurityRoles(true, cancellationToken);

return roles.SelectMany(clientSecurityRuleResolver.Resolve)
.Distinct()
.ToList();
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace Framework.SecuritySystem;
namespace Framework.SecuritySystem.AvailableSecurity;

public class AvailableSecurityOperationSource(IAvailableSecurityRoleSource availableSecurityRoleSource)
: IAvailableSecurityOperationSource
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using Framework.Core;
using Framework.SecuritySystem.ExternalSystem;

namespace Framework.SecuritySystem;
namespace Framework.SecuritySystem.AvailableSecurity;

public class AvailableSecurityRoleSource(IEnumerable<IPermissionSystem> permissionSystems, ISecurityRoleSource securityRoleSource)
: IAvailableSecurityRoleSource
Expand Down
Loading
Loading