CSLA.NET 6.0.0
CSLA .NET is a software development framework that helps you build a reusable, maintainable object-oriented business layer for your app.
AuthorizationRule.cs
Go to the documentation of this file.
1//-----------------------------------------------------------------------
2// <copyright file="AuthorizationRule.cs" company="Marimer LLC">
3// Copyright (c) Marimer LLC. All rights reserved.
4// Website: https://cslanet.com
5// </copyright>
6// <summary>Base class providing basic authorization rule</summary>
7//-----------------------------------------------------------------------
8using System;
9using System.Collections.Generic;
10using System.Linq;
11using System.Text;
12using Csla.Properties;
13
14namespace Csla.Rules
15{
20 public abstract class AuthorizationRule : IAuthorizationRule
21 {
22 private Csla.Core.IMemberInfo _element;
23 private AuthorizationActions _action;
24 private bool _cacheResult = true;
25 private bool _locked = false;
26
32 {
33 _action = action;
34 }
41 : this(action)
42 {
43 _element = element;
44 }
49 protected abstract void Execute(IAuthorizationContext context);
50
51
58 public bool CacheResult
59 {
60 get { return _cacheResult; }
61 protected set
62 {
63 CanWriteProperty("CacheResult");
64 _cacheResult = value;
65 }
66 }
67
73 {
74 get { return _element; }
75 set
76 {
77 CanWriteProperty("Element");
78 _element = value;
79 }
80 }
86 {
87 get { return _action; }
88 set
89 {
90 CanWriteProperty("Action");
91 _action = value;
92 }
93 }
94
95 private void CanWriteProperty(string argument)
96 {
97 if (_locked)
98 throw new ArgumentException(string.Format("{0} ({1})", Resources.PropertySetNotAllowed, argument), argument);
99 }
100
101 #region IAuthorizationRule
102
103 void IAuthorizationRule.Execute(IAuthorizationContext context)
104 {
105 if (!_locked)
106 _locked = true;
107 Execute(context);
108 }
109
110 Csla.Core.IMemberInfo IAuthorizationRule.Element
111 {
112 get { return Element; }
113 }
114
119 AuthorizationActions IAuthorizationRule.Action
120 {
121 get { return Action; }
122 }
123
124 #endregion
125
126 #region Read Property
138 protected object ReadProperty(object obj, Csla.Core.IPropertyInfo propertyInfo)
139 {
140 var target = obj as Core.IManageProperties;
141 if (target != null)
142 return target.ReadProperty(propertyInfo);
143 else
144 throw new ArgumentException(Resources.IManagePropertiesRequiredException);
145 }
146
147 #endregion
148 }
149}
A strongly-typed resource class, for looking up localized strings, etc.
static string IManagePropertiesRequiredException
Looks up a localized string similar to Target object must implement IManageProperties.
static string PropertySetNotAllowed
Looks up a localized string similar to Property set not allowed.
Base class providing basic authorization rule implementation.
object ReadProperty(object obj, Csla.Core.IPropertyInfo propertyInfo)
Reads a property's field value.
abstract void Execute(IAuthorizationContext context)
Authorization rule implementation.
AuthorizationRule(AuthorizationActions action, Csla.Core.IMemberInfo element)
Creates an instance of the rule.
bool CacheResult
Gets a value indicating whether the results of this rule can be cached at the business object level.
Csla.Core.IMemberInfo Element
Gets the name of the element (property/method) to which this rule is associated.
AuthorizationActions Action
Gets the authorization action this rule will enforce.
AuthorizationRule(AuthorizationActions action)
Creates an instance of the rule.
Maintains metadata about a method or property.
Definition: IMemberInfo.cs:19
Maintains metadata about a property.
Implemented by objects which provide context information to an authorization rule when it is invoked.
Interface defining an authorization rule implementation.
AuthorizationActions
Authorization actions.