public static AuthorizationResult Authorize(object target) { if (target == null) { throw new ArgumentNullException("target"); } if (DesignerProperties.IsInDesignTool) { return(AuthorizationResult.Allowed); } AuthorizationSource source = Authorization.SourceFactory.CreateSource(AuthorizationRuleManager.GetAuthorizationAttributes(target)); if (source == null) { throw new InvalidOperationException("Factory cannot return a null source."); } DependencyObject targetDo = target as DependencyObject; if (targetDo != null) { if (Authorization.GetBehaviorManager(targetDo) == null) { Authorization.SetBehaviorManager(targetDo, new AuthorizationBehaviorManager(targetDo)); } Authorization.GetBehaviorManager(targetDo).SetBehaviors(AuthorizationRuleManager.GetAuthorizationBehaviors(target), source); } return(source.Result); }
public static void ClearAuthorizationRules(object target) { if (target == null) { throw new ArgumentNullException("target"); } AuthorizationRuleManager.GetRules(target).Clear(); }
public static IEnumerable <AuthorizationRule> GetAuthorizationRules(object target) { if (target == null) { throw new ArgumentNullException("target"); } return(AuthorizationRuleManager.GetRules(target).ToArray()); }
static AuthorizationRuleManager() { AuthorizationRuleManager._useRollingInitialization = false; AuthorizationRuleManager.AddAuthorizationRule(typeof(object), new MarkupAuthorizationRule()); AuthorizationRuleManager.AddAuthorizationRule(typeof(UIElement), new MarkupAuthorizationRule("Visibility")); AuthorizationRuleManager.AddAuthorizationRule(typeof(Page), new MarkupAuthorizationRule("IsEnabled")); AuthorizationRuleManager._useRollingInitialization = true; }
public static bool RemoveAuthorizationRule(object target, AuthorizationRule rule) { if (target == null) { throw new ArgumentNullException("target"); } if (rule == null) { throw new ArgumentNullException("rule"); } return(AuthorizationRuleManager.GetRules(target).Remove(rule)); }
public static void AddAuthorizationRule(object target, AuthorizationRule rule) { if (target == null) { throw new ArgumentNullException("target"); } if (rule == null) { throw new ArgumentNullException("rule"); } AuthorizationRuleManager.GetRules(target).Add(rule); }
public static IEnumerable <AuthorizationBehavior> GetAuthorizationBehaviors(object target) { if (target == null) { throw new ArgumentNullException("target"); } List <AuthorizationBehavior> binders = new List <AuthorizationBehavior>(); foreach (AuthorizationRule rule in AuthorizationRuleManager.GetAuthorizationRules(target)) { binders.AddRange(rule.GetAuthorizationBehaviors(target)); } return(binders); }
public static IEnumerable <AuthorizationAttribute> GetAuthorizationAttributes(object target) { if (target == null) { throw new ArgumentNullException("target"); } List <AuthorizationAttribute> attributes = new List <AuthorizationAttribute>(); foreach (AuthorizationRule rule in AuthorizationRuleManager.GetAuthorizationRules(target)) { attributes.AddRange(rule.GetAuthorizationAttributes(target)); } return(attributes); }
private static IList <AuthorizationRule> GetRules(object target) { WeakReference reference = new WeakReference(target); if (!AuthorizationRuleManager.Rules.ContainsKey(reference)) { List <AuthorizationRule> rules = new List <AuthorizationRule>(); AuthorizationRuleManager.InitializeRules(target, rules); lock (AuthorizationRuleManager.SyncLock) { if (!AuthorizationRuleManager.Rules.ContainsKey(reference)) { AuthorizationRuleManager.Rules[reference] = rules; } } } return(AuthorizationRuleManager.Rules[reference]); }
public static AuthorizationResult Authorize(object target, AuthorizationRule rule) { AuthorizationRuleManager.AddAuthorizationRule(target, rule); return(Authorization.Authorize(target)); }