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.
PermissionsRoot.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
19{
20#if TESTING
21 [DebuggerNonUserCode]
22#endif
23 [Serializable()]
24 public class PermissionsRoot : BusinessBase<PermissionsRoot>
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, RelationshipTypes.PrivateField);
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
70 public static void AddObjectAuthorizationRules()
71 {
72 // add rules for default ruleset
74 BusinessRules.AddRule(typeof(PermissionsRoot), new IsInRole(AuthorizationActions.DeleteObject, "Admin"), "custom1");
75 BusinessRules.AddRule(typeof(PermissionsRoot), new IsInRole(AuthorizationActions.DeleteObject, "User", "Admin"), "custom2");
76 }
77
78 protected override void AddBusinessRules()
79 {
80 BusinessRules.AddRule(new IsInRole(Rules.AuthorizationActions.ReadProperty, FirstNameProperty, new List<string> { "Admin" }));
81 BusinessRules.AddRule(new IsInRole(Rules.AuthorizationActions.WriteProperty, FirstNameProperty, new List<string> { "Admin" }));
82 BusinessRules.AddRule(new IsInRole(Rules.AuthorizationActions.ExecuteMethod, DoWorkMethod, new List<string> { "Admin" }));
83 }
84
85 #endregion
86
87 #region "Criteria"
88
89 [Serializable()]
90 private class Criteria
91 {
92 //implement
93 }
94
95 #endregion
96
97 [RunLocal()]
98 [Create]
99 protected void DataPortal_Create()
100 {
101 _firstName = "default value"; //for now...
102 }
103 }
104}
Provides consistent context information between the client and server DataPortal objects.
const string DefaultRuleSet
The default RuleSet name
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 PropertyInfo< string > FirstNameProperty
static readonly Csla.Core.IMemberInfo DoWorkMethod
override object GetIdValue()
Override this method to return a unique identifying value for this object.
Maintains metadata about a method or property.
Definition: IMemberInfo.cs:19
AuthorizationActions
Authorization actions.
RelationshipTypes
List of valid relationship types between a parent object and another object through a managed propert...
@ Serializable
Prevents updating or inserting until the transaction is complete.
@ Create
Create operation.