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.
PermissionsRoot2.cs
Go to the documentation of this file.
1//-----------------------------------------------------------------------
2// <copyright file="PermissionsRoot.cs" company="Marimer LLC">
3// Copyright (c) Marimer LLC. All rights reserved.
4// Website: https://cslanet.com
5// </copyright>
6// <summary>no summary</summary>
7//-----------------------------------------------------------------------
8using System;
9using System.Collections.Generic;
10using System.Text;
11using Csla.Core;
12using Csla.Rules;
16using System.Diagnostics;
17
18namespace Csla.Test.Security
19{
20#if TESTING
21 [DebuggerNonUserCode]
22#endif
23 [Serializable()]
24 public class PermissionsRoot2 : BusinessBase<PermissionsRoot2>
25 {
26 private int _ID = 0;
27 protected override object GetIdValue()
28 {
29 return _ID;
30 }
31
32 public static PropertyInfo<string> FirstNameProperty = RegisterProperty<string>(c => c.FirstName);
33 private string _firstName = FirstNameProperty.DefaultValue;
34 public string FirstName
35 {
36 get
37 {
38 if (CanReadProperty("FirstName"))
39 {
40 return _firstName;
41 }
42 else
43 {
44 throw new Csla.Security.SecurityException("Property get not allowed");
45 }
46 }
47 set
48 {
49 if (CanWriteProperty("FirstName"))
50 {
51 _firstName = value;
52 }
53 else
54 {
55 throw new Csla.Security.SecurityException("Property set not allowed");
56 }
57 }
58 }
59
60 public readonly static Csla.Core.IMemberInfo DoWorkMethod = RegisterMethod(typeof(PermissionsRoot), "DoWork");
61
62 public void DoWork()
63 {
64 CanExecuteMethod(DoWorkMethod, true);
65 }
66
67 #region Authorization
68
69 public static void AddObjectAuthorizationRules()
70 {
71 // add rules for multiple rulesets
72 BusinessRules.AddRule(typeof(PermissionsRoot2), new IsInRole(AuthorizationActions.DeleteObject, "User"));
73 BusinessRules.AddRule(typeof(PermissionsRoot2), new IsInRole(AuthorizationActions.DeleteObject, "Admin"), "custom1");
74 BusinessRules.AddRule(typeof(PermissionsRoot2), new IsInRole(AuthorizationActions.DeleteObject, "User", "Admin"), "custom2");
75 }
76
77 protected override void AddBusinessRules()
78 {
79 BusinessRules.AddRule(new Csla.Rules.CommonRules.IsInRole(Rules.AuthorizationActions.ReadProperty, FirstNameProperty, new List<string> { "Admin" }));
80 BusinessRules.AddRule(new Csla.Rules.CommonRules.IsInRole(Rules.AuthorizationActions.WriteProperty, FirstNameProperty, new List<string> { "Admin" }));
81 BusinessRules.AddRule(new Csla.Rules.CommonRules.IsInRole(Rules.AuthorizationActions.ExecuteMethod, DoWorkMethod, new List<string> { "Admin" }));
82 }
83
84 #endregion
85
86 #region "Criteria"
87
88 [Serializable()]
89 private class Criteria
90 {
91 //implement
92 }
93
94 #endregion
95
96 [RunLocal()]
97 [Create]
98 protected void DataPortal_Create()
99 {
100 _firstName = "default value"; //for now...
101 }
102 }
103}
This is the base class from which most business objects will be derived.
Definition: BusinessBase.cs:38
static MethodInfo RegisterMethod(string methodName)
Registers a method for use in Authorization.
Maintains metadata about a property.
Tracks the business rules for a business object.
void AddRule(IBusinessRuleBase rule)
Associates a business rule with the business object.
IsInRole authorization rule.
static readonly Csla.Core.IMemberInfo DoWorkMethod
override object GetIdValue()
Override this method to return a unique identifying value for this object.
static PropertyInfo< string > FirstNameProperty
Maintains metadata about a method or property.
Definition: IMemberInfo.cs:19
AuthorizationActions
Authorization actions.
@ Serializable
Prevents updating or inserting until the transaction is complete.
@ Create
Create operation.