/// <summary> /// Associates a per-type authorization rule with /// the business type. /// </summary> /// <param name="objectType">Type of business object.</param> /// <param name="rule">Rule object.</param> /// <param name="ruleSet">Rule set name.</param> public static void AddRule(Type objectType, IAuthorizationRule rule, string ruleSet) { var typeRules = AuthorizationRuleManager.GetRulesForType(objectType, ruleSet); EnsureUniqueRule(typeRules, rule); typeRules.Rules.Add(rule); }
/// <summary> /// Creates a AuthorizationContext instance for unit testing. /// </summary> /// <param name="rule">The rule.</param> /// <param name="user">The current user.</param> /// <param name="target">The target.</param> /// <param name="targetType">Type of the target.</param> public AuthorizationContext(IAuthorizationRule rule, IPrincipal user, object target, Type targetType) { Rule = rule; User = user; Target = target; TargetType = targetType; }
/// <summary> /// Creates a AuthorizationContext instance for unit testing. /// </summary> /// <param name="applicationContext"></param> /// <param name="rule">The rule.</param> /// <param name="target">The target.</param> /// <param name="targetType">Type of the target.</param> public AuthorizationContext(ApplicationContext applicationContext, IAuthorizationRule rule, object target, Type targetType) { ApplicationContext = applicationContext; Rule = rule; Target = target; TargetType = targetType; }
public AuthorizationService( IRepository<UserGroup> userGroupRepository, IAuthorizationRule[] rules, IPermissionProvider[] providers ) { this.userGroupRepository = userGroupRepository; this.rules = rules; this.providers = providers; }
/// <summary> /// Initializes the test. /// </summary> /// <param name="rule">The rule.</param> /// <param name="target">The target.</param> /// <param name="type">The type.</param> public void InitializeTest(IAuthorizationRule rule, object target, Type type) { var services = new ServiceCollection(); services.AddCsla(); var provider = services.BuildServiceProvider(); var applicationContext = provider.GetRequiredService <ApplicationContext>(); Accessor = new ObjectAccessor(applicationContext); AuthorizationContext = new AuthorizationContext(applicationContext, rule, target, type); }
private BooleanExpression GetParsedExpression(string ruleName) { IAuthorizationRule rule = null; authorizationRules.TryGetValue(ruleName, out rule); if (rule == null) { return(null); } string expression = rule.Expression; Parser parser = new Parser(); return(parser.Parse(expression)); }
private static void EnsureUniqueRule(AuthorizationRuleManager mgr, IAuthorizationRule rule) { IAuthorizationRule oldRule = null; if (rule.Element != null) { oldRule = mgr.Rules.FirstOrDefault(c => c.Element != null && c.Element.Name == rule.Element.Name && c.Action == rule.Action); } else { oldRule = mgr.Rules.FirstOrDefault(c => c.Element == null && c.Action == rule.Action); } if (oldRule != null) { throw new ArgumentException("rule"); } }
BooleanExpression GetParsedExpression(string ruleName, bool expEmpty) { expEmpty = false; IAuthorizationRule rule = null; authorizationRules.TryGetValue(ruleName, out rule); if (rule == null) { return(null); } if (string.IsNullOrEmpty(rule.Expression)) { expEmpty = true; } Parser parser = new Parser(); return(parser.Parse(rule.Expression)); }
/// <summary> /// Initializes the test. /// </summary> /// <param name="rule">The rule.</param> /// <param name="target">The target.</param> /// <param name="type">The type.</param> public void InitializeTest(IAuthorizationRule rule, object target, Type type) { AuthorizationContext = new AuthorizationContext(rule, target, type); }
/// <summary> /// Associates an authorization rule with the business object. /// </summary> /// <param name="rule">Rule object.</param> public void AddRule(IAuthorizationRule rule) { EnsureUniqueRule(TypeAuthRules, rule); TypeAuthRules.Rules.Add(rule); }
/// <summary> /// Associates a per-type authorization rule with /// the business type in the default rule set. /// </summary> /// <param name="objectType">Type of business object.</param> /// <param name="rule">Rule object.</param> public static void AddRule(Type objectType, IAuthorizationRule rule) { AddRule(objectType, rule, ApplicationContext.RuleSet); }
/// <summary> /// Creates a AuthorizationContext instance for unit testing. /// </summary> /// <param name="rule">The rule.</param> /// <param name="target">The target.</param> /// <param name="targetType">Type of the target.</param> public AuthorizationContext(IAuthorizationRule rule, object target, Type targetType) { Rule = rule; Target = target; TargetType = targetType; }
private static void EnsureUniqueRule(AuthorizationRuleManager mgr, IAuthorizationRule rule) { IAuthorizationRule oldRule = null; if (rule.Element != null) oldRule = mgr.Rules.FirstOrDefault(c => c.Element != null && c.Element.Name == rule.Element.Name && c.Action == rule.Action); else oldRule = mgr.Rules.FirstOrDefault(c => c.Element == null && c.Action == rule.Action); if (oldRule != null) throw new ArgumentException("rule"); }
private static string GetReason(IAuthorizationRule <T> rule) { return($"Allowed by requirement - {rule.GetType().Name}"); }
public Allow(IAuthorizationRule <T> rule) : base(GetReason(rule)) { }
public RuleDefinition(IAuthorizationRule rule, RuleConcatenationModeEnum mode) : this() { this.Rule = rule; this.Mode = mode; }
public AuthorizationPolicy(IAuthorizationRule <TModel> innerRule) { _innerRule = innerRule; }