Skip to content

Commit

Permalink
add DomainModeSecurityRule sugar (#512)
Browse files Browse the repository at this point in the history
  • Loading branch information
iatsuta authored Oct 15, 2024
1 parent fa4d063 commit 6b0467c
Show file tree
Hide file tree
Showing 8 changed files with 13 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,9 @@ public abstract record SecurityRule
public record ModeSecurityRule(string Name) : SecurityRule
{
public override string ToString() => this.Name;

public DomainSecurityRule.DomainModeSecurityRule ToDomain<TDomainObject>() => this.ToDomain(typeof(TDomainObject));

public DomainSecurityRule.DomainModeSecurityRule ToDomain(Type domainType) => new(domainType, this);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public override void Register(IServiceCollection services)
{
foreach (var domainObjectSecurityPair in this.domainObjectSecurityDict)
{
services.AddSingleton(new DomainModeSecurityRuleInfo(new DomainSecurityRule.DomainModeSecurityRule(this.DomainType, domainObjectSecurityPair.Key), domainObjectSecurityPair.Value));
services.AddSingleton(new DomainModeSecurityRuleInfo(domainObjectSecurityPair.Key.ToDomain(this.DomainType), domainObjectSecurityPair.Value));
}

if (this.securityPath != null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public class DomainSecurityServiceWithFunctor<TOriginalDomainSecurityService, TD
{
protected override ISecurityProvider<TDomainObject> CreateSecurityProvider(SecurityRule.ModeSecurityRule securityRule)
{
var actualSecurityRule = (SecurityRule?)securityRuleExpander.TryExpand(new DomainSecurityRule.DomainModeSecurityRule(typeof(TDomainObject), securityRule)) ?? securityRule;
var actualSecurityRule = (SecurityRule?)securityRuleExpander.TryExpand(securityRule.ToDomain<TDomainObject>()) ?? securityRule;

var originalSecurityProvider = originalDomainSecurityService.GetSecurityProvider(actualSecurityRule);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ public abstract class DependencyDomainSecurityServiceBase<TDomainObject, TBaseDo
protected override ISecurityProvider<TDomainObject> CreateSecurityProvider(SecurityRule securityRule)
{
if (securityRule is SecurityRule.ModeSecurityRule modeSecurityRule
&& securityRuleExpander.TryExpand(new DomainSecurityRule.DomainModeSecurityRule(typeof(TDomainObject), modeSecurityRule)) is
{ } customSecurityRule)
&& securityRuleExpander.TryExpand(modeSecurityRule.ToDomain<TDomainObject>()) is { } customSecurityRule)
{
return this.CreateSecurityProvider(customSecurityRule);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ protected sealed override ISecurityProvider<TDomainObject> CreateSecurityProvide

protected virtual ISecurityProvider<TDomainObject> CreateSecurityProvider(SecurityRule.ModeSecurityRule securityRule)
{
return this.GetSecurityProvider(new DomainModeSecurityRule(typeof(TDomainObject), securityRule));
return this.GetSecurityProvider(securityRule.ToDomain<TDomainObject>());
}

protected virtual ISecurityProvider<TDomainObject> CreateSecurityProvider(OperationSecurityRule securityRule)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ public static IServiceCollection RegisterProjectionDomainSecurityServices(this I

if (pair.CustomViewSecurityRule != null)
{
services.AddSingleton(new DomainModeSecurityRuleInfo(new DomainSecurityRule.DomainModeSecurityRule(pair.DomainType, SecurityRule.View), pair.CustomViewSecurityRule));
services.AddSingleton(new DomainModeSecurityRuleInfo(SecurityRule.View.ToDomain(pair.DomainType), pair.CustomViewSecurityRule));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ public static ISecuritySystemSettings AddSecurityRules(this ISecuritySystemSetti
SecurityRule.Disabled.And((TestRestrictionObject v) => v.RestrictionHandler))
.AddSecurityRule(
SampleSystemSecurityGroup.TestGroup,
new DomainSecurityRule.DomainModeSecurityRule(typeof(Employee), SecurityRule.View));
SecurityRule.View.ToDomain<Employee>());
}

public static ISecuritySystemSettings AddCustomSecurityOperations(this ISecuritySystemSettings settings)
Expand Down
6 changes: 3 additions & 3 deletions src/__SolutionItems/CommonAssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
[assembly: AssemblyCompany("Luxoft")]
[assembly: AssemblyCopyright("Copyright © Luxoft 2009-2024")]

[assembly: AssemblyVersion("22.4.2.0")]
[assembly: AssemblyFileVersion("22.4.2.0")]
[assembly: AssemblyInformationalVersion("22.4.2.0")]
[assembly: AssemblyVersion("22.4.3.0")]
[assembly: AssemblyFileVersion("22.4.3.0")]
[assembly: AssemblyInformationalVersion("22.4.3.0")]

#if DEBUG
[assembly: AssemblyConfiguration("Debug")]
Expand Down

0 comments on commit 6b0467c

Please sign in to comment.